-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.sh
executable file
·349 lines (295 loc) · 11.8 KB
/
setup.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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
#!/bin/bash
this_dir=$(cd `dirname $0`; pwd)
binDir=$this_dir/bin
configDir=$this_dir/etc
[ ! -f $configDir/piLogger.conf ] && errorExit "No config file $configDir/piLogger.conf, please run $this_dir/configure"
. $configDir/piLogger.conf
. $baseDir/bin/functions-upgrade
needReboot=""
#=============================
# functions
#=============================
errorExit(){
echo "ERROR: $@"
exit 1
}
cat<<EOT
#================================
# Check that required variables are set
#================================
EOT
[ -z "$interface" ] && errorExit "_interface_ variable in $configDir/piLogger.conf not set, please run $this_dir/configure"
cat<<EOT
#================================
# Minimize install
#================================
EOT
[ -n "$minimizeInstall" ] && {
sudo rm -rf python_games
sudo apt-get -y autoremove x11-common
sudo apt-get -y autoremove midori
sudo apt-get -y autoremove python*
sudo apt-get -y autoremove lxde-icon-theme
sudo apt-get -y autoremove omxplayer
sudo apt-get -y autoremove wolfram-engine
sudo apt-get -y autoremove scratch
sudo apt-get -y autoremove dillo
sudo apt-get -y autoremove galculator
sudo apt-get -y autoremove netsurf-common
sudo apt-get -y autoremove netsurf-gtk
sudo apt-get -y autoremove lxde-common
sudo apt-get -y autoremove lxdeterminal
sudo apt-get -y autoremove hicolor-icon-theme
sudo apt-get -y autoremove libreoffice
sudo apt-get -y autoremove libreoffice-core
sudo apt-get -y autoremove
sudo apt-get -y clean
sudo rm -rf /usr/share/icons/*
sudo rm -rf /opt/vc/src/*
sudo rm -rf /usr/share/icons/*
sudo rm -rf /usr/share/wallpapers
sudo rm -rf /usr/share/themes
sudo rm -rf /usr/share/kde4
# remove some folders from a clean debian jessie installation
sudo rm -rf /home/pi/Music
sudo rm -rf /home/pi/Pictures
sudo rm -rf /home/pi/Desktop
sudo rm -rf /home/pi/Documents
sudo rm -rf /home/pi/Downloads
sudo rm -rf /home/pi/Public
sudo rm -rf /home/pi/Templates
sudo rm -rf /home/pi/Videos
echo "sudo find / -name *.wav -exec rm {} \\; " ; # 29.80MB
echo "sudo find / -name *.mp3 -exec rm {} \\; " ; # 1.94MB
}
cat<<EOT
#================================
# enable i2c kernel modules
#================================
EOT
#--- enable i2c_arm and i2c1 options
echo " - enabling i2c config in /boot/config.txt"
sudo sed -ie 's/^#dtparam=i2c_arm=on/dtparam=i2c_arm=on/' /boot/config.txt
sudo sed -ie 's/^#dtparam=i2c1=on/dtparam=i2c1=on/' /boot/config.txt
echo " - adding i2c-dev to /etc/modules"
[ -z "$(grep i2c-dev /etc/modules)" ] && { sudo sh -c "echo i2c-dev >> /etc/modules" ; needReboot=true ; }
cat<<EOT
#================================
# correctly configure locales
#================================
EOT
#--- setting up the locale
[ -n "$piLoggerLocale" ] && {
echo " - setting up locale (if not already set up)"
[[ -z "$(grep -v '^#' /etc/locale.gen | grep 'en_US.UTF-8')" ]] && {
sudo sed -ie 's/^# en_US.UTF-8/en_US.UTF-8/' /etc/locale.gen
sudo locale-gen
sudo update-locale LANG=en_US.UTF-8
sudo update-locale LANGUAGE=en_US.UTF-8
sudo update-locale LC_ALL=en_US.UTF-8
}
}
cat<<EOT
#================================
# setup directories
#================================
EOT
[ ! -d "$logDir" ] && { echo "Creating logDir: $logDir" ; sudo mkdir -p "$logDir" ; }
[ ! -d "$dataDir" ] && { echo "Creating dataDir: $dataDir" ; sudo mkdir -p "$dataDir" ; }
[ ! -d "$dbDir" ] && { echo "Creating dbDir: $dbDir" ; sudo mkdir -p "$dbDir" ; }
[ ! -d "$graphDir" ] && { echo "Creating graphDir: $graphDir" ; sudo mkdir -p "$graphDir" ; }
[ ! -d "$cacheDir" ] && { echo "Creating cacheDir: $cacheDir" ; sudo mkdir -p "$cacheDir" ; }
[ ! -d "$oneWireDir" ] && { echo "Creating oneWireDir: $oneWireDir" ; sudo mkdir -p "$oneWireDir" ; }
[ ! -d "$backupDir" ] && { echo "Creating backupDir: $backupDir" ; sudo mkdir -p "$backupDir" ; }
[ ! -d "$dataDir/remote-logging-enabled" ] && { echo "Creating remote-logging-enabled: $dataDir/remote-logging-enabled" ; sudo mkdir -p "$dataDir"/remote-logging-enabled ; }
[ ! -d "$spoolDir" ] && { echo "Creating spoolDir: $spoolDir" ; sudo mkdir -p "$spoolDir" ; }
myUser=$(id -u)
myGroup=$(id -g)
sudo chown ${myUser}:${myGroup} "$dataDir"
sudo chown ${myUser}:${myGroup} "$logDir"
sudo chown ${myUser}:${myGroup} "$graphDir"
sudo chown ${myUser}:${myGroup} "$cacheDir"
sudo chown ${myUser}:${myGroup} "$backupDir"
sudo chown ${myUser}:${myGroup} "$dataDir/remote-logging-enabled"
sudo chown ${myUser}:${myGroup} "$spoolDir"
sudo chmod 777 $spoolDir
sudo chown ${myUser}:www-data "$dbDir"
sudo chmod 775 $dbDir
[ ! -h $this_dir/html/cache ] && { ln -s $cacheDir $this_dir/html/cache ; }
[ ! -d $this_dir/html/graphs ] && { ln -s $dataDir/graphs $this_dir/html/graphs ; }
[ ! -d $this_dir/html/xml ] && { mkdir $dataDir/xml ; ln -s $dataDir/xml $this_dir/html/xml ; }
cat<<EOT
#================================
# Make sure the latest updates are available
#================================
EOT
curTS=$(date "+%s")
aptTS=$(stat -c %Y /var/cache/apt/)
(( ageApt = $curTS - $aptTS ))
#--- one day = 86400
#--- one week = 604800
[ $ageApt -gt 604800 ] && sudo apt-get update
cat<<EOT
#================================
# Check for dependencies
#================================
EOT
echo " - Interface: $interface"
cat<<EOT
#================================
# bc
#================================
EOT
sudo dpkg -s bc >/dev/null 2>&1 || { echo " - Installing bc" ; sudo apt-get -q -y install bc ; }
sudo dpkg -s dnsutils >/dev/null 2>&1 || { echo " - Installing dnsutils" ; sudo apt-get -q -y install dnsutils ; }
cat<<EOT
#================================
# OWFS
#================================
EOT
sudo dpkg -s owfs >/dev/null 2>&1 || { echo " - Installing owfs" ; sudo apt-get -q -y install owfs ; }
[ ! -h /etc/init.d/start1wire ] && { sudo ln -s $this_dir/etc/init.d/start1wire /etc/init.d/ ; needReboot=true ; }
[ ! -h /etc/rc2.d/S02start1wire ] && { sudo update-rc.d start1wire defaults ; needReboot=true ; }
#--- remove dummy devices from the config file /etc/owfs.conf
sudo sed -i 's/^server: FAKE/#server: FAKE/' /etc/owfs.conf
#--- disable owftpd, owhttpd and owserver
sudo update-rc.d owftpd disable > /dev/null
sudo update-rc.d owhttpd disable > /dev/null
sudo update-rc.d owserver disable > /dev/null
cat<<EOT
#================================
# RRDTool
#================================
EOT
sudo dpkg -s rrdtool >/dev/null 2>&1 || { echo " - Installing rrdtool" ; sudo apt-get -q -y install rrdtool ; }
cat<<EOT
#================================
# sqlite3
#================================
EOT
sudo dpkg -s sqlite3 >/dev/null 2>&1 || { echo " - Installing sqlite3" ; sudo apt-get -q -y install sqlite3 ; }
#--- setup the sqlite3 config database
[ ! -f $appDbFile ] && {
echo " - Setting upp $appDbFile database"
$binDir/dbTool --setup --db
currentVersion=$(cat $baseDir/currentVersion | grep -vE "#|^$")
echo " - Setting the installed version to $currentVersion"
piLogger_setInstalledVersion $currentVersion
}
cat<<EOT
#================================
# php
#================================
EOT
echo "* Checking installed packages"
curInstallPackages=""
curRelease=$(grep VERSION_CODENAME= /etc/os-release | cut -d= -f2)
echo " - OS Release: $curRelease"
case $curRelease in
jessie|wheezy)
#--- older raspbian
#--- note, php5-cgi has to come before php5. Otherwise apt-get will install apache2 to satisfy dependencies
#--- https://wildlyinaccurate.com/installing-php-on-debian-without-apache/
for package in php5-cgi php5 php5-sqlite php5-cli php5-rrd php5-curl lighttpd sqlite3 bc screen python-dev python-pip
do
echo -n " - Checking $package"
sudo dpkg -s $package >/dev/null 2>&1 || { echo " - Adding package $package to the install list" ; curInstallPackages="$curInstallPackages $package" ; }
done
;;
buster|stretch|*)
for package in php-cgi php php-sqlite3 php-cli php-rrd php-mbstring php-curl lighttpd sqlite3 bc screen python-dev python-pip
do
echo -n " - Checking $package"
sudo dpkg -s $package >/dev/null 2>&1 || { echo " - Adding package $package to the install list" ; curInstallPackages="$curInstallPackages $package" ; }
done
;;
esac
echo
[ -n "$curInstallPackages" ] && { echo " - Installing packages: $curInstallPackages" ; sudo apt-get -q -y install $curInstallPackages ; }
cat<<EOT
#================================
# Lighttpd
#================================
EOT
sudo dpkg -s lighttpd >/dev/null 2>&1 || { echo " - Installing lighttpd" ; sudo apt-get -q -y install lighttpd ; }
sudo chmod 755 /var/log/lighttpd
[ -f /etc/lighttpd/lighttpd.conf ] && { sudo mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.org ; sudo ln -s $configDir/lighttpd/lighttpd.conf /etc/lighttpd ; }
[ ! -h /etc/lighttpd/conf-enabled/10-accesslog.conf ] && sudo ln -s $configDir/lighttpd/conf-enabled/10-accesslog.conf /etc/lighttpd/conf-enabled
[ ! -h /etc/lighttpd/conf-enabled/10-dir-listing.conf ] && sudo ln -s $configDir/lighttpd/conf-enabled/10-dir-listing.conf /etc/lighttpd/conf-enabled
case $curRelease in
jessie|wheezy)
[ ! -h /etc/lighttpd/conf-enabled/10-cgi.conf ] && { echo "* CGI for $curRelease" ; sudo ln -sf $configDir/lighttpd/conf-enabled/10-cgi.jessie.conf /etc/lighttpd/conf-enabled/10-cgi.conf ; }
;;
buster)
[ ! -h /etc/lighttpd/conf-enabled/10-cgi.conf ] && { echo "* CGI for $curRelease" ; sudo ln -sf $configDir/lighttpd/conf-enabled/10-cgi.buster.conf /etc/lighttpd/conf-enabled/10-cgi.conf ; }
;;
stretch|*)
[ ! -h /etc/lighttpd/conf-enabled/10-cgi.conf ] && { echo "* CGI for $curRelease" ; sudo ln -sf $configDir/lighttpd/conf-enabled/10-cgi.stretch.conf /etc/lighttpd/conf-enabled/10-cgi.conf ; }
;;
esac
#--- make sure Apache2 is disabled
sudo service apache2 stop
sudo update-rc.d apache2 disable > /dev/null
sudo service lighttpd restart
cat<<EOT
#================================
# Set up bash completion by linking shellFunctions to /etc/bash_completion.d/piLogger
#================================
EOT
echo " - Setting up bash completion"
[ ! -h /etc/bash_completion.d/piLogger ] && { sudo ln -s $this_dir/bin/shellFunctions /etc/bash_completion.d/piLogger ; needReboot=true ; }
cat<<EOT
#================================
# /etc/piLogger.conf link to installation directory
#================================
EOT
[[ ! -d /etc/piLogger.d && ! -h /etc/piLogger.d ]] && sudo ln -s $configDir /etc/piLogger.d
cat<<EOT
#================================
# Setup logrotate
#================================
EOT
[[ ! -r /etc/logrotate.d/piLogger ]] && sudo cp $configDir/logrotate.d/piLogger /etc/logrotate.d/piLogger
cat<<EOT
#================================
# Setup sudoers
#================================
EOT
sudo cp $configDir/sudoers.d/piLogger /etc/sudoers.d/piLogger ; sudo chown root:root /etc/sudoers.d/piLogger ; sudo chmod 0440 /etc/sudoers.d/piLogger
cat<<EOT
#================================
# Show info about timezones
#================================
EOT
echo "* If your timezone is not set, you can do so by running:"
echo "sudo cp /usr/share/zoneinfo/Europe/Zurich /etc/localtime"
cat<<EOT
#================================
# Setup admin password (setting the default password to "admin")
#================================
EOT
$this_dir/bin/resetPassword admin
cat<<EOT
#================================
# Run the upgrade script
#================================
EOT
$this_dir/bin/upgrade.sh --doIt
cat<<EOT
#================================
# Run composer
#================================
EOT
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
cd $this_dir
composer install
cd -
cat<<EOT
#================================
# End
#================================
EOT
[ -n "$needReboot" ] && {
echo "* Done, please reboot!"
echo " sudo shutdown -r now"
}