1
0
mirror of https://github.com/km4ack/patmenu2.git synced 2025-05-16 14:50:13 -07:00

add config repair

This commit is contained in:
KM4ACK 2021-11-24 17:18:47 -06:00
parent ce870922ad
commit 47adb9efbd

View File

@ -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="<b>Pat Menu\rConfig File Repair\r</b> 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="<b>Cannot download new config file.\rCheck internet connection</b>" \
--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="<b>Config File Repaired</b>" \
--button=gtk-ok
$MAIN & exit
}