2018-04-21 04:16:30 +02:00
|
|
|
|
#! /bin/bash
|
|
|
|
|
|
2018-05-07 16:48:49 +02:00
|
|
|
|
|
2018-04-21 04:16:30 +02:00
|
|
|
|
function colourConvert {
|
|
|
|
|
if [ $1 = 'o' ]; then
|
|
|
|
|
echo "orange"
|
|
|
|
|
fi
|
|
|
|
|
if [ $1 = 'g' ]; then
|
|
|
|
|
echo "vert"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function monoGrep { # Permet de récupérer l'argument dans la config (true/false/etc) du paramètre passé à la fonction ($1)
|
|
|
|
|
if [ $# -eq 1 ]; then
|
|
|
|
|
echo $(grep $configFile -e "^$1" | head -n 1 | cut -d "=" -f 2 | cut -d " " -f 2)
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-07 16:48:49 +02:00
|
|
|
|
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
|
2018-04-21 04:16:30 +02:00
|
|
|
|
|
|
|
|
|
echo "WARNING: $1 is $2"
|
2018-05-07 16:48:49 +02:00
|
|
|
|
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"
|
2018-04-21 04:16:30 +02:00
|
|
|
|
echo "Setting $1 to $3"
|
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
|
|
parameterState=$(grep $configFile -e ^"$1")
|
|
|
|
|
sed -i "s/$parameterState/$(echo -n "$(echo "$parameterState" | cut -d "=" -f1 )"= $3)/" $configFile
|
|
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-05 19:04:03 +02:00
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-07 16:48:49 +02:00
|
|
|
|
|
|
|
|
|
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
|
2018-04-21 04:16:30 +02:00
|
|
|
|
|
2018-05-05 16:10:20 +02:00
|
|
|
|
if [ ! -e $configFile ]; then
|
2018-05-07 16:48:49 +02:00
|
|
|
|
echo "ERROR: Invalid config file!"
|
2018-05-05 16:10:20 +02:00
|
|
|
|
exit
|
|
|
|
|
fi
|
2018-04-21 04:16:30 +02:00
|
|
|
|
|
2018-05-05 19:04:03 +02:00
|
|
|
|
matchScriptVersions=("0" "1" "2" "99")
|
|
|
|
|
|
2018-04-21 04:16:30 +02:00
|
|
|
|
### COLOR CHANGE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
colour=$(monoGrep "COULEUR")
|
|
|
|
|
|
|
|
|
|
if [ $colour = 'orange' ]; then
|
|
|
|
|
printf '\e[48;5;208m]' # Change la couleur du fond à orange
|
|
|
|
|
echo "bite"
|
|
|
|
|
elif [ $colour = 'vert' ]; then
|
|
|
|
|
printf '\e[48;5;118m]' # ou à vert
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
printf '\e[38;5;232m]' # Ecrit le texte en noir pour la lisibilité
|
|
|
|
|
clear
|
|
|
|
|
|
|
|
|
|
echo "Current colour is $colour"
|
|
|
|
|
|
|
|
|
|
colourConfirm=$colour
|
|
|
|
|
|
2018-05-07 16:48:49 +02:00
|
|
|
|
while [ "$colourConfirm" != "$newColour" ]; do # Boucle de confirmation
|
2018-04-21 04:16:30 +02:00
|
|
|
|
|
|
|
|
|
newColour=" "
|
|
|
|
|
colourConfirm=" "
|
|
|
|
|
|
|
|
|
|
while [ "$newColour" != "o" -a "$newColour" != "g" ]; do
|
|
|
|
|
|
|
|
|
|
echo -n "Please choose the colour (o/g): "
|
|
|
|
|
read newColour
|
|
|
|
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
if [ $newColour = 'o' ]; then
|
|
|
|
|
printf '\e[48;5;208m]'
|
|
|
|
|
elif [ $newColour = 'g' ]; then
|
|
|
|
|
printf '\e[48;5;118m]'
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
clear
|
|
|
|
|
|
|
|
|
|
echo "The new colour is $(colourConvert $newColour)"
|
|
|
|
|
|
|
|
|
|
while [ "$colourConfirm" != 'o' -a "$colourConfirm" != 'g' ]; do
|
|
|
|
|
|
|
|
|
|
echo -n "Please confirm the chosen colour: "
|
|
|
|
|
read colourConfirm
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [ $(colourConvert $colourConfirm) = "$colour" ]; then
|
|
|
|
|
echo "The colour remains $colour"
|
|
|
|
|
else
|
|
|
|
|
echo "The colour has been changed from $colour to $(colourConvert $colourConfirm)"
|
|
|
|
|
sed -i "s/= $colour/= $(colourConvert $colourConfirm)/" $configFile # Change la couleur à la couleur choisie
|
|
|
|
|
fi
|
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### PARAMETER CHANGE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parameterTest "SIMULATION" "true" "false"
|
|
|
|
|
parameterTest "ATTENTE_JUMPER" "false" "true"
|
2018-05-07 16:48:49 +02:00
|
|
|
|
parameterTest "BASIC_DETECTION" "false" "true"
|
2018-04-21 04:16:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# On refait la même pour la version du match
|
|
|
|
|
# Reusability, anyone?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
currentMatchVersion=$(monoGrep "MATCHSCRIPT_TO_EXECUTE")
|
|
|
|
|
echo "Ready to launch matchScript version $currentMatchVersion"
|
|
|
|
|
|
|
|
|
|
while [ "$changeMatchScript" != 'y' -a "$changeMatchScript" != 'n' ]; do
|
2018-05-07 16:48:49 +02:00
|
|
|
|
echo -n "Would you like to change it ? (y/n): "
|
2018-04-21 04:16:30 +02:00
|
|
|
|
read changeMatchScript
|
|
|
|
|
done
|
|
|
|
|
|
2018-05-05 19:04:03 +02:00
|
|
|
|
if [ $changeMatchScript != 'n' ]; then
|
|
|
|
|
newMatchVersion=""
|
|
|
|
|
confirmMatchVersion="coucou"
|
2018-05-07 16:48:49 +02:00
|
|
|
|
|
2018-05-05 19:04:03 +02:00
|
|
|
|
while [ "$confirmMatchVersion" != "$newMatchVersion" ]; do
|
|
|
|
|
confirmMatchVersion=" "
|
|
|
|
|
newMatchVersion=" "
|
|
|
|
|
|
|
|
|
|
while [ ! $(multiTest "$newMatchVersion" matchScriptVersions[@]) ]; do
|
2018-05-07 16:48:49 +02:00
|
|
|
|
|
|
|
|
|
echo -n "Choose a valid version (" # Permet d'afficher les valeurs du tableau proprement
|
2018-05-05 19:04:03 +02:00
|
|
|
|
for i in ${matchScriptVersions[@]};do
|
|
|
|
|
echo -n "$i"
|
|
|
|
|
if [ ! "$i" = "${matchScriptVersions[$(expr ${#matchScriptVersions[@]} - 1)]}" ]; then
|
|
|
|
|
echo -n "/"
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
echo -n "): "
|
2018-04-21 04:16:30 +02:00
|
|
|
|
read newMatchVersion
|
2018-05-07 16:48:49 +02:00
|
|
|
|
|
2018-04-21 04:16:30 +02:00
|
|
|
|
done
|
|
|
|
|
|
2018-05-05 19:04:03 +02:00
|
|
|
|
while [ ! $(multiTest "$confirmMatchVersion" matchScriptVersions[@] ) ]; do
|
2018-04-21 04:16:30 +02:00
|
|
|
|
echo -n "Please confirm your selection: "
|
|
|
|
|
read confirmMatchVersion
|
|
|
|
|
done
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
if [ "$confirmMatchVersion" = "$currentMatchVersion" ]; then
|
|
|
|
|
echo "Match version remains $currentMatchVersion"
|
|
|
|
|
else
|
|
|
|
|
matchScriptState=$(grep $configFile -e ^"MATCHSCRIPT_TO_EXECUTE")
|
|
|
|
|
sed -i "s/$matchScriptState/$(echo -n "$(echo "$matchScriptState" | cut -d "=" -f1 )""= $newMatchVersion")/" $configFile
|
|
|
|
|
echo "MatchVersion has been changed from $currentMatchVersion to $confirmMatchVersion"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo ""
|
2018-04-30 23:32:23 +02:00
|
|
|
|
echo "May the Force be with Aspie"
|
|
|
|
|
|
2018-05-07 16:48:49 +02:00
|
|
|
|
exit
|