From dedb4bc31b5ecb8bba83f324064cfa603f00fe1b Mon Sep 17 00:00:00 2001 From: trotFunky Date: Sat, 5 May 2018 19:04:03 +0200 Subject: [PATCH] =?UTF-8?q?Modularit=C3=A9=20avec=20les=20versions=20de=20?= =?UTF-8?q?matchScript=20sous=20forme=20de=20liste?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Perso/auto_config.sh | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/Perso/auto_config.sh b/Perso/auto_config.sh index 7c3b162..a699529 100755 --- a/Perso/auto_config.sh +++ b/Perso/auto_config.sh @@ -28,6 +28,21 @@ function parameterTest { # Test si le paramètre $1 est égal à la valeur $2 et fi } +function multiTest { # Vérifie si $1 fait parti des éléments de $2 + + if [ ! $# -eq 2 ]; then + exit + fi + + for toTest in ${!2}; do + if [ "$1" = "$toTest" ]; then + echo "0" + exit + fi + done + exit +} + configFile=""$( dirname "${BASH_SOURCE[0]}" )"/config.txt" if [ ! -e $configFile ]; then @@ -35,6 +50,8 @@ if [ ! -e $configFile ]; then exit fi +matchScriptVersions=("0" "1" "2" "99") + ### COLOR CHANGE @@ -114,19 +131,26 @@ while [ "$changeMatchScript" != 'y' -a "$changeMatchScript" != 'n' ]; do read changeMatchScript done -if [ $changeMatchScript != 'n' ]; then - newMatchVersion="" - confirmMatchVersion="coucou" - while [ "$confirmMatchVersion" != "$newMatchVersion" ]; do - confirmMatchVersion=" " - newMatchVersion=" " - - while [ "$newMatchVersion" != "0" -a "$newMatchVersion" != "1" -a "$newMatchVersion" != "99" ]; do - echo -n "Choose a valid version (0/1/99): " + if [ $changeMatchScript != 'n' ]; then + newMatchVersion="" + confirmMatchVersion="coucou" + while [ "$confirmMatchVersion" != "$newMatchVersion" ]; do + confirmMatchVersion=" " + newMatchVersion=" " + + while [ ! $(multiTest "$newMatchVersion" matchScriptVersions[@]) ]; do + echo -n "Choose a valid version (" + for i in ${matchScriptVersions[@]};do + echo -n "$i" + if [ ! "$i" = "${matchScriptVersions[$(expr ${#matchScriptVersions[@]} - 1)]}" ]; then + echo -n "/" + fi + done + echo -n "): " read newMatchVersion done - while [ "$confirmMatchVersion" != "0" -a "$confirmMatchVersion" != "1" -a "$confirmMatchVersion" != "99" ]; do + while [ ! $(multiTest "$confirmMatchVersion" matchScriptVersions[@] ) ]; do echo -n "Please confirm your selection: " read confirmMatchVersion done