From 47adb9efbd5c300c75b6b01c0ea5e2ba1acf41c3 Mon Sep 17 00:00:00 2001 From: KM4ACK Date: Wed, 24 Nov 2021 17:18:47 -0600 Subject: [PATCH] add config repair --- manage-pat-functions | 94 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) diff --git a/manage-pat-functions b/manage-pat-functions index 3696255..05243d0 100644 --- a/manage-pat-functions +++ b/manage-pat-functions @@ -454,7 +454,99 @@ $MAIN & exit } - +REPAIRCONFIG(){ +DIR=/run/user/$UID +WHO=$(whoami) + +FILECHECK=$(ls $DIR | grep config.json) +if [ ! -z $FILECHECK ]; then +rm $DIR/config.json* +fi + + +#Verify Pat installed and set path variable if it is +if ! hash pat 2>/dev/null; then +echo "Pat Winlink not found on this system" +exit +else +PATV=$(pat version | awk '{print $2}' | sed 's/v0.//' | awk -F "." '{print $1}') + if [ $PATV -le 11 ]; then + PATPATH=$HOME/.wl2k/ + else + PATPATH=$XDGHOME_CONFIG_PATH/ + fi +fi + +#user input +SETTINGS=$(yad --form --width=600 --text-align=center --center --title="Repair Config File" --text-align=center \ +--image $LOGO --window-icon=$LOGO --image-on-top --separator="|" --item-separator="|" \ +--text="Pat Menu\rConfig File Repair\r by KM4ACK" \ +--field="Call Sign" "" \ +--field="Winlink Password" "" \ +--field="Six Character Grid Square" "" \ +--field="Allow access to Pat across network?":CB "YES|NO" \ +--button="Repair Config File":2 \ +--button="Cancel":1) +BUT=$? +if [ $BUT = 1 ]; then +$MAIN +elif [ $BUT = 252 ]; then +exit +fi + +#parse input into variables +CALL=$(echo $SETTINGS | awk -F "|" '{print $1}') +CALL=${CALL^^} +PASSWD=$(echo $SETTINGS | awk -F "|" '{print $2}') +GRID=$(echo $SETTINGS | awk -F "|" '{print $3}') +GRID=${GRID^^} +SECURE=$(echo $SETTINGS | awk -F "|" '{print $4}') + + + +if [ "$SECURE" = 'NO' ]; then +SECURE="127.0.0.1" +else +SECURE="0.0.0.0" +fi + +#check to see if EES is installed and set port accordingly +if [ -f /var/www/html/celladdy.php ]; then +PORT=5000 +else +PORT=8080 +fi + +#download config.json file from km4ack github +cd $DIR +wget -q https://raw.githubusercontent.com/km4ack/pi-scripts/master/config.json + +#verify download success +if [ $? != 0 ]; then +yad --title="Cannot Download!" --width=300 --height=100 \ +--image $LOGO --window-icon=$LOGO --image-on-top \ +--center --text="Cannot download new config file.\rCheck internet connection" \ +--button=gtk-ok +$MAIN & exit +fi + +#update file with user settings +sed -i "s/N0CALL/$CALL/" $DIR/config.json +sed -i "s/PASSWORD/$PASSWD/" $DIR/config.json +sed -i "s/GRID/$GRID/" $DIR/config.json +sed -i "s/8080/$PORT/" $DIR/config.json +sed -i "s/127.0.0.1/$SECURE/" $DIR/config.json + +#cp file and restart pat +cp $DIR/config.json $PATPATH/ +sudo systemctl restart pat@$WHO + +yad --title="Repair Complete" --width=300 --height=100 \ +--image $LOGO --window-icon=$LOGO --image-on-top \ +--center --text="Config File Repaired" \ +--button=gtk-ok +$MAIN & exit +}