1
0
Fork 0

Changed the structure, added README

This commit is contained in:
trotFunky 2020-05-17 15:07:53 +01:00
parent 64527ae96a
commit 4bcec25c2e
6 changed files with 10 additions and 1 deletions

13
INTech/MATCH_BEGIN.sh Executable file
View file

@ -0,0 +1,13 @@
#! /bin/bash
xterm -e "/home/pi/Documents/TechTheTown-HighLevel/config/auto_config.sh"
couleur=$(grep "/home/pi/Documents/TechTheTown-HighLevel/config/config.txt" -e "^COULEUR" | head -n 1 | cut -d "=" -f 2 | cut -d " " -f 2)
if [ $couleur = "orange" ]; then
xterm -e "python ~/Documents/TechTheTown-HighLevel/src/patternRecognition/setPatternPosition/SetPatternPositionOrange.py;exit"
else
xterm -e "python ~/Documents/TechTheTown-HighLevel/src/patternRecognition/setPatternPosition/SetPatternPositionGreen.py;exit"
fi
xterm -e "cd ~/Documents/TechTheTown-HighLevel; java -jar techthetown-highlevel.jar;cd - "

264
INTech/auto_config.sh Executable file
View file

@ -0,0 +1,264 @@
#! /bin/bash
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
}
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" | "keep-cfg" )
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" | "keep-cfg" )
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 ""
parameterState=$(grep $configFile -e ^"$1")
sed -i "s/$parameterState/$(echo -n "$(echo "$parameterState" | cut -d "=" -f1 )"= $3)/" $configFile
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
}
if [ $# -eq 0 ]; then
echo "Standard mode"
mode="std"
else
while getopts ":yYnNkK" 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;;
k | K )
echo "Keeping parameter values"
mode="keep-cfg"
break;;
* )
echo "Invalid option used. Valid options are: (yYnNkK)"
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 "ERROR: Invalid config file!"
exit
fi
matchScriptVersions=("0" "1" "2" "99")
### 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
while [ "$colourConfirm" != "$newColour" ]; do # Boucle de confirmation
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"
parameterTest "BASIC_DETECTION" "false" "true"
parameterTest "ADVANCED_DETECTION" "false" "true"
# 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
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 (" # Permet d'afficher les valeurs du tableau proprement
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 [ ! $(multiTest "$confirmMatchVersion" matchScriptVersions[@] ) ]; do
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 ""
echo "May the Force be with Aspie"
exit

89
INTech/gitUpdate.sh Executable file
View file

@ -0,0 +1,89 @@
#!/bin/bash
export LC_ALL=POSIX
WORK_DIR=$HOME"/.gitAutoPull"
work_array="."
if [ $# -gt 0 ]; then
work_array=$@
fi
for GIT_REPO in $work_array ; do
GIT_REPO_NAME="$(echo '$GIT_REPO' | tr '/' '_' | tr -d '~')"
CHECK_TIMER_FILE=$WORK_DIR/localCommitsCheck"$GIT_REPO_NAME"
cd $GIT_REPO > /dev/null
if [ $? -ne 0 ]; then
echo $GIT_REPO" Does not exist or is not a directory"
exit -2
fi
if [ -z "$(git rev-parse --git-dir 2>/dev/null)" ]; then
echo $GIT_REPO" is not a git repository"
exit -2
fi
if [ ! -d $WORK_DIR ]; then
mkdir $WORK_DIR > /dev/null
fi
if [ ! -d $WORK_DIR ]; then
echo "Could not create work directory, aborting"
exit -4
fi
if [ -e $CHECK_TIMER_FILE ]; then
read count < $CHECK_TIMER_FILE
if [ $cout -ne 0 ]; then
echo $(( $count - 1 )) > $CHECK_TIMER_FILE
exit -1
else
rm -f $CHECK_TIMER_FILE
fi
fi
remoteStatus="$(git fetch --dry-run 2>&1 | tail -n 1 | grep -v -e'+')" # Empty if there are no commits to fetch
refChanges=$(git push -n --porcelain | grep -e'refs')
nbRefs=$(echo "$refChanges" | wc -l)
nbNonPushRefs=$(echo $(echo "$refChanges" | cut -f1) | wc -w)
localStatus="Nothing to do" # Empty if there are commits to push
if [ ! -z $(echo $refChanges | grep -e"*") ]; then
localStatus=""
fi
if [ ! $nbRefs -eq $nbNonPushRefs ]; then
localStatus=""
fi
output=$(
if [ -z "$remoteStatus" ]; then
if [ -z "$localStatus" ]; then
echo "Pushing "$GIT_REPO" updates to origin"
git push 2>&1
exit 1
fi
else
if [ -z "localStatus" ]; then
echo "Local and remote diverged, stopping auto-update for 30 iterations..."
echo 30 > $WORK_DIR/localCommitsCheck"$GIT_REPO_NAME"
else
echo "Updating "$GIT_REPO" with remote commits"
git fetch --all 2>&1
git remote update 2>&1
exit 1
fi
fi )
if [ ! -z "$output" ]; then
echo "$output" | wall
fi
done
exit 0