-
Notifications
You must be signed in to change notification settings - Fork 11
/
vigiupdate.sh
executable file
·110 lines (89 loc) · 1.87 KB
/
vigiupdate.sh
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
#!/bin/bash
set -e
set -u
BASEURL=https://www.vigibot.com/vigiclient
BASEDIR=/usr/local/vigiclient
updated=no
trace() {
echo "$(date "+%d/%m/%Y %H:%M:%S") $1"
}
abnormal() {
trace "Abnormal script termination"
}
check() {
before=$(date -r $1/$2 +%s 2> /dev/null || echo 0)
wget $BASEURL/$2 -P $1 -N -T 20 -t 3 > /dev/null 2>&1 || trace "$1/$2 wget error"
after=$(date -r $1/$2 +%s)
if [ $after -gt $before ]
then
trace "$1/$2 is updated"
updated=yes
else
trace "$1/$2 is not changed"
fi
}
trap abnormal EXIT
check $BASEDIR vigiupdate.sh
check /etc/cron.d vigicron
if [ $updated == yes ]
then
trace "Purging updater log"
rm -f /var/log/vigiupdate.log
trace "Exiting"
trap - EXIT
exit 0
fi
check /etc/systemd/system vigiclient.service
check /etc/systemd/system socat.service
if [ $updated == yes ]
then
trace "Rebooting"
trap - EXIT
sudo reboot
fi
if pidof -x $0 -o $$ > /dev/null
then
trace "Only one instance is allowed from here"
trap - EXIT
exit 1
fi
timedatectl status | fgrep "synchronized: yes" > /dev/null || {
trace "System clock must be synchronized from here"
trap - EXIT
exit 1
}
check $BASEDIR node_modules.tar.gz
check $BASEDIR package.json
if [ $updated == yes ]
then
trace "Purging node_modules directory"
cd $BASEDIR
rm -rf node_modules
trace "Extracting node_modules.tar.gz"
tar xf node_modules.tar.gz
fi
check $BASEDIR clientrobotpi.js
check $BASEDIR sys.json
check $BASEDIR trame.js
if [ $updated == yes ]
then
trace "Purging vigiclient.log"
rm -f /var/log/vigiclient.log
trace "Restarting vigiclient service"
systemctl restart vigiclient
trap - EXIT
exit 0
fi
check $BASEDIR opencv.tar.gz
if [ $updated == yes ]
then
cd $BASEDIR
trace "Extracting opencv.tar.gz"
tar -x --keep-newer-files -f opencv.tar.gz
trace "Purging opencv binaries"
cd opencv
find -name bin -delete
trace "Compiling opencv binaries"
./make.sh
fi
trap - EXIT