From be3ab6785b0c8a7dab61ff16f8f70f1b70616600 Mon Sep 17 00:00:00 2001 From: trotFunky Date: Mon, 7 May 2018 16:48:49 +0200 Subject: [PATCH] =?UTF-8?q?Modifications=20de=20l'auto=5Fconfig=20pour=20l?= =?UTF-8?q?e=20rendre=20plus=20modulaire=20au=20niveau=20des=20param=C3=A8?= =?UTF-8?q?tres=20Ajout=20d'options=20pour=20compenser=20la=20lourdeur=20d?= =?UTF-8?q?es=20param=C3=A8tres=20Modifications=20de=20commentaires/messag?= =?UTF-8?q?es=20d'info/etc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Perso/auto_config.sh | 106 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 97 insertions(+), 9 deletions(-) diff --git a/Perso/auto_config.sh b/Perso/auto_config.sh index a699529..729b4df 100755 --- a/Perso/auto_config.sh +++ b/Perso/auto_config.sh @@ -1,5 +1,6 @@ #! /bin/bash + function colourConvert { if [ $1 = 'o' ]; then echo "orange" @@ -15,10 +16,71 @@ function monoGrep { # Permet de récupérer l'argument dans la config (true/fa fi } -function parameterTest { # Test si le paramètre $1 est égal à la valeur $2 et, le cas échéant, le remplace par $3 - if [ "$(monoGrep "$1")" = "$2" ]; then +function parameterTest { # Test si le paramètre $1 est égal à la valeur $2 et, le cas échéant, le remplace par $3. Demande confirmation + answer="" + + if [ "$(monoGrep "$1")" = "$2" ]; then # Si le paramètre est à la valeur $2, demande si on veut la changer ou pas echo "WARNING: $1 is $2" + case $mode in + "std" ) + while [ "$answer" != "y" -a "$answer" != "n" ]; do + echo -n "Change it to standard value ($3) ? (y/n): " + read answer + done + ;; + "force-yes" ) + answer="y" + ;; + "force-no" ) + answer="n" + ;; + esac + + if [ $answer = "y" ]; then + echo "Setting $1 to $3" + echo "" + + parameterState=$(grep $configFile -e ^"$1") + sed -i "s/$parameterState/$(echo -n "$(echo "$parameterState" | cut -d "=" -f1 )"= $3)/" $configFile + else + echo "Keeping $1 at non-standard value ($2)" + echo "" + fi + + elif [ "$(monoGrep "$1")" = "$3" ]; then # Si le paramètre est à la valeur $3 demande si on veut le garder ou pas + + echo "$1 is already $3" + + case $mode in + "std" ) + while [ "$answer" != "y" -a "$answer" != "n" ]; do + echo -n "Keep it at standard value ? (y/n): " + read answer + done + ;; + "force-yes" ) + answer="y" + ;; + "force-no" ) + answer="n" + ;; + esac + + if [ $answer = "y" ]; then + echo "Keeping $1 at standard value ($3)" + echo "" + else + echo "Changing $1 to non-standard value ($2)" + echo "" + + parameterState=$(grep $configFile -e ^"$1") + sed -i "s/$parameterState/$(echo -n "$(echo "$parameterState" | cut -d "=" -f1 )"= $2)/" $configFile + fi + + else + + echo "WARNING: $1 value is invalid" echo "Setting $1 to $3" echo "" @@ -43,10 +105,33 @@ function multiTest { # Vérifie si $1 fait parti des éléments de $2 exit } -configFile=""$( dirname "${BASH_SOURCE[0]}" )"/config.txt" + +if [ $# -eq 0 ]; then + echo "Standard mode" + mode="std" +else + while getopts ":yYnN" option; do # Permet de gérer les options du script + case $option in + y | Y ) + echo "Forcing yes" + mode="force-yes" + break;; + n | N ) + echo "Forcing no" + mode="force-no" + break;; + * ) + echo "Invalid option used. Valid options are: (yYnN)" + exit + esac + done +fi + + +configFile=""$( dirname "${BASH_SOURCE[0]}" )"/config.txt" # Obtient le chemin d'origine du script et pas le lieu d'éxécution if [ ! -e $configFile ]; then - echo "Erreur: fichier de config invalide!" + echo "ERROR: Invalid config file!" exit fi @@ -71,7 +156,7 @@ echo "Current colour is $colour" colourConfirm=$colour -while [ "$colourConfirm" != "$newColour" ]; do # Boucle de confirmation +while [ "$colourConfirm" != "$newColour" ]; do # Boucle de confirmation newColour=" " colourConfirm=" " @@ -116,7 +201,7 @@ echo "" parameterTest "SIMULATION" "true" "false" parameterTest "ATTENTE_JUMPER" "false" "true" -parameterTest "basic_detection" "false" "true" +parameterTest "BASIC_DETECTION" "false" "true" # On refait la même pour la version du match @@ -127,19 +212,21 @@ currentMatchVersion=$(monoGrep "MATCHSCRIPT_TO_EXECUTE") echo "Ready to launch matchScript version $currentMatchVersion" while [ "$changeMatchScript" != 'y' -a "$changeMatchScript" != 'n' ]; do - echo -n "Would you like to change it ? (y/n)" + echo -n "Would you like to change it ? (y/n): " read changeMatchScript done if [ $changeMatchScript != 'n' ]; then newMatchVersion="" confirmMatchVersion="coucou" + while [ "$confirmMatchVersion" != "$newMatchVersion" ]; do confirmMatchVersion=" " newMatchVersion=" " while [ ! $(multiTest "$newMatchVersion" matchScriptVersions[@]) ]; do - echo -n "Choose a valid version (" + + echo -n "Choose a valid version (" # Permet d'afficher les valeurs du tableau proprement for i in ${matchScriptVersions[@]};do echo -n "$i" if [ ! "$i" = "${matchScriptVersions[$(expr ${#matchScriptVersions[@]} - 1)]}" ]; then @@ -148,6 +235,7 @@ done done echo -n "): " read newMatchVersion + done while [ ! $(multiTest "$confirmMatchVersion" matchScriptVersions[@] ) ]; do @@ -168,4 +256,4 @@ fi echo "" echo "May the Force be with Aspie" -exit +exit \ No newline at end of file