forked from andi34/photobooth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-raspbian.sh
executable file
·398 lines (338 loc) · 11.8 KB
/
install-raspbian.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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
#!/bin/bash
# Stop on the first sign of trouble
set -e
# Show all commands
# set -x
RUNNING_ON_PI=true
if [ ! -z $1 ]; then
webserver=$1
else
webserver=apache
fi
function info {
echo -e "\033[0;36m${1}\033[0m"
}
function error {
echo -e "\033[0;31m${1}\033[0m"
}
function no_raspberry {
info "WARNING: This reset script is intended to run on a Raspberry Pi."
info "Running the script on other devices running Debian / a Debian based distribution is possible, but PI specific features will be missing!"
read -p "Do you want to continue? (y/n)" -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
RUNNING_ON_PI=false
return
fi
exit ${1}
}
if [ $UID != 0 ]; then
error "ERROR: Only root is allowed to execute the installer. Forgot sudo?"
exit 1
fi
if [ ! -f /proc/device-tree/model ]; then
no_raspberry 2
else
PI_MODEL=$(tr -d '\0' </proc/device-tree/model)
if [[ $PI_MODEL != Raspberry* ]]; then
no_raspberry 3
fi
fi
if [[ ! -z $1 && ("$1" = "nginx" || "$1" = "lighttpd") ]]; then
info "### Used webserver: $webserver"
else
info "### Used webserver: Apache Webserver"
fi
COMMON_PACKAGES=(
'curl'
'git'
'gphoto2'
'jq'
'libimage-exiftool-perl'
'nodejs'
'npm'
'php-gd'
'php-zip'
'yarn'
'rsync'
'udisks2'
)
apache_webserver() {
info "### Installing Apache Webserver..."
apt install -y libapache2-mod-php
}
nginx_webserver() {
info "### Installing NGINX Webserver..."
apt install -y nginx php-fpm
nginx_conf="/etc/nginx/sites-enabled/default"
if [ -f "${nginx_conf}" ]; then
info "### Enable PHP in NGINX"
cp "${nginx_conf}" ~/nginx-default.bak
sed -i 's/^\(\s*\)index index\.html\(.*\)/\1index index\.php index\.html\2/g' "${nginx_conf}"
sed -i '/location ~ \\.php$ {/s/^\(\s*\)#/\1/g' "${nginx_conf}"
sed -i '/include snippets\/fastcgi-php.conf/s/^\(\s*\)#/\1/g' "${nginx_conf}"
sed -i '/fastcgi_pass unix:\/run\/php\//s/^\(\s*\)#/\1/g' "${nginx_conf}"
sed -i '/.*fastcgi_pass unix:\/run\/php\//,// { /}/s/^\(\s*\)#/\1/g; }' "${nginx_conf}"
info "### Testing NGINX config"
/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
info "### Restarting NGINX"
systemctl reload nginx
else
error "Can not find ${nginx_conf} !"
info "Using Apache Webserver !"
apt remove -y nginx php-fpm
apache_webserver
fi
}
lighttpd_webserver() {
info "### Installing Lighttpd Webserver..."
apt install -y lighttpd php-fpm
lighttpd-enable-mod fastcgi
lighttpd-enable-mod fastcgi-php
php_conf="/etc/lighttpd/conf-available/15-fastcgi-php.conf"
if [ -f "${php_conf}" ]; then
info "### Enable PHP for Lighttpd"
cp ${php_conf} ${php_conf}.bak
cat > ${php_conf} <<EOF
# -*- depends: fastcgi -*-
# /usr/share/doc/lighttpd/fastcgi.txt.gz
# http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ConfigurationOptions#mod_fastcgi-fastcgi
## Start an FastCGI server for php (needs the php5-cgi package)
fastcgi.server += ( ".php" =>
((
"socket" => "/var/run/php/php7.3-fpm.sock",
"broken-scriptfilename" => "enable"
))
)
EOF
service lighttpd force-reload
else
error "Can not find ${php_conf} !"
info "Using Apache Webserver !"
apt remove -y lighttpd php-fpm
apache_webserver
fi
}
echo "
@@@@@@@@@@@@@@@@@@@
@@. .@@
%@@@@@@. @@ @@@@@@@@@ @@
@@@ @@* @@. .@@
&@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&
@@@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@@@
@@ @@
@@ @@@@@@@@@@@@@. *@@ @@@@@ @@
@@ @@@@ @@@@ @@
@@@@@@@@@@@@@@@@@@@@@ #@@@@@@@# @@@@@@@@@@@@@@@@@@@@@
@@ @@@ @@@@( (@@@@ @@@ @@
@@ &@@ .@@% %@@. @@& @@
@@ @@ @@ @@ @@ @@
@@ %@@ @@* /@@ @@% @@
@@ @@% @@ @@ %@@ @@
@@ *@@ @@& &@@ @@* @@
@@ @@ @@* *@@ @@ @@
@@ @@ @@@ @@@ @@ @@
@@%%%%%%%%%%%%%%%@@% @@@@@&%&@@@@@ %@@%%%%%%%%%%%%%%%@@
@@@@@@@@@@@@@@@@@@@@@@ *&@&* @@@@@@@@@@@@@@@@@@@@@@
@@ ,@@@@& &@@@@, @@
@@ (@@@@@@@@@( @@
@@ @@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
"
info "### The Photobooth installer for your Raspberry Pi."
info "### First we update your system. That's not worth mentioning."
apt update
apt dist-upgrade -y
info "### Photobooth needs some software to run."
if [ "$webserver" == "nginx" ]; then
nginx_webserver
elif [ "$webserver" == "lighttpd" ]; then
lighttpd_webserver
else
apache_webserver
fi
info "### Installing common software..."
for package in "${COMMON_PACKAGES[@]}"; do
if [ $(dpkg-query -W -f='${Status}' ${package} 2>/dev/null | grep -c "ok installed") -eq 1 ]; then
info "[Package] ${package} installed already"
else
info "[Package] Installing missing common package: ${package}"
if [[ ${package} == "yarn" ]]; then
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
apt update
fi
apt install -y ${package}
fi
done
echo -e "\033[0;33m### Is Photobooth the only website on this system?"
read -p "### Warning: If typing y, the whole /var/www/html folder will be removed! [y/N] " -n 1 -r deleteHtmlFolder
echo -e "\033[0m"
if [ "$deleteHtmlFolder" != "${deleteHtmlFolder#[Yy]}" ] ;then
info "### Ok, we will replace the html folder with the Photobooth."
cd /var/www/
rm -rf html
INSTALLFOLDER="html"
INSTALLFOLDERPATH="/var/www/html/"
else
info "### Ok, we will install Photobooth into /var/www/html/photobooth."
cd /var/www/html/
INSTALLFOLDER="photobooth"
INSTALLFOLDERPATH="/var/www/html/$INSTALLFOLDER/"
fi
info "### Now we are going to install Photobooth."
git clone https://github.com/andi34/photobooth $INSTALLFOLDER
cd $INSTALLFOLDERPATH
echo -e "\033[0;33m### Please select a version to install:"
echo -e " 1 Install last development version"
echo -e " 2 Install last stable Release"
read -p "Please enter your choice: " -n 1 -r
echo -e "\033[0m"
if [[ $REPLY =~ ^[1]$ ]]
then
info "### We are installing last development version"
VERSION="development"
git fetch origin dev
git checkout origin/dev
else
if [[ ! $REPLY =~ ^[2]$ ]]
then
info "### Invalid choice!"
fi
LATEST_VERSION=$( git describe --tags `git rev-list --tags --max-count=1` )
VERSION="stable2"
info "### We are installing last stable Release: Version $LATEST_VERSION"
git checkout $LATEST_VERSION
fi
git submodule update --init
info "### Get yourself a hot beverage. The following step can take up to 15 minutes."
yarn install
yarn build
# Pi specific setup start
if [ "$RUNNING_ON_PI" = true ]; then
echo -e "\033[0;33m### Do you like to use a Raspberry Pi (HQ) Camera to take pictures?"
read -p "### If yes, this will generate a personal configuration with all needed changes. [y/N] " -n 1 -r
echo -e "\033[0m"
if [[ $REPLY =~ ^[Yy]$ ]]
then
(cat << EOF) > $INSTALLFOLDERPATH/config/my.config.inc.php
<?php
\$config = array (
'take_picture' =>
array (
'cmd' => 'raspistill -n -o %s -q 100 -t 1 | echo "Done"',
'msg' => 'Done',
),
);
EOF
fi
fi
# Pi specific setup end
info "### Setting permissions."
chown -R www-data:www-data $INSTALLFOLDERPATH
gpasswd -a www-data plugdev
gpasswd -a www-data video
if [ -f "/usr/lib/gvfs/gvfs-gphoto2-volume-monitor" ]; then
info "### Disabling camera automount."
chmod -x /usr/lib/gvfs/gvfs-gphoto2-volume-monitor
fi
echo -e "\033[0;33m### You probably like to use a printer."
read -p "### You like to install CUPS and set needing printer permissions? [y/N] " -n 1 -r
echo -e "\033[0m"
if [[ $REPLY =~ ^[Yy]$ ]]
then
info "### Installing CUPS and setting printer permissions."
apt install -y cups
gpasswd -a www-data lp
gpasswd -a www-data lpadmin
fi
# Pi specific setup start
if [ "$RUNNING_ON_PI" = true ]; then
echo -e "\033[0;33m### You probably like to start the browser on every start."
read -p "### Open Chromium in Kiosk Mode at every boot and hide the mouse cursor? [y/N] " -n 1 -r
echo -e "\033[0m"
if [[ $REPLY =~ ^[Yy]$ ]]
then
apt install -y unclutter
cat >> /etc/xdg/lxsession/LXDE-pi/autostart <<EOF
@xset s off
@xset -dpms
@xset s noblank
@chromium-browser --incognito --kiosk http://localhost/
@unclutter -idle 3
EOF
fi
info "### Remote Buzzer Feature"
info "### Configure Raspberry PI GPIOs for Photobooth - please reboot in order use the Remote Buzzer Feature"
usermod -a -G gpio www-data
# remotebuzzer config depending on version
if [ "$VERSION" == "stable2" ]; then
# stable2
info "### Enable Nodejs GPIO access - please reboot in order to use the Remote Buzzer Feature"
cat > /etc/udev/rules.d/20-photobooth-gpiomem.rules <<EOF
SUBSYSTEM=="bcm2835-gpiomem", KERNEL=="gpiomem", GROUP="gpio", MODE="0660"
EOF
sed -i '/dtoverlay=gpio-no-irq/d' /boot/config.txt
cat >> /boot/config.txt << EOF
dtoverlay=gpio-no-irq
EOF
else
# latest development version + stable3
# remove old artifacts from node-rpio library, if there was
if [ -f '/etc/udev/rules.d/20-photobooth-gpiomem.rules' ]; then
info "### Remotebuzzer switched from node-rpio to onoff library. We detected an old remotebuzzer installation and will remove artifacts"
rm -f /etc/udev/rules.d/20-photobooth-gpiomem.rules
sed -i '/dtoverlay=gpio-no-irq/d' /boot/config.txt
fi
# add configuration required for onoff library
sed -i '/Photobooth/,/Photobooth End/d' /boot/config.txt
cat >> /boot/config.txt << EOF
# Photobooth
gpio=16,20,21=pu
# Photobooth End
EOF
# add configuration required for www-data to be able to initiate system shutdown
info "### Note: In order for the shutdown button to work we install /etc/sudoers.d/020_www-data-shutdown"
cat >> /etc/sudoers.d/020_www-data-shutdown << EOF
# Photobooth Remotebuzzer shutdown button for www-data to shutdown the system
www-data ALL=(ALL) NOPASSWD: /sbin/shutdown
EOF
fi
# remotebuzzer config depending on version end
echo -e "\033[0;33m### Sync to USB - this feature will automatically copy (sync) new pictures to a USB stick."
echo -e "### The actual configuration will be done in the admin panel but we need to setup Raspberry Pi OS first"
read -p "### Would you like to enable the USB sync file backup? [y/N] " -n 1 -r
echo -e "\033[0m"
if [[ $REPLY =~ ^[Yy]$ ]]
then
info "### Disabling automount for pi user"
mkdir -p /home/pi/.config/pcmanfm/LXDE-pi/
cat >> /home/pi/.config/pcmanfm/LXDE-pi/pcmanfm.conf <<EOF
[volume]
mount_on_startup=0
mount_removable=0
autorun=0
EOF
chown -R pi:pi /home/pi/.config/pcmanfm
info "### Adding polkit rule so www-data can (un)mount drives"
cat >> /etc/polkit-1/localauthority/50-local.d/udisks2.pkla <<EOF
[Allow www-data to mount drives with udisks2]
Identity=unix-user:www-data
Action=org.freedesktop.udisks2.filesystem-mount*;org.freedesktop.udisks2.filesystem-unmount*
ResultAny=yes
ResultInactive=yes
ResultActive=yes
EOF
fi
fi
# Pi specific setup end
info "### Congratulations you finished the install process."
info "### Have fun with your Photobooth, but first restart your device."
echo -e "\033[0;33m"
read -p "### Do you like to reboot now? [y/N] " -n 1 -r
echo -e "\033[0m"
if [[ $REPLY =~ ^[Yy]$ ]]
then
info "### Your device will reboot now."
shutdown -r now
fi