forked from mholgatem/ThermOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.sh
More file actions
83 lines (75 loc) · 2.18 KB
/
Copy pathupdate.sh
File metadata and controls
83 lines (75 loc) · 2.18 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
UPDATER_VERSION=1.2
UPDATE_BASE=https://raw.githubusercontent.com/mholgatem/ThermOS/master/update.sh
runSelfUpdate() {
# Download new version
echo -n "Downloading latest version of updater..."
if ! wget --quiet --output-document="$0.tmp" $UPDATE_BASE ; then
echo "Failed: Could not retrieve specified file."
echo "File requested: $UPDATE_BASE"
echo "Running current version of updater..."
else
echo "Success."
# Copy over modes from old version
OCTAL_MODE=$(stat -c '%a' $0)
if ! chmod $OCTAL_MODE "$0.tmp" ; then
echo "Failed: Error while trying to set permissions for $0.tmp."
else
mv "$0.tmp" "$0"
fi
fi
exec /bin/bash $0 --no_self_update
}
runUpdate(){
#check for gunicorn
if [ "$( pip list | grep -F gunicorn)" == "" ]; then
echo "Preparing to install gunicorn"
sudo pip install gunicorn
fi
cd /home/pi/ThermOS
path="/home/pi/thermos_backup/$(date +%Y_%m_%d-%H_%M_%S)/"
echo "Creating backup in: $path"
mkdir -p "$path"
cp -rf . "$path"
if [ "$cmd" == "hard_reset" ]; then
git reset --hard origin/master
else
# stash user changes, pull update, re-add user changes
git config --global user.email "[email protected]"
git config --global user.name "[email protected]"
git checkout master
git stash
git pull
git stash pop
git config --global --unset user.email
git config --global --unset user.name
fi
#copy system services and reload
sudo cp thermostat-daemon.service /lib/systemd/system/
sudo cp thermostat-web.service /lib/systemd/system/
sudo systemctl stop thermostat-web
sudo systemctl stop thermostat-daemon
sudo systemctl daemon-reload
secs=$((1 * 60))
while [ $secs -gt 0 ]; do
echo -ne "-----> Thermostat will restart in: $secs seconds\033[0K\r"
sleep 1
: $((secs--))
done
echo "Reloading daemon and restarting services..."
sudo systemctl start thermostat-daemon
sudo systemctl start thermostat-web
}
key="$1"
cmd=""
case $key in
-h|--hard)
cmd="hard_reset"
runUpdate
;;
-n|--no_self_update)
runUpdate
;;
*)
runSelfUpdate
;;
esac