-
Notifications
You must be signed in to change notification settings - Fork 0
/
rc.local
63 lines (56 loc) · 2.29 KB
/
rc.local
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
# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.
if [ ! -f /root/gps_nextcloud.sh ]; then
cat > /root/gps_nextcloud.sh << EOF
#!/bin/sh
# nextcloud url
URL="https://YOUR_NEXTCLOUD.URL"
# put your Session ID in here
SESSION="YOUR_SESSION_ID"
# put your device name in here
NAME="YOUR_DEVICE_NAME"
# log file for offline logging
OFFLINELOGFILE="/tmp/offline.log"
# update delay in seconds
DELAY=5
while :
do
FIX=\$(/usr/sbin/gpsctl -s) # get GPS status
if [ \$FIX = "1" ] # if GPS signal is present
then
LAT=\$(/usr/sbin/gpsctl -i) # get latitude
if [ "\$LAT" != "\$LATOLD" ] # check if new latitude is different from old latitude
then
LATOLD=\$LAT # set old latitude to new one
SPD=\$(/usr/sbin/gpsctl -v) # get ground speed
LON=\$(/usr/sbin/gpsctl -x) # get longitude
SAT=\$(/usr/sbin/gpsctl -p) # get connected sattelites
ALT=\$(/usr/sbin/gpsctl -a) # get altitude
ACC=\$(/usr/sbin/gpsctl -u) # get accuracy
TIMESTAMP=\$(/usr/sbin/gpsctl -t) # get gps timestamp
GPSResults="\$URL/apps/phonetrack/log/gpslogger/\$SESSION/\$NAME?lat=\$LAT&lon=\$LON&sat=\$SAT&alt=\$ALT&acc=\$ACC&speed=\$SPD×tamp=\$TIMESTAMP"
DataCheck=\$(ip addr show qmimux0 | grep "inet\b" | awk '{print \$2}' | cut -d/ -f1)
ip_full=\$(echo \$DataCheck | grep -oE '((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])') # validate IP
if [ \$ip_full != "" ] #If Valid IP
then
curl --insecure \${GPSResults// /} # send data to nextcloud
if [ -f \$OFFLINELOGFILE ] # if file exists
then
while IFS= read -r line
do
curl -k \$line
done <"\$OFFLINELOGFILE"
rm \$OFFLINELOGFILE # remove file
fi
else
echo \${GPSResults// /} >> \$OFFLINELOGFILE # log GPS data in file
fi
fi
fi
sleep \$DELAY
done
EOF
chmod +x /root/gps_nextcloud.sh
fi
/root/gps_nextcloud.sh &
exit 0