-
Notifications
You must be signed in to change notification settings - Fork 17
/
update.sh
executable file
·70 lines (65 loc) · 1.94 KB
/
update.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
#!/bin/bash
#get script path
SCRIPT=$(readlink -f $0)
SCRIPTPATH=`dirname $SCRIPT`
cd $SCRIPTPATH
VERSION=$(cat version 2>/dev/null)
OLD_VERSION=$2
#if not root user, restart script as root
if [ "$(whoami)" != "root" ]; then
echo "Switching to root user..."
sudo bash $SCRIPT $*
exit 1
fi
shopt -s nocasematch
if ! [[ "$1" == "-noupdate" ]]; then
echo "Performing self-update..."
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
exec /bin/bash update.sh -noupdate $VERSION
fi
# find current version, then fallthrough to latest version
case $OLD_VERSION in
"")
;&
"1.2")
UPDATE_VERSION=1.2
echo $UPDATE_VERSION > version
echo "Handling v1.2 updates..."
;&
"1.3")
UPDATE_VERSION=1.3
echo $UPDATE_VERSION > version
echo "Handling v1.3 updates..."
#Add uvIndex to logs.db -> hourlyWeather table
sqlite3 $SCRIPTPATH/logs/logs.db "ALTER TABLE hourlyWeather ADD COLUMN uvIndex NUMERIC"
sudo apt-get -y install nginx
#create nginx server
sudo cp $SCRIPTPATH"/nginx-thermos" /etc/nginx/sites-available/ThermOS
sudo ln -s /etc/nginx/sites-available/ThermOS /etc/nginx/sites-enabled/
sudo rm /etc/nginx/sites-enabled/default
sudo cp $SCRIPTPATH"/nginx.conf" /etc/nginx/nginx.conf
web=$SCRIPTPATH"/thermostat-web.service"
sudo cp $web /lib/systemd/system/
;&
"DONE")
wget -O version https://raw.githubusercontent.com/mholgatem/ThermOS/master/version
echo "Finished Updating...Restarting services."
;;
*)
echo "Version "$VERSION" is already newest version."
;;
esac
sudo systemctl stop thermostat-daemon
sudo systemctl stop thermostat-web
sudo systemctl daemon-reload
sudo systemctl start thermostat-daemon
sudo systemctl start thermostat-web
sudo service nginx restart
echo 'Update Complete!'