forked from Electrotest/BehovsBoBoxen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh~
executable file
·198 lines (148 loc) · 5.53 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
#! /bin/sh
#
#
#
# install.sh
#
# Description: Installs BehovsBoBoxen
#
# Usage: install.sh {web|all} {x}
#
# web - update the web server part
# all - installs the complete system including update/upgrade of system, install of additional packages etc.
# x - If a second argument is specified, Domoticz support is installed, i.e. bbb_domoticz.py will be the
# control process.
#
if [ -z "$2" ]
then
DOMOTICZ=1
echo "No Domoticz support"
else
DOMOTICZ=0
echo "Domoticz support"
fi
# Set true (0) if support for Domoticz control is desired
# Will use bbb_add/bbb_domoticz.py as control system and install startup script
# rc.local will not modified
#
#
#
# Function updates the webb application
#
do_web()
{
echo "Update BehovsBoBoxen webb application"
sudo chmod 755 /var/www -R
# full file permissions
sudo cp -R /home/pi/BehovsBoBoxen/html /var/www
# copies the files for the web-interface
sudo chmod 755 /var/www/html -R
# restore file permissions
sudo chmod 777 /var/www/html/application/textfile -R
sudo chmod 777 /var/www/html/application/data -R
sudo chmod 777 /var/www/html/application/data/.ht.sqlite3
sudo chmod 777 /var/www/html/src/CCSpotprices/CCSpotprices.php
# full file permissions
sudo rm -f /var/www/html/index.html
# remove above file
echo "Webb application updated"
RETVAL="$?"
return "$RETVAL"
}
#
# Function that installs the whole BehovsBoBoxen
#
do_all()
{
echo "Install BehovsBoBoxen"
sudo apt-get update -y
# gets Raspian updates
sudo apt-get upgrade -y
# installs Raspian updates
sudo apt-get install vsftpd -y
# installs ftp programme
sudo apt-get install apache2 php5 libapache2-mod-php5 -y
# installs webserver and php library
sudo apt-get install sqlite3
# installs sqlite3
sudo apt-get install php5-sqlite
# installs php-sqlite
sudo a2enmod rewrite
# activates mod_rewrite
sudo service apache2 restart
# restarts apache2
sudo rm -f /var/www/html -R
sudo chmod 777 /home/pi/BehovsBoBoxen -R
# full file permissions for the the BehovsBoBoxen-repository from github
if [ $DOMOTICZ ]
then
echo "Install Domoticz support"
sudo cp /home/pi/BehovsBoBoxen/scripts/bbb_domoticz.sh /etc/init.d
sudo chmod 755 /etc/init.d/bbb_domoticz.sh
sudo update-rc.d bbb_domoticz.sh defaults
else
sudo cp /home/pi/BehovsBoBoxen/scripts/rc.local /etc/rc.local
sudo chmod 755 /etc/rc.local
# copies and change path for the file that starts the box at reboot
fi
do_web
# sudo crontab -l -u root | cat /home/pi/BehovsBoBoxen/scripts/cron.txt | sudo crontab -u root -
# we get the new spotpricefile after 16:00 and recalculate the temperatures afte
cat /boot/config.txt |grep "dtoverlay=w1-gpio,gpiopin=4" || echo "dtoverlay=w1-gpio,gpiopin=4" | sudo tee -a /boot/config.txt
# append "dtoverlay=..." to /boot/config.txt unless it's already there
#
echo "Enable SSL mode"
sudo a2enmod ssl
sudo service apache2 restart
# enable mod_ssl
sudo chmod 777 /etc/apache2 -R
sudo rm -f /etc/apache2/apache2.conf
sudo cp /home/pi/BehovsBoBoxen/scripts/apache2.conf /etc/apache2/apache2.conf
# AllowOverride All
# sudo mkdir /etc/apache2/ssl
sudo cp -rp /home/pi/BehovsBoBoxen/ssl /etc/apache2
sudo chmod 777 /etc/apache2/ssl -R
# adds ssl repository, to hold key and cerificate
echo "Generate selfsigned certificate"
sudo openssl req -x509 -nodes -days 1095 -newkey rsa:2048 -out /etc/apache2/ssl/behovsboboxen.crt -keyout /etc/apache2/ssl/behovsboboxen.key -subj "/C=SE/ST=Sverige/L=Molndal/O=/OU=/CN=behovsboboxen"
# req request
#-nodes if a private key is created it will not be encrypted
#-newkey creates a new certificate request and a new private key
#rsa:2048 generates an RSA key 2048 bits in size
#-keyout the filename to write the newly created private key to
#-out specifies the output filename
#-subj sets certificate subject
#x509 certificate display and signing utility
#-subj arg Replaces subject field of input request with specified data and
echo "Certificate done"
sudo rm -f /etc/apache2/sites-available/default-ssl.conf
sudo cp -rp /home/pi/BehovsBoBoxen/scripts/default-ssl /etc/apache2/sites-available/default-ssl
sudo cp -rp /home/pi/BehovsBoBoxen/scripts/000-default-ssl /etc/apache2/sites-enabled/000-default-ssl
# symlink text, -p keeps file permissions from host to receiver
sudo cp -rp /home/pi/BehovsBoBoxen/scripts/default-ssl.conf /etc/apache2/sites-available/default-ssl.conf
sudo cp -rp /home/pi/BehovsBoBoxen/scripts/default-ssl.conf /etc/apache2/sites-enabled/default-ssl.conf
# 443
sudo chmod 755 /etc/apache2
sudo chmod 755 /etc/apache2/ssl
sudo chmod 755 /home/pi/BehovsBoBoxen
# restores file permissions
sudo /etc/init.d/apache2 restart
# restarts apache2
echo "installation ok, the system will restart"
sudo reboot
RETVAL="$?"
return "$RETVAL"
}
case "$1" in
web)
do_web
;;
all)
do_all
;;
*)
echo "Usage: $SCRIPTNAME {web|all}"
exit 3
;;
esac
: