MYPATH=$HOME/patmenu2 MAIN=$MYPATH/./manage-pat LOGO=$MYPATH/pmlogo.png DELETEALIAS(){ PATCONFIG=$XDG_CONFIG_HOME/pat/config.json OUTFILE=/run/user/$UID/currentlist.txt TEMP=/run/user/$UID/patconfig.txt WHO=$(whoami) jq .connect_aliases $PATCONFIG | sed '/^}/d' | sed '/^{/d' | sed 's/^ *//g' > $OUTFILE cat $OUTFILE sed -i 's/"//g' $OUTFILE sed -i 's/,//g' $OUTFILE sed -i 's/://' $OUTFILE echo;echo cat $OUTFILE | awk 'OFS="\n" {print $1, $2}' REMOVE=$(PARSER='OFS="\n" {print $1, $2}' tail -50 $OUTFILE | awk "$PARSER" | \ yad --title="Current Alias List" --width=1100 --height=500 \ --image $LOGO --window-icon=$LOGO --image-on-top \ --center --list --text="Select Alias to Delete" \ --column Call --column INFO \ --button="Delete Alias":2 \ --button="Cancel":1) BUT=$? if [ $BUT = 1 ]; then $MAIN & exit elif [ $BUT = 252 ]; then exit fi RCALL=$(echo $REMOVE | awk -F "|" '{print $1}') RCALL1=$(echo "\"$RCALL\"") #check something was selected if [ -z "$RCALL" ]; then yad --title="No Selection" --width=300 --height=100 \ --image $LOGO --window-icon=$LOGO --image-on-top \ --center --form --text="No station was selected\r Please try again" \ --button=gtk-ok $MAIN & exit fi jq 'del(.connect_aliases.'$RCALL1')' $PATCONFIG > $TEMP cp $TEMP $PATCONFIG rm $TEMP $OUTFILE sudo killall pat sudo systemctl start pat@$WHO yad --title="Alias Deleted" --width=400 --height=200 \ --image $LOGO --window-icon=$LOGO --image-on-top \ --center --text="$RCALL1 Alias DELETED" \ --button=gtk-ok $MAIN & exit } LOGIN(){ CONFIG=$XDG_CONFIG_HOME/pat/config.json WHO=$(whoami) USER=$(yad --form --width=420 --text-align=center --center --title="Pat Log In/Out" --text-align=center \ --image $LOGO --window-icon=$LOGO --image-on-top --separator="|" --item-separator="|" \ --text="Pat Log In/Out by KM4ACK" \ --field="Call Sign" "" \ --field="Winlink Password" "" \ --field="Six Character Grid Square" "EM65TV" \ --button="Log In":2 \ --button="Log Out":3 \ --button="Cancel":1) BUT=$? if [ $BUT = 252 ]; then echo "true exit" exit elif [ $BUT = 1 ]; then echo "cancel" elif [ $BUT = 2 ]; then echo "Log IN" CALLSIGN=$(echo $USER | awk -F "|" '{print $1}') CALLSIGN=$(echo "${CALLSIGN^^}") PASS=$(echo $USER | awk -F "|" '{print $2}') GRID=$(echo $USER | awk -F "|" '{print $3}') GRID=$(echo "${GRID^^}") echo "$CALLSIGN $PASS $GRID" #set callsign sed -i "s/\"mycall\": \".*\",/\"mycall\": \"$CALLSIGN\",/" $CONFIG #set password sed -i "s/\"secure_login_password\": \".*\",/\"secure_login_password\": \"$PASS\",/" $CONFIG #set locator sed -i "s/\"locator\": \".*\",/\"locator\": \"$GRID\",/" $CONFIG sudo systemctl restart pat@$WHO $MAIN & exit elif [ $BUT = 3 ]; then echo "Log OUT" CALLSIGN=N0CALL PASS="" GRID="" #set callsign sed -i "s/\"mycall\": \".*\",/\"mycall\": \"$CALLSIGN\",/" $CONFIG #set password sed -i "s/\"secure_login_password\": \".*\",/\"secure_login_password\": \"$PASS\",/" $CONFIG #set locator sed -i "s/\"locator\": \".*\",/\"locator\": \"$GRID\",/" $CONFIG sudo killall pat $MAIN & exit fi } GPSGRID(){ CONFIG=$XDG_CONFIG_HOME/pat/config.json if ! hash ruby2.3 2>/dev/null; then echo "Ruby Not found on system" yad --form --width=300 --text-align=center --center --title="Ruby not Found" --text-align=center \ --image $LOGO --window-icon=$LOGO --image-on-top --separator="|" --item-separator="|" \ --text="Ruby is needed to read GPS data but not found installed on your system. Would you like to install it now?" \ --button="Install Ruby":2 \ --button="Cancel":1 BUT=$? if [ $BUT = 1 ]; then $MAIN & exit elif [ $BUT = 2 ]; then INSTALLRUBY(){ sudo apt-get update sudo apt-get install -y ruby2.3 sudo gem install gpsd_client sudo gem install maidenhead } INSTALLRUBY | yad --center --progress --pulsate --auto-close --no-buttons --text-align=center \ --text="Installing Ruby. This will take several minutes\rDO NOT CLOSE THIS WINDOW\rDoing so will abort the install." fi fi yad --center --timeout=5 --timeout-indicator=top \ --auto-close --no-buttons --text="Getting grid from GPS" & NEWGRID=$($MYPATH/getgrid | cut -b 1-6) if [ "$NEWGRID" = 'JJ00aa' ]; then NEWGRID="GPS READ ERROR or NO LOCK" yad --form --width=400 --text-align=center --center --title="GPS ERROR" --text-align=center \ --image $LOGO --window-icon=$LOGO --image-on-top --separator="|" --item-separator="|" \ --text="Update Pat Grid by KM4ACK\r\rGPS ERROR" \ --field="Grid read from GPS":RO "$NEWGRID" \ --button=gtk-quit $MAIN & exit fi yad --form --width=200 --text-align=center --center --title="Update Grid" --text-align=center \ --image $LOGO --window-icon=$LOGO --image-on-top --separator="|" --item-separator="|" \ --text="Update Pat Grid by KM4ACK" \ --field="Grid read from GPS":RO "$NEWGRID" \ --button="Update Pat":2 \ --button="Cancel":1 BUT=$? if [ $BUT = 1 ]; then $MAIN & exit elif [ $BUT = 2 ]; then sed -i "s/\"locator\": \".*\",/\"locator\": \"$NEWGRID\",/" $CONFIG yad --center --timeout=2 --timeout-indicator=top \ --auto-close --no-buttons --text="Grid Square Updated" $MAIN & exit fi } RESTORECONFIG(){ CONFIG=$XDG_CONFIG_HOME/pat/config.json OUTFILE=/run/user/$UID/config.list WHO=$(whoami) ls $XDG_CONFIG_HOME/pat/ | grep .bkup > $OUTFILE INFO=$(PARSER='OFS="\n" {print $1}' tail -10 $OUTFILE | awk "$PARSER" | \ yad --title="Restore Config" --width=1100 --height=500 \ --image $LOGO --window-icon=$LOGO --image-on-top \ --center --list --text="Choose File to Restore" \ --column File-to-Restore \ --button="Cancel":1 \ --button="Restore File":2) BUT=$? if [ $BUT = 252 ]; then exit elif [ $BUT = 1 ]; then $MAIN exit fi FILE=$(echo $INFO | awk -F "|" '{print $1}') cp $XDG_CONFIG_HOME/pat/$FILE $CONFIG sudo killall pat sudo systemctl start pat@$WHO yad --form --width=420 --text-align=center --center --title="Config Restore" --text-align=center \ --image $LOGO --window-icon=$LOGO --image-on-top --separator="|" --item-separator="|" \ --text="Config Restore by KM4ACK\r\rRESTROE COMPLETE" \ --button=gtk-ok $MAIN } BKUPCONFIG(){ CONFIG=$XDG_CONFIG_HOME/pat/config.json WHO=$(whoami) DATE=$(date +%d%b%Y-%H%M) yad --form --width=420 --text-align=center --center --title="Backup Config" --text-align=center \ --image $LOGO --window-icon=$LOGO --image-on-top --separator="|" --item-separator="|" \ --text="Backup Pat Config by KM4ACK" \ --button="Backup Config":2 \ --button="Main Menu":1 BUT=$? if [ $BUT = 1 ]; then $MAIN & exit elif [ $BUT = 252 ]; then exit elif [ $BUT = 2 ]; then echo "Backing up file" BKUPCONFIG=config.$DATE.bkup cp $CONFIG $XDG_CONFIG_HOME/pat/$BKUPCONFIG yad --form --width=420 --text-align=center --center --title="Config Backup" --text-align=center \ --image $LOGO --window-icon=$LOGO --image-on-top --separator="|" --item-separator="|" \ --text="Config File Backup by KM4ACK\r\rBackup COMPLETE" \ --button=gtk-ok fi $MAIN } SPEED(){ CONFIG=$XDG_CONFIG_HOME/pat/config.json CURRENT=$(cat $CONFIG | grep -i max | sed 's/"Max":\ //' | tr -d "[:blank:]") WHO=$(whoami) NEW=$(yad --form --width=320 --text-align=center --center --title="Speed" --text-align=center \ --image $LOGO --window-icon=$LOGO --image-on-top --separator="|" --item-separator="|" \ --text="Current ARDOP Speed is $CURRENT" \ --field="Set ARDOP Speed to":CB "200|500|1000|2000" \ --button="Cancel":1 \ --button="Set Speed":2) BUT=$? if [ $BUT = 1 ]; then $MAIN & exit elif [ $BUT = 252 ]; then exit fi NEW=$(echo $NEW | awk -F "|" '{print $1}') sed -i "s/\"Max\":.*/ \"Max\": $NEW/" $CONFIG sudo killall pat sudo systemctl start pat@$WHO yad --form --width=320 --text-align=center --center --title="Speed" --text-align=center \ --image $LOGO --window-icon=$LOGO --image-on-top --separator="|" --item-separator="|" \ --text="ARDOP Speed set to $NEW" \ --button=gtk-ok $MAIN & exit } SETPTT(){ CONFIG=$XDG_CONFIG_HOME/pat/config.json WHO=$(whoami) CURRENT=$(cat $CONFIG | grep ptt_ctrl | tail -1 | sed 's/"ptt_ctrl":\ //' | sed 's/,//' | tr -d "[:blank:]") PTT=$(yad --form --width=400 --text="Current Pat ARDOP PTT = $CURRENT" --text-align=center --center --title="Set PTT" --text-align=center \ --separator="|" --item-separator="|" \ --image=$LOGO --window-icon=$LOGO --image-on-top \ --field="ARDOP PTT":CB "true|false" \ --button="Set PTT":2 \ --button="Cancel":1) QUIT=$? if [ $QUIT = 1 ]; then $MAIN & exit elif [ $QUIT = 252 ]; then exit fi ANS=$(echo $PTT | awk -F "|" '{print $1}') CURRENT=$(cat $CONFIG | grep ptt_ctrl | tail -1 | sed 's/"ptt_ctrl":\ //' | sed 's/,//') echo "Set $CURRENT to $ANS" if [ $CURRENT = 'false' ]; then sed -i "s/\"ptt_ctrl\":\ false,/\"ptt_ctrl\":\ $ANS,/" $CONFIG elif [ $CURRENT = 'true' ]; then sed -i "s/\"ptt_ctrl\":\ true,/\"ptt_ctrl\":\ $ANS,/" $CONFIG fi sudo killall pat sudo systemctl start pat@$WHO yad --form --width=400 --text-align=center --center --title="Set PTT" --text-align=center \ --separator="|" --item-separator="|" \ --image=$LOGO --window-icon=$LOGO --image-on-top \ --text="Pat ARDOP PTT now set to $ANS" \ --button=gtk-ok $MAIN & exit } MANUALGPS() { WHO=$(whoami) CONFIG=$XDG_CONFIG_HOME/pat/config.json GRID=$(yad --form --width=400 --text-align=center --center --title="Set Grid" --text-align=center \ --image $LOGO --window-icon=$LOGO --image-on-top --separator="|" --item-separator="|" \ --text="Update Pat Grid by KM4ACK" \ --field="Six Character Grid": "$NEWGRID" \ --button="Update Grid":2 \ --button="Cancel":1) BUT=$? if [ $BUT = 252 ]; then exit fi if [ $BUT = 1 ]; then $MAIN & exit fi NEWGRID=$(echo $GRID | awk -F "|" '{print $1}') NEWGRID=${NEWGRID^^} sed -i "s/\"locator\": \".*\",/\"locator\": \"$NEWGRID\",/" $CONFIG echo "GRID UPDATED" sudo killall pat sudo systemctl start pat@$WHO yad --form --width=400 --text-align=center --center --title="Grid Update" --text-align=center \ --image $LOGO --window-icon=$LOGO --image-on-top --separator="|" --item-separator="|" \ --text="Grid Updated to $NEWGRID" \ --button=gtk-ok $MAIN } LISTEN(){ #This funtion sets the listen modes for Pat Winlink WHO=$(whoami) TEMP=/run/user/$UID/listen.txt NOW=$(grep ExecStart /lib/systemd/system/pat@.service | sed 's|ExecStart=/usr/bin/pat -l||;s/http//') if [ $NOW = 'ExecStart=/usr/bin/pat' ]; then NOW="Not listening for incoming connections" fi LISTEN=$(yad --center --list --checklist --width=600 --height=300 --separator="|" \ --image $LOGO --column=Check --column=Mode --column=Description \ --print-column=2 --window-icon=$LOGO --image-on-top --text-align=center \ --text="Pat Listen Modes\rCurrently Listening on:\r$NOW" --title="Pat Menu" \ false "TELNET" "Connection over Internet or Mesh" \ false "AX25" "Packet Connections 2M-440" \ false "ARDOP" "HF Connections using ARDOP Modem" \ --button="Main Menu":1 \ --button="Set Listen Mode":2 \ --button="Stop Listening":3) BUT=$? if [ $BUT = 252 ]; then exit elif [ $BUT = 1 ]; then $MAIN & exit elif [ $BUT = 2 ]; then #Send results to temp file. echo $LISTEN > $TEMP #check temp file for what's there TELNET=$(grep TELNET $TEMP) ARDOP=$(grep ARDOP $TEMP) AX25=$(grep AX25 $TEMP) #Set telnet variable if [ -n "$TELNET" ]; then TELNET="telnet," fi #set ardop variable if [ -n "$ARDOP" ]; then ARDOP="ardop," fi #set ax25 variable if [ -n "$AX25" ]; then AX25="ax25," fi cat < $TEMP [Unit] Description=pat - Winlink client for %I Documentation=https://github.com/la5nta/pat/wiki After=ax25.service network.target [Service] User=%i ExecStart=/usr/bin/pat http Restart=on-failure [Install] WantedBy=multi-user.target EOF #add listen modes set by user sed -i "s|Exec.*|ExecStart=/usr/bin/pat -l $TELNET$ARDOP$AX25 http|" $TEMP sudo cp $TEMP /lib/systemd/system/pat@.service sudo systemctl daemon-reload sudo systemctl restart pat@$WHO yad --form --width=320 --text-align=center --center --title="Listening" --text-align=center \ --image $LOGO --window-icon=$LOGO --image-on-top --separator="|" --item-separator="|" \ --text="Listen mode set to $TELNET$ARDOP$AX25" \ --button=gtk-ok $MAIN & exit elif [ $BUT = 3 ]; then cat < $TEMP [Unit] Description=pat - Winlink client for %I Documentation=https://github.com/la5nta/pat/wiki After=ax25.service network.target [Service] User=%i ExecStart=/usr/bin/pat http Restart=on-failure [Install] WantedBy=multi-user.target EOF sudo cp $TEMP /lib/systemd/system/pat@.service sudo systemctl daemon-reload sudo systemctl restart pat@$WHO fi yad --form --width=320 --text-align=center --center --title="Listening" --text-align=center \ --image $LOGO --window-icon=$LOGO --image-on-top --separator="|" --item-separator="|" \ --text="No longer listening for incoming connections" \ --button=gtk-ok $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 }