forked from openenergymonitor/emonpi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
firstbootupdate
executable file
·37 lines (29 loc) · 1.17 KB
/
firstbootupdate
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
#!/bin/bash
# Script to update new emonPi's to latest firmware and software the fist time they are booted up in the factory
# Looks to see if /home/pi/data/emonpiupdate.log exists or LCD push button (GPIO 23) is pressed (high when pressed)
# To rc.local before exit 0 add:
# su pi -c '/home/pi/emonpi/firstbootupdate'
# Check if update log file is empty if so then proceed to update
button="$(sudo cat /sys/class/gpio/gpio23/value)"
if [ ! -s /home/pi/data/emonpiupdate.log ] || [ "$button" == 1 ]; then
echo "First Boot Update.."
printf "Checking internet connectivity...wait 30s\n"
sleep 30
WGET="/usr/bin/wget"
$WGET -q --tries=20 --timeout=5 http://www.google.com -O /tmp/google.idx &> /dev/null
if [ ! -s /tmp/google.idx ]; then
echo "No Internet connection :-("
else
echo "Internet connection detected running update.."
connected=true
fi
if [ "$connected" = true ]; then
/home/pi/emonpi/service-runner-update.sh 2>&1 >> /home/pi/data/emonpiupdate.log 2>&1
# set permissions on newly created logfile so emonpiupdate script an write to it
sudo chmod 666 /home/pi/data/emonpiupdate.log
fi
else
echo "Not first boot"
exit
fi
exit