-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathinstall.sh
286 lines (243 loc) · 11.1 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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#!/bin/bash
##############################################################################
# Bash script to install HousePanel
# written by @kewashi for HousePanel installation
# inspiration from @AamnahAkram of http://aamnah.com
# removed option to specify a branch - now only works on master branch
#
# first, make sure your rPI is configured using:
# sudo raspi-config
#
# then, the easiest way to run this is to do this:
#
# cd ~
# sudo wget https://raw.githubusercontent.com/kewashi/HousePanel/master/install.sh
# sudo chmod 755 ./install.sh
# bash ./install.sh
#
##############################################################################
#COLORS
# Reset
Color_Off='\033[0m' # Text Reset
# Regular Colors
Red='\033[0;31m' # Red
Green='\033[0;32m' # Green
Yellow='\033[0;33m' # Yellow
Purple='\033[0;35m' # Purple
Cyan='\033[0;36m' # Cyan
clear
# get the IP number
ip=$(hostname -I | cut -f1 --delimiter=' ')
# operate this script from the home folder only
cd ~
echo -e "$Cyan \nThe default location for Apache web files is /var/www/html $Color_Off"
echo -e "$Cyan Enter below the directory name beneath this location where you want to install HousePanel $Color_Off"
echo -e "$Cyan If you want HP installed in /var/www/html/housepanel, enter $C olor_Off housepanel $Cyan below. $Color_Off"
echo -e "$Cyan or... if you prefer a different name, like $Color_Off mypanel $Cyan , enter $Color_Off mypanel $Cyan below. $Color_Off"
hpdir="housepanel"
read -p " Directory name for HousePanel (default= $hpdir): " nhpdir
[ -n "$nhpdir" ] && hpdir=$nhpdir
isupdate="n"
nisupdate="n"
echo -e "$Cyan Is this an update to a prior installation? "
read -p " Enter y for yes or n for no (default= $isupdate): " nisupdate
[ -n "$nisupdate" ] && isupdate=$nisupdate
apache="n"
napache="n"
if [ "$isupdate" = "n" ];
then
echo -e "$Cyan Do rPI update, Apache and PHP setup, or skip if you are sure that your setup is correct. $Color_Off"
read -p " Perform rPI, Apache and PHP install? Enter y for yes or n for no (default= $apache): " napache
[ -n "$napache" ] && apache=$napache
fi
if [ "$apache" = "y" ];
then
phpver="5"
nphpver="5"
read -p " Enter 5 for php5 ... anything else will install php7 (default= $phpver): " nphpver
[ -n "$nphpver" ] && phpver=$nphpver
fi
gpio="n"
ngpio="n"
if [ "$isupdate" = "n" ];
then
echo -e "$Cyan Install GPIO extensions if you want to use your rPI to control devices wired physically into it. $Color_Off"
read -p " Install rPI extensions for GPIO - enter y for yes, or n for no. (default= $gpio): " ngpio
[ -n "$ngpio" ] && gpio=$ngpio
fi
hppush="n"
nhppush="n"
echo -e "$Cyan Install or Update the housepanel-push Node.js middleman to enable direct updates? $Color_Off"
read -p " Enter y for yes or n for no. (default= $hppush): " nhppush
[ -n "$nhppush" ] && hppush=$nhppush
userskin="n"
nuserskin="n"
echo -e "$Cyan Do you have a custom skin directory? $Color_Off"
read -p " If so, enter name here or accept default of no: " nuserskin
[ -n "$nhppush" ] && userskin=$nuserskin
# this block updates the rPI and installs Apache and PHP
# it can be skipped if you know your rPI is up to date
if [ "$isupdate" = "n" ];
then
zipfile="master.zip"
infostr="HousePanel has been downloaded and installed"
if [ "$apache" = "y" ];
then
# Update packages and Upgrade system
echo -e "$Cyan \nUpdating System. This may take awhile so please be patient... $Color_Off"
sudo apt-get update -y
# sudo apt-get upgrade -y
echo -e "$Green \nSystem was updated $Color_Off"
## Install Apache and PHP
if [ "$phpver" = "5" ];
then
echo -e "$Cyan \nInstalling Apache and PHP 5 ... $Color_Off"
sudo apt-get install apache2 libapache2-mod-php5 php5 curl php5-curl php5-gd --fix-missing -y
else
echo -e "$Cyan \nInstalling Apache and PHP ... $Color_Off"
sudo apt-get install apache2 libapache2-mod-php php php-mbstring curl php-curl php-gd --fix-missing -y
fi
fi
if [ "$gpio" = "y" ];
then
echo -e "$Cyan \nInstalling optional rpi settings for use as a thing ... $Color_Off"
sudo apt-get install wiringpi raspi-gpio rpi-update -y
echo -e "$Green \nApache, PHP, and Optional settings installed $Color_Off"
fi
# Getting raw files from HousePanel
echo -e "$Cyan \nDownloading and unzipping HousePanel to /var/www/html/$hpdir ... $Color_Off"
if [ -e $zipfile ];
then
sudo rm -f $zipfile
fi
# remove any old version of zipped download dir
if [ -d HousePanel-master ];
then
sudo rmdir -f HousePanel-master
fi
# download the files as a zip file
sudo wget -r -nd https://github.com/kewashi/HousePanel/archive/$zipfile
sudo unzip $zipfile
# copy over any existing custom files if they exist
if [ -f /var/www/html/$hpdir/hmoptions.cfg ];
then
sudo cp /var/www/html/$hpdir/hm*.cfg HousePanel-master
fi
if [ -f /var/www/html/$hpdir/customtiles.css ];
then
sudo cp /var/www/html/$hpdir/customtiles.css HousePanel-master
fi
if [ -f /var/www/html/$hpdir/skin-housepanel/customtiles.css ];
then
sudo cp /var/www/html/$hpdir/skin-housepanel/customtiles.css HousePanel-master/skin-housepanel
fi
if [ -f /var/www/html/$hpdir/skin-modern/customtiles.css ];
then
sudo cp /var/www/html/$hpdir/skin-modern/customtiles.css HousePanel-master/skin-modern
fi
if [ -f /var/www/html/$hpdir/skin-plain/customtiles.css ];
then
sudo cp /var/www/html/$hpdir/skin-plain/customtiles.css HousePanel-master/skin-plain
fi
if [ "$userskin" != "n" ];
then
sudo cp -R /var/www/html/$hpdir/$userskin HousePanel-master
fi
# remove if the target directory exists
if [ -d /var/www/html/$hpdir ];
then
sudo rmdir -f /var/www/html/$hpdir
fi
# rename the downloaded unzipped folder structure to our target directory name
sudo mv HousePanel-master /var/www/html/$hpdir
sudo rm -f $zipfile
fi
if [ "$isupdate" = "y" ];
then
infostr="HousePanel has been updated"
cd /var/www/html/$hpdir
# update individual files
echo -e "$Cyan \nCopying updated main files... $Color_Off"
wget -q -nd -N "https://raw.githubusercontent.com/kewashi/HousePanel/master/housepanel.php"
wget -q -nd -N "https://raw.githubusercontent.com/kewashi/HousePanel/master/housepanel.js"
wget -q -nd -N "https://raw.githubusercontent.com/kewashi/HousePanel/master/hpapi.py"
wget -q -nd -N "https://raw.githubusercontent.com/kewashi/HousePanel/master/customize.js"
wget -q -nd -N "https://raw.githubusercontent.com/kewashi/HousePanel/master/tileeditor.js"
wget -q -nd -N "https://raw.githubusercontent.com/kewashi/HousePanel/master/tileeditor.css"
wget -q -nd -N "https://raw.githubusercontent.com/kewashi/HousePanel/master/frame1.html"
wget -q -nd -N "https://raw.githubusercontent.com/kewashi/HousePanel/master/frame2.html"
wget -q -nd -N "https://raw.githubusercontent.com/kewashi/HousePanel/master/frame3.html"
wget -q -nd -N "https://raw.githubusercontent.com/kewashi/HousePanel/master/frame4.html"
wget -q -nd -N "https://raw.githubusercontent.com/kewashi/HousePanel/master/housepanel.css"
wget -q -nd -N "https://raw.githubusercontent.com/kewashi/HousePanel/master/iconlist.txt"
wget -q -nd -N "https://raw.githubusercontent.com/kewashi/HousePanel/master/getdir.php"
wget -q -nd -N "https://raw.githubusercontent.com/kewashi/HousePanel/master/index.html"
if [ ! -f "jquery-1.12.4.min.js" ];
then
echo -e "$Cyan \nCopying jQuery files... $Color_Off"
wget -q -nd -N "https://raw.githubusercontent.com/kewashi/HousePanel/master/jquery-1.12.4.min.js"
wget -q -nd -N "https://raw.githubusercontent.com/kewashi/HousePanel/master/jquery-ui.min.js"
wget -q -nd -N "https://raw.githubusercontent.com/kewashi/HousePanel/master/jquery-ui.css"
fi
cd docs
wget -q -nd -N "https://raw.githubusercontent.com/kewashi/HousePanel/master/docs/index.html"
echo -e "$Cyan \nUpdating css files for default skins... $Color_Off"
cd ../skin-housepanel
wget -q -nd -N "https://raw.githubusercontent.com/kewashi/HousePanel/master/skin-housepanel/housepanel.css"
cd ../skin-modern
wget -q -nd -N "https://raw.githubusercontent.com/kewashi/HousePanel/master/skin-modern/housepanel.css"
cd ../skin-plain
wget -q -nd -N "https://raw.githubusercontent.com/kewashi/HousePanel/master/skin-plain/housepanel.css"
if [ "$hppush" = "y" ];
then
echo -e "$Cyan \nUpdating housepanel-push files... $Color_Off"
cd ../housepanel-push
wget -q -nd -N "https://raw.githubusercontent.com/kewashi/HousePanel/master/housepanel-push/housepanel-push.js"
wget -q -nd -N "https://raw.githubusercontent.com/kewashi/HousePanel/master/housepanel-push/package.json"
fi
cd /var/www/html/$hpdir
fi
echo -e "$Cyan \nSetting permissions for /var/www/html/$hpdir $Color_Off"
sudo chown -R www-data:www-data /var/www/html/$hpdir
sudo chmod -R 777 /var/www/html/$hpdir
sudo chown -R pi:pi /var/www/html/$hpdir/housepanel-push
sudo chmod -R 775 /var/www/html/$hpdir/housepanel-push
# Create a default index file to show php info
# echo "<?php phpinfo ();?>" > /var/www/html/$hpdir/index.php
# Restart Apache
echo -e "$Cyan \nRestarting Apache $Color_Off"
sudo systemctl daemon-reload
sudo service apache2 restart
# create the contents of housepanel-push.service dynamically
if [ "$hppush" = "y" ];
then
cd /var/www/html/$hpdir/housepanel-push
echo -e "$Cyan \nInstalling housepanel-push package $Color_Off"
npm install
# create the file to install as a service
echo -e "$Cyan \nCreating a file to run housepanel-push as a service $Color_Off"
sudo echo "[Unit]" > housepanel-push.service
sudo echo "Description=Node.js HousePanel Push Server" >> housepanel-push.service
sudo echo "After=network-online.target" >> housepanel-push.service
sudo echo " " >> housepanel-push.service
sudo echo "[Service]" >> housepanel-push.service
sudo echo "Restart=on-failure" >> housepanel-push.service
sudo echo "RestartSec=10" >> housepanel-push.service
sudo echo "WorkingDirectory=/var/www/html/$hpdir/housepanel-push" >> housepanel-push.service
sudo echo "ExecStart=/usr/bin/node housepanel-push.js" >> housepanel-push.service
sudo echo "Type=simple" >> housepanel-push.service
sudo echo "User=pi" >> housepanel-push.service
sudo echo " " >> housepanel-push.service
sudo echo "[Install]" >> housepanel-push.service
sudo echo "WantedBy=multi-user.target" >> housepanel-push.service
sudo chmod 755 housepanel-push.service
echo -e "$Cyan \nInstalling housepanel-push as a service $Color_Off"
sudo cp housepanel-push.service /etc/systemd/system
cd /etc/systemd/system
sudo systemctl enable housepanel-push
sudo systemctl daemon-reload
sudo systemctl restart housepanel-push
fi
cd ~
echo -e "$Green \n$infostr in /var/www/html/$hpdir $Color_Off"
echo -e "$Green \nTo use open a browser and load http://$ip/$hpdir/housepanel.php $Color_Off"