forked from mholgatem/ThermOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
62 lines (50 loc) · 1.7 KB
/
install.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
#!/bin/bash
#get script path
SCRIPT=$(readlink -f $0)
SCRIPTPATH=`dirname $SCRIPT`
cd $SCRIPTPATH
#if not root user, restart script as root
if [ "$(whoami)" != "root" ]; then
echo "Switching to root user..."
sudo bash $SCRIPT $*
exit 1
fi
#set constants
IP="$(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1')"
NONE='\033[00m'
CYAN='\033[36m'
FUSCHIA='\033[35m'
UNDERLINE='\033[4m'
echo "Running Update..."
#install dependencies
sudo apt-get update
echo
echo "Installing Dependencies..."
echo
sudo apt-get -y install python-pip python-dev sqlite3 nginx
sudo pip install flask gunicorn pygal python-forecastio
#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
#Add uvIndex to logs.db -> hourlyWeather table
sqlite3 $SCRIPTPATH/logs/logs.db "ALTER TABLE hourlyWeather ADD COLUMN uvIndex NUMERIC"
#copy service unit files for systemctl
daemon=$SCRIPTPATH"/thermostat-daemon.service"
web=$SCRIPTPATH"/thermostat-web.service"
sudo cp $daemon /lib/systemd/system/
sudo cp $web /lib/systemd/system/
sudo systemctl enable thermostat-daemon
sudo systemctl enable thermostat-web
sudo systemctl daemon-reload
sudo systemctl start thermostat-daemon
sudo systemctl start thermostat-web
sudo service nginx restart
echo
echo
echo "-----------------"
echo -e "${CYAN}Installation Complete!${NONE}"
echo -e "${CYAN}Type your Pi's IP address into a web browser to access your control panel${NONE}"
echo -e "${FUSCHIA}${UNDERLINE}"$IP"${NONE}"
echo "-----------------"