pi-scripts/gpsupdate

380 lines
12 KiB
Text
Raw Permalink Normal View History

2021-01-11 18:44:12 -06:00
#!/bin/bash
2022-11-22 07:25:10 -06:00
VERSION=6
2021-01-11 18:44:12 -06:00
#script to change GPS in gpsd file and restart gpsd service
2021-02-18 15:06:59 -06:00
#reference - https://www.linux-magazine.com/Issues/2018/210/Tutorial-gpsd
#11JAN2021 KM4ACK
2021-02-06 07:07:11 -06:00
2022-11-22 07:25:10 -06:00
LOGO=$HOME/73Linux/data/ico/gps.png
2021-01-11 18:44:12 -06:00
2022-11-22 07:25:10 -06:00
PASS=$(yad --entry --width=420 --text-align=center --center --title="GPS Update Tool" \
--image ${LOGO} --window-icon=${LOGO} --image-on-top --separator="|" --item-separator="|" --hide-text \
--text="Required\rBad password will cause program to exit" \
--entry-label="Sudo Password*" \
--button="Continue":2)
BUT=$?
if [ ${BUT} = 252 ]; then
exit
fi
PASS=$(echo $PASS | awk -F "|" '{print $1}')
#reset sudo timer to prevent false positive
sudo -k
echo "Checking SUDO credentials....standby"
echo $PASS | sudo -S touch /run/user/$UID/sutest
if [ $? = 1 ]; then
yad --form --width=250 --text-align=center --center --title="Wrong Password" --text-align=center \
--image ${LOGO} --window-icon=${LOGO} --image-on-top --separator="|" --item-separator="|" \
--text="<b>Password Incorrect!</b>\rCan't continue" \
--button=gtk-close
exit
else
echo "Credentials check out....continuing"
fi
2021-02-18 15:06:59 -06:00
2021-01-11 18:44:12 -06:00
#Verify YAD is installed
if ! hash yad 2>/dev/null; then
2022-11-22 07:25:10 -06:00
echo "Installing YAD....please wait"
echo $PASS | sudo -S apt install -y yad
2021-01-11 18:44:12 -06:00
fi
2021-02-18 15:06:59 -06:00
#####################################
# Help File
#####################################
HELP(){
cat <<EOF > /run/user/$UID/gpsintro.txt
GPS Update Tool Version $VERSION by KM4ACK
This tool allows you to update the required files
when you change between different GPS units/types.
USB GPS DEVICES:
Multiple USB choices may be available to choose
from if you have several USB devices connected
to your pi. If you have trouble identifying which
of the choices is your GPS, try unplugging all
USB componets except your GPS and run this script
again.
STREAM MOBILE PHONE GPS:
Both your pi and your mobile phone MUST be
on the same network for this to function.
To stream your phone GPS you will need an
app on your phone. For iPhone see
https://itunes.apple.com/us/app/gps-2-ip/id408625926?mt=8
For Android phones see
https://play.google.com/store/apps/details?id=io.github.tiagoshibata.gpsdclient
Set the app in UDP or UDP Push mode. Set the IP
address to be the same as your Raspberry Pi. To
find the IP address of the Pi, run:
hostname -I
from the command line. After choosing "Phone" from
the dropdown, again enter your Pi's IP address
and the same port that you entered in the app
on your phone. If you are in the field, your pi will
likely be in "hotspot" mode. In this configuration
connect your phone to the hotspot via WiFi. Then
use the IP address of 10.10.10.10 both in this script
and in the app on your phone.
BLUETOOTH GPS:
Bluetooth GPS is considered beta as I don't have a
bluetooth GPS unit to test with. This assumes that
the GPS unit is attach to an rfcomm port. You will
need to know the rfcomm port number to use this feature.
This script will not help you connect the GPS to the Pi
via bluetooth. If you own a Bluetooth GPS and find that
this section will not work for you, please file an
issue ticket at github.
https://github.com/km4ack/pi-scripts/issues
Serial GPS:
You will need to know the serial port number to
which the GPS is attached. After choosing serial
GPS as your GPS type, enter the serial number
that the GPS is attached to.
CHANGELOG:
To see the changelog for this script run:
gpsupdate change
from the command line.
EOF
INTRO=$(yad --width=650 --height=400 --text-align=center --center --title="GPS Update Tool" \
--image $LOGO --window-icon=$LOGO --image-on-top --separator="|" --item-separator="|" \
--text="<b>GPS Update v$VERSION by KM4ACK</b>" \
--text-info</run/user/$UID/gpsintro.txt \
--button="Exit":0 > /dev/null 2>&1 \
--button="Continue":1)
BUT=$?
if [ $BUT = 252 ] || [ $BUT = 0 ]; then
2022-11-22 07:25:10 -06:00
rm /run/user/$UID/gpsintro.txt
exit
2021-02-18 15:06:59 -06:00
fi
rm /run/user/$UID/gpsintro.txt
}
#####################################
# Display Changelog
#####################################
CHANGELOG(){
clear;echo;echo
cat <<EOF>/run/user/$UID/changelog.txt
2022-11-22 07:25:10 -06:00
Version 6 18OCT2022
add sudo password to support x86
2021-10-29 05:01:46 -05:00
Version 5 29OCT2021
add defaults for phone GPS
2021-09-18 08:05:26 -05:00
Version 4 06SEPT0221
add gpsd restart to main screen
2021-02-18 15:06:59 -06:00
Version 3 11FEB2021
add bluetooth GPS support
add cell phone GPS support
add changelog function
add additional user instructions
change sed command when modding gpsd file
move USBGPS to funtion
move help file to function
add help option to main script
move main menu to function
bump version number
Version 2 06FEB2021
add serial GPS support
bump version number
Verions 1 11JAN2021
script created to help swap between multiple GPS devices
EOF
INTRO=$(yad --width=650 --height=350 --text-align=center --center --title="GPS Update Tool by KM4ACK - Changelog" --show-uri \
--image $LOGO --window-icon=$LOGO --image-on-top --separator="|" --item-separator="|" \
--text-info</run/user/$UID/changelog.txt \
--button="Exit":2 > /dev/null 2>&1)
BUT=$?
if [ $BUT = 252 ] || [ $BUT = 2 ]; then
2022-11-22 07:25:10 -06:00
rm /run/user/$UID/changelog.txt
exit
2021-02-18 15:06:59 -06:00
fi
rm /run/user/$UID/changelog.txt
exit
}
if [ $1 = 'change' ]>/dev/null 2>&1; then
2022-11-22 07:25:10 -06:00
CHANGELOG
2021-02-18 15:06:59 -06:00
fi
#Verify gpsd is installed
2021-02-06 07:07:11 -06:00
if ! hash gpsd 2>/dev/null; then
2022-11-22 07:25:10 -06:00
yad --center --height="300" --width="400" --form --separator="|" --item-separator="|" --title="GPS" \
--image $LOGO --window-icon=$LOGO --image-on-top \
--text="\r\r\r<b><big>GPS software not installed.\rPlease install and try again.</big></b>" \
--button="Exit":1
2021-02-06 07:07:11 -06:00
fi
2021-02-18 15:06:59 -06:00
#####################################
# Phone GPS Function
#####################################
PHONEGPS(){
2021-10-29 05:01:46 -05:00
IP=*
PORT=11123
2021-02-18 15:06:59 -06:00
PHONEPORT=$(yad --form --width=420 --text-align=center --center --title="GPS Update Tool" \
--image $LOGO --window-icon=$LOGO --image-on-top --separator="|" --item-separator="|" \
--text="<b>version $VERSION</b>" \
--text="\rEnter IP addr and port number for GPS\rSee help file for more information" \
2021-10-29 05:01:46 -05:00
--field="IP Addr" "$IP" \
--field="Port Number" "$PORT" \
2021-02-18 15:06:59 -06:00
--button="Continue":2 \
--button="Exit":1)
BUT=$?
MYIP=$(echo $PHONEPORT | awk -F "|" '{print $1}')
MYPORT=$(echo $PHONEPORT | awk -F "|" '{print $2}')
if [ $BUT = 252 ] || [ $BUT = 1 ]; then
2022-11-22 07:25:10 -06:00
exit
2021-02-18 15:06:59 -06:00
fi
##############################################################
#This section mods the gpsd file and restart the gpsd service#
##############################################################
cp /etc/default/gpsd /run/user/$UID
sed -i "s|DEVICES=.*|DEVICES=\"udp://$MYIP:$MYPORT\"|" /run/user/$UID/gpsd
2022-11-22 07:25:10 -06:00
echo $PASS | sudo -S cp /run/user/$UID/gpsd /etc/default/
2021-02-18 15:06:59 -06:00
2022-11-22 07:25:10 -06:00
echo $PASS | sudo -S systemctl restart gpsd
2021-02-18 15:06:59 -06:00
yad --center --height="300" --width="300" --form --separator="|" --item-separator="|" --title="GPS" \
--image $LOGO --window-icon=$LOGO --image-on-top \
--text="\r\r\r\r\r<b><big>GPS had been updated</big></b>" \
--button="Exit":1
exit
}
2021-01-11 18:44:12 -06:00
2021-02-06 07:07:11 -06:00
#####################################
2021-02-18 15:06:59 -06:00
# serial GPS Function
2021-02-06 07:07:11 -06:00
#####################################
2021-02-18 15:06:59 -06:00
#For those that use a serial GPS hat like https://www.adafruit.com/product/2324
2021-02-06 07:07:11 -06:00
SERIALGPS(){
2021-02-18 15:06:59 -06:00
SERIALPORT=$(yad --form --width=420 --text-align=center --center --title="GPS Update Tool" \
2021-02-06 07:07:11 -06:00
--image $LOGO --window-icon=$LOGO --image-on-top --separator="|" --item-separator="|" \
--text="<b>version $VERSION</b>" \
--text="\rEnter serial port number for GPS" \
--field="Serial Port Number" \
--button="Continue":2 \
--button="Exit":1)
BUT=$?
MYPORT=$(echo $SERIALPORT | awk -F "|" '{print $1}')
if [ $BUT = 252 ] || [ $BUT = 1 ]; then
2022-11-22 07:25:10 -06:00
exit
2021-02-06 07:07:11 -06:00
fi
##############################################################
#This section mods the gpsd file and restart the gpsd service#
##############################################################
cp /etc/default/gpsd /run/user/$UID
2021-02-18 15:06:59 -06:00
sed -i "s|DEVICES=.*|DEVICES=\"/dev/serial$MYPORT\"|" /run/user/$UID/gpsd
2021-02-06 07:07:11 -06:00
2022-11-22 07:25:10 -06:00
echo $PASS | sudo -S cp /run/user/$UID/gpsd /etc/default/
2021-02-06 07:07:11 -06:00
2022-11-22 07:25:10 -06:00
echo $PASS | sudo -S systemctl restart gpsd
2021-02-06 07:07:11 -06:00
yad --center --height="300" --width="300" --form --separator="|" --item-separator="|" --title="GPS" \
--image $LOGO --window-icon=$LOGO --image-on-top \
--text="\r\r\r\r\r<b><big>GPS had been updated</big></b>" \
--button="Exit":1
exit
}
2021-01-11 18:44:12 -06:00
#####################################
2021-02-18 15:06:59 -06:00
# bluetooth GPS Function
2021-01-11 18:44:12 -06:00
#####################################
2021-02-18 15:06:59 -06:00
#Section used by hams that use a serial GPS hat like https://www.adafruit.com/product/2324
2021-01-11 18:44:12 -06:00
2021-02-18 15:06:59 -06:00
BLUEGPS(){
BLUEPORT=$(yad --form --width=420 --text-align=center --center --title="GPS Update Tool" \
2021-02-06 07:07:11 -06:00
--image $LOGO --window-icon=$LOGO --image-on-top --separator="|" --item-separator="|" \
--text="<b>version $VERSION</b>" \
2021-02-18 15:06:59 -06:00
--text="\rEnter rfcomm port number for GPS" \
--field="Rfcomm Port Number" \
2021-02-06 07:07:11 -06:00
--button="Continue":2 \
--button="Exit":1)
BUT=$?
2021-02-18 15:06:59 -06:00
MYPORT=$(echo $BLUEPORT | awk -F "|" '{print $1}')
if [ $BUT = 252 ] || [ $BUT = 1 ]; then
2022-11-22 07:25:10 -06:00
exit
2021-02-18 15:06:59 -06:00
fi
##############################################################
#This section mods the gpsd file and restart the gpsd service#
##############################################################
cp /etc/default/gpsd /run/user/$UID
sed -i "s|DEVICES=.*|DEVICES=\"/dev/rfcomm$MYPORT\"|" /run/user/$UID/gpsd
2022-11-22 07:25:10 -06:00
echo $PASS | sudo -S cp /run/user/$UID/gpsd /etc/default/
2021-02-18 15:06:59 -06:00
2022-11-22 07:25:10 -06:00
echo $PASS | sudo -S systemctl restart gpsd
2021-02-18 15:06:59 -06:00
yad --center --height="300" --width="300" --form --separator="|" --item-separator="|" --title="GPS" \
--image $LOGO --window-icon=$LOGO --image-on-top \
--text="\r\r\r\r\r<b><big>GPS had been updated</big></b>" \
--button="Exit":1
2021-02-06 07:07:11 -06:00
exit
2021-02-18 15:06:59 -06:00
}
2021-02-06 07:07:11 -06:00
2021-02-18 15:06:59 -06:00
#####################################
# USB GPS Function
#####################################
USBGPS(){
2021-01-11 18:44:12 -06:00
#######################################################
#This section allows the user to identify the GPS unit#
#######################################################
yad --center --height="200" --width="200" --form --separator="|" --item-separator="|" --title="GPS" \
--image $LOGO --window-icon=$LOGO --image-on-top \
2021-02-06 07:07:11 -06:00
--text="\r\r\r<b><big>Connect your GPS to the pi</big></b>" \
2021-01-11 18:44:12 -06:00
--button="Exit":1 \
--button="Continue":2
BUT=$?
if [ $BUT = 1 ] || [ $BUT = 252 ]; then
2022-11-22 07:25:10 -06:00
exit
2021-01-11 18:44:12 -06:00
fi
USB=$(ls /dev/serial/by-id)
USB=$(echo $USB | sed "s/\s/|/g")
GPS=$(yad --center --height="200" --width="300" --form --separator="|" --item-separator="|" --title="GPS" \
--image $LOGO --window-icon=$LOGO --image-on-top \
2021-02-06 07:07:11 -06:00
--text="<b>Choose Your GPS</b>" \
2021-01-11 18:44:12 -06:00
--field="GPS":CB "$USB")
BUT=$?
if [ $BUT = 252 ] || [ $BUT = 1 ]; then
2022-11-22 07:25:10 -06:00
exit
2021-01-11 18:44:12 -06:00
fi
GPS=$(echo $GPS | awk -F "|" '{print $1}')
##############################################################
#This section mods the gpsd file and restart the gpsd service#
##############################################################
cp /etc/default/gpsd /run/user/$UID
2021-02-18 15:06:59 -06:00
sed -i "s|DEVICES=.*|DEVICES=\"/dev/serial/by-id/$GPS\"|" /run/user/$UID/gpsd
2021-01-11 18:44:12 -06:00
2022-11-22 07:25:10 -06:00
echo $PASS | sudo -S cp /run/user/$UID/gpsd /etc/default/
2021-01-11 18:44:12 -06:00
2022-11-22 07:25:10 -06:00
echo $PASS | sudo -S systemctl restart gpsd
2021-01-11 18:44:12 -06:00
yad --center --height="300" --width="300" --form --separator="|" --item-separator="|" --title="GPS" \
--image $LOGO --window-icon=$LOGO --image-on-top \
--text="\r\r\r\r\r<b><big>GPS had been updated</big></b>" \
--button="Exit":1
2021-02-18 15:06:59 -06:00
}
MAIN(){
#######################################################
# Choose GPS Type :: Serial,USB,Bluetooth,Phone #
#######################################################
GPSTYPE=$(yad --form --width=420 --text-align=center --center --title="GPS Update Tool" \
--image $LOGO --window-icon=$LOGO --image-on-top --separator="|" --item-separator="|" \
--text="GPS Update Tool <b>v$VERSION</b> by KM4ACK" \
--field="Choose GPS Type or Help":CB "Help|USB|Serial|Bluetooth|Phone" \
2021-09-18 08:05:26 -05:00
--button="Restart GPSD":3 \
2021-02-18 15:06:59 -06:00
--button="Continue":2 \
--button="Exit":1)
BUT=$?
if [ $BUT = 1 ] || [ $BUT = 252 ]; then
2022-11-22 07:25:10 -06:00
exit
2021-02-18 15:06:59 -06:00
fi
2021-09-18 08:05:26 -05:00
if [ $BUT = 3 ]; then
2022-11-22 07:25:10 -06:00
echo "restarting gpsd service"
echo $PASS | sudo -S systemctl restart gpsd
yad --center --height="300" --width="300" --form --separator="|" --item-separator="|" --title="GPS" \
--image $LOGO --window-icon=$LOGO --image-on-top \
--text="\r\r\r\r\r<b><big>gpsd service restarted</big></b>" \
--button="Ok":1
MAIN
2021-09-18 08:05:26 -05:00
fi
2021-02-18 15:06:59 -06:00
MYGPS=$(echo $GPSTYPE | awk -F "|" '{print $1}')
if [ $MYGPS = 'Serial' ]; then
2022-11-22 07:25:10 -06:00
SERIALGPS
2021-02-18 15:06:59 -06:00
elif [ $MYGPS = 'Bluetooth' ]; then
2022-11-22 07:25:10 -06:00
BLUEGPS
2021-02-18 15:06:59 -06:00
elif [ $MYGPS = 'Phone' ]; then
2022-11-22 07:25:10 -06:00
PHONEGPS
2021-02-18 15:06:59 -06:00
elif [ $MYGPS = 'USB' ]; then
2022-11-22 07:25:10 -06:00
USBGPS
2021-02-18 15:06:59 -06:00
elif [ $MYGPS = 'Help' ]; then
2022-11-22 07:25:10 -06:00
HELP
MAIN
2021-02-18 15:06:59 -06:00
fi
}
MAIN