forked from andi34/photobooth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-raspbian.sh
executable file
·311 lines (259 loc) · 9.35 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
#!/bin/bash
# Stop on the first sign of trouble
set -e
# Show all commands
# set -x
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"
}
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
error "ERROR: This installer is only intended to run on a Raspberry Pi."
exit 2
fi
PI_MODEL=$(tr -d '\0' </proc/device-tree/model)
if [[ $PI_MODEL != Raspberry* ]]; then
error "ERROR: This installer is only intended to run on a Raspberry Pi."
exit 3
fi
if [[ ! -z $1 && ("$1" = "nginx" || "$1" = "lighttpd") ]]; then
info "### Used webserver: $webserver"
else
info "### Used webserver: Apache Webserver"
fi
COMMON_PACKAGES=(
'git'
'gphoto2'
'jq'
'libimage-exiftool-perl'
'nodejs'
'npm'
'php-gd'
'yarn'
)
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
echo -e "\033[0;33m### Do you like to install from git? This will take more"
read -p "### time but it is recommended and makes updating Photobooth easier. [y/N] " -n 1 -r
echo -e "\033[0m"
if [[ $REPLY =~ ^[Yy]$ ]]
then
info "### Your wish is my command!"
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"
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` )
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
else
info "### Your wish is my command!"
info "### Downloading the latest release and extracting it."
curl -s https://api.github.com/repos/andi34/photobooth/releases/latest |
jq '.assets[].browser_download_url | select(endswith(".tar.gz"))' |
xargs curl -L --output /tmp/photobooth-latest.tar.gz
mkdir -p $INSTALLFOLDERPATH
tar -xzvf /tmp/photobooth-latest.tar.gz -C $INSTALLFOLDERPATH
cd $INSTALLFOLDERPATH
fi
info "### Setting permissions."
chown -R www-data:www-data $INSTALLFOLDERPATH
gpasswd -a www-data plugdev
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
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 "### Enable Nodejs GPIO access - please reboot in order to use the Remote Buzzer Feature"
usermod -a -G gpio www-data
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
info "### Congratulations you finished the install process."
info "### Have fun with your Photobooth, but first restart your Pi."
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 Raspberry Pi will reboot now."
shutdown -r now
fi