forked from km4ack/pi-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpsupdate
More file actions
379 lines (324 loc) · 12.1 KB
/
gpsupdate
File metadata and controls
379 lines (324 loc) · 12.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
#!/bin/bash
VERSION=6
#script to change GPS in gpsd file and restart gpsd service
#reference - https://www.linux-magazine.com/Issues/2018/210/Tutorial-gpsd
#11JAN2021 KM4ACK
LOGO=$HOME/73Linux/data/ico/gps.png
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
#Verify YAD is installed
if ! hash yad 2>/dev/null; then
echo "Installing YAD....please wait"
echo $PASS | sudo -S apt install -y yad
fi
#####################################
# 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
rm /run/user/$UID/gpsintro.txt
exit
fi
rm /run/user/$UID/gpsintro.txt
}
#####################################
# Display Changelog
#####################################
CHANGELOG(){
clear;echo;echo
cat <<EOF>/run/user/$UID/changelog.txt
Version 6 18OCT2022
add sudo password to support x86
Version 5 29OCT2021
add defaults for phone GPS
Version 4 06SEPT0221
add gpsd restart to main screen
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
rm /run/user/$UID/changelog.txt
exit
fi
rm /run/user/$UID/changelog.txt
exit
}
if [ $1 = 'change' ]>/dev/null 2>&1; then
CHANGELOG
fi
#Verify gpsd is installed
if ! hash gpsd 2>/dev/null; then
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
fi
#####################################
# Phone GPS Function
#####################################
PHONEGPS(){
IP=*
PORT=11123
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" \
--field="IP Addr" "$IP" \
--field="Port Number" "$PORT" \
--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
exit
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
echo $PASS | sudo -S cp /run/user/$UID/gpsd /etc/default/
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>GPS had been updated</big></b>" \
--button="Exit":1
exit
}
#####################################
# serial GPS Function
#####################################
#For those that use a serial GPS hat like https://www.adafruit.com/product/2324
SERIALGPS(){
SERIALPORT=$(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 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
exit
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/serial$MYPORT\"|" /run/user/$UID/gpsd
echo $PASS | sudo -S cp /run/user/$UID/gpsd /etc/default/
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>GPS had been updated</big></b>" \
--button="Exit":1
exit
}
#####################################
# bluetooth GPS Function
#####################################
#Section used by hams that use a serial GPS hat like https://www.adafruit.com/product/2324
BLUEGPS(){
BLUEPORT=$(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 rfcomm port number for GPS" \
--field="Rfcomm Port Number" \
--button="Continue":2 \
--button="Exit":1)
BUT=$?
MYPORT=$(echo $BLUEPORT | awk -F "|" '{print $1}')
if [ $BUT = 252 ] || [ $BUT = 1 ]; then
exit
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
echo $PASS | sudo -S cp /run/user/$UID/gpsd /etc/default/
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>GPS had been updated</big></b>" \
--button="Exit":1
exit
}
#####################################
# USB GPS Function
#####################################
USBGPS(){
#######################################################
#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 \
--text="\r\r\r<b><big>Connect your GPS to the pi</big></b>" \
--button="Exit":1 \
--button="Continue":2
BUT=$?
if [ $BUT = 1 ] || [ $BUT = 252 ]; then
exit
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 \
--text="<b>Choose Your GPS</b>" \
--field="GPS":CB "$USB")
BUT=$?
if [ $BUT = 252 ] || [ $BUT = 1 ]; then
exit
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
sed -i "s|DEVICES=.*|DEVICES=\"/dev/serial/by-id/$GPS\"|" /run/user/$UID/gpsd
echo $PASS | sudo -S cp /run/user/$UID/gpsd /etc/default/
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>GPS had been updated</big></b>" \
--button="Exit":1
}
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" \
--button="Restart GPSD":3 \
--button="Continue":2 \
--button="Exit":1)
BUT=$?
if [ $BUT = 1 ] || [ $BUT = 252 ]; then
exit
fi
if [ $BUT = 3 ]; then
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
fi
MYGPS=$(echo $GPSTYPE | awk -F "|" '{print $1}')
if [ $MYGPS = 'Serial' ]; then
SERIALGPS
elif [ $MYGPS = 'Bluetooth' ]; then
BLUEGPS
elif [ $MYGPS = 'Phone' ]; then
PHONEGPS
elif [ $MYGPS = 'USB' ]; then
USBGPS
elif [ $MYGPS = 'Help' ]; then
HELP
MAIN
fi
}
MAIN