-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrc.local
executable file
·72 lines (53 loc) · 1.68 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
64
65
66
67
68
69
70
71
72
#!/bin/sh -e
#
# rc.local
#
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
#sudo systemctl stop ntp;
#sudo ntpd -q -g >> /root/time.log
sudo rfkill block bluetooth;
sudo timedatectl >> /root/git.log;
LOC='/root'
if $(cd ${LOC}/BBSensor && git status --branch --porcelain | grep -q behind); then
cd ${LOC}/BBSensor && git merge >> ${LOC}/git.log 2>&1
fi
((count = 20)) # Maximum number to try.
while [[ $count -ne 0 ]] ; do
ping -c 1 8.8.8.8 # Try once.
rc=$?
if [[ $rc -eq 0 ]] ; then
((count = 1)) # If okay, flag to exit loop.
fi
((count = count - 1)) # So we don't go forever.
done
if [[ $rc -eq 0 ]] ; then # Make final determination.
RETRIES=5
DELAY=10
COUNT=1
# Update the repo, with retries incase the sensor is not connected to the internet.
while [ $COUNT -lt $RETRIES ]; do
cd ${LOC}/BBSensor && git pull >> ${LOC}/git.log 2>&1
if [ $? -eq 0 ]; then
RETRIES=0
break
fi
let COUNT=$COUNT+1
sleep $DELAY
done
fi
# transfer rules of usb transfer if they dont exist and reboot.
if [ ! -f "/etc/udev/rules.d/optional_usb.rules" ]; then
echo "Adding USB transfer rules";
chmod a+x /root/BBSensor/usb/*;
cp /root/BBSensor/usb/optional_usb.rules /etc/udev/rules.d/;
chmod a+x /etc/udev/rules.d/optional_usb.rules;
sudo reboot
fi
sudo timedatectl >> ${LOC}/git.log 2>&1;
cd ${LOC}/BBSensor && sudo python3 -m sensorpi >> /root/sensor.log &
#echo 'bbsensor00' | sudo tee /etc/hostname
exit 0