forked from PhotoboothProject/photobooth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-photobooth.sh
executable file
·1617 lines (1434 loc) · 53.9 KB
/
install-photobooth.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
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# Stop on the first sign of trouble
set -e
USERNAME=''
WEBSERVER="apache"
SILENT_INSTALL=false
RUNNING_ON_PI=true
RASPBERRY_PI_5=false
FORCE_RASPBERRY_PI=false
DATE=$(date +"%Y%m%d-%H-%M")
IPADDRESS=$(hostname -I | cut -d " " -f 1)
PHOTOBOOTH_TMP_LOG="/tmp/$DATE-photobooth.txt"
BRANCH="main"
GIT_INSTALL=true
SUBFOLDER=true
KIOSK_MODE=false
HIDE_MOUSE=false
USB_SYNC=false
SETUP_CUPS=false
GPHOTO_PREVIEW=false
MJPEG_PREVIEW=false
MJPEG_PREVIEW_ONLY=false
CUPS_REMOTE_ANY=false
WEBBROWSER="unknown"
KIOSK_FLAG="--kiosk http://localhost"
CHROME_FLAGS=false
CHROME_DEFAULT_FLAGS="--noerrdialogs --disable-infobars --disable-features=Translate --no-first-run --check-for-update-interval=31536000 --touch-events=enabled --password-store=basic"
AUTOSTART_FILE=""
DESKTOP_OS=true
WAYLAND_ENV=true
PHP_VERSION="8.3"
GO2RTC_VERSION="v1.8.6-4"
# Update
RUN_UPDATE=false
BACKUPBRANCH="backup-$DATE"
PHOTOBOOTH_FOUND=false
PHOTOBOOTH_PATH=(
'/var/www/html'
'/var/www/html/photobooth'
)
PHOTOBOOTH_SUBMODULES=(
'vendor/rpihotspot'
'vendor/Seriously'
)
# Node.js
NEEDS_NODEJS_CHECK=true
NODEJS_CHECKED=false
NODEJS_MAJOR="18"
NODEJS_MINOR="17"
NODEJS_MICRO="0"
NEEDED_NODE_VERSION="v$NODEJS_MAJOR.$NODEJS_MINOR(.$NODEJS_MICRO or newer)"
NEEDS_NPM_CHECK=true
COMMON_PACKAGES=(
'gphoto2'
'libimage-exiftool-perl'
'nodejs'
"php${PHP_VERSION}-gd"
"php${PHP_VERSION}-xml"
"php${PHP_VERSION}-zip"
"php${PHP_VERSION}-mbstring"
'python3'
'rsync'
'udisks2'
)
EXTRA_PACKAGES=(
'curl'
'gcc'
'g++'
'make'
)
INSTALL_PACKAGES=()
DEBIAN=(
'buster'
'bullseye'
'bookworm'
)
function info {
echo -e "\033[0;36m${1}\033[0m"
echo "${1}" >>"$PHOTOBOOTH_TMP_LOG"
}
function warn {
echo -e "\033[0;33m${1}\033[0m"
echo "WARN: ${1}" >>"$PHOTOBOOTH_TMP_LOG"
}
function error {
echo -e "\033[0;31m${1}\033[0m"
echo "ERROR: ${1}" >>"$PHOTOBOOTH_TMP_LOG"
}
function print_spaces() {
echo ""
info "###########################################################"
echo ""
}
function print_logo() {
echo "
@@@@@@@@@@@@@@@@@@@
@@. .@@
%@@@@@@. @@ @@@@@@@@@ @@
@@@ @@* @@. .@@
&@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&
@@@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@@@
@@ @@
@@ @@@@@@@@@@@@@. *@@ @@@@@ @@
@@ @@@@ @@@@ @@
@@@@@@@@@@@@@@@@@@@@@ #@@@@@@@# @@@@@@@@@@@@@@@@@@@@@
@@ @@@ @@@@( (@@@@ @@@ @@
@@ &@@ .@@% %@@. @@& @@
@@ @@ @@ @@ @@ @@
@@ %@@ @@* /@@ @@% @@
@@ @@% @@ @@ %@@ @@
@@ *@@ @@& &@@ @@* @@
@@ @@ @@* *@@ @@ @@
@@ @@ @@@ @@@ @@ @@
@@%%%%%%%%%%%%%%%@@% @@@@@&%&@@@@@ %@@%%%%%%%%%%%%%%%@@
@@@@@@@@@@@@@@@@@@@@@@ *&@&* @@@@@@@@@@@@@@@@@@@@@@
@@ ,@@@@& &@@@@, @@
@@ (@@@@@@@@@( @@
@@ @@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
"
}
#Param 1: Question / Param 2: Default / silent answer
function ask_yes_no {
if [ "$SILENT_INSTALL" = false ]; then
read -p "${1}: " -n 1 -r
else
REPLY=${2}
fi
}
function no_raspberry {
warn "WARNING: This script is intended to run on a Raspberry Pi."
warn "Running the script on other devices running Debian / a Debian based distribution is possible, but Raspberry Pi specific features will be missing!"
RUNNING_ON_PI=false
print_spaces
}
function view_help() {
cat <<EOF
Usage: sudo bash install-photobooth.sh -u=<YourUsername> [-b=<stable4:dev:package> -hprsV -w=<apache:nginx:lighttpd]
-h, -help, --help Display help.
-b, -branch, --branch Enter the Photobooth branch (version) you like to install.
Available branches: dev (default), stable4, stable3, package
By default, latest development verison (dev) will be installed.
package will install latest Release from zip.
-p, -php, --php Choos the PHP version to install (Default = 8.3)
-r, -raspberry, --raspberry Skip Pi detection and add Pi specific adjustments.
Note: only to use on Raspberry Pi OS!
-s, -silent, --silent Run silent installation:
- Uses Apache Webserver
- installs Photobooth into /var/www/html
- installs latest Photobooth development version via git
- installs CUPS
- deny remote access to CUPS over IP from all devices inside
your network (automatic image building failes to enable
because cups can't be configured while in chroot env)
- installs a collection of free-software printer drivers (Gutenprint)
- disables screen saver and hide the mouse cursor (Raspberry Pi only)
- adds config for USB sync file backup (Raspberry Pi only)
-update, --update Try updating Photobooth via git.
-u, -username, --username Always required. Enter your OS username you like to use Photobooth on.
-m, -mjpeg, --mjpeg Install go2rtc to provide remote preview (via URL) of your camera.
-M, -mjpeg-only, --mjpeg-only Only install go2rtc to provide remote preview (via URL) of your camera, then exit
-V, -verbose, --verbose Run script in verbose mode.
-w, -webserver, --webserver Enter the webserver to use [apache, nginx, lighttpd].
Apache is used by default.
Example to install Photobooth on a Raspberry Pi getting asked for enabled options:
sudo bash install-photobooth.sh -u="photobooth"
Options can be combined. Example for a silent installation on a Raspberry Pi:
sudo bash install-photobooth.sh -u="photobooth" -s
EOF
}
print_logo
print_spaces
info "### The Photobooth installer for your Raspberry Pi."
print_spaces
info "################## Passed options #########################"
echo ""
options=$(getopt -l "help,branch::,php::,update,username::,raspberry,mjpeg,mjpeg-only,silent,verbose,webserver::" -o "hb::p::u::rsmMVw::" -a -- "$@")
eval set -- "$options"
while true; do
case $1 in
-h | --help)
view_help
exit 0
;;
-b | --branch)
shift
if [ "$1" == "dev" ] || [ "$1" == "stable4" ] || [ "$1" == "main" ]; then
BRANCH=$1
GIT_INSTALL=true
elif [ "$1" == "package" ]; then
BRANCH="stable4"
GIT_INSTALL=false
NEEDS_NODEJS_CHECK=false
NEEDS_NPM_CHECK=false
else
BRANCH="main"
GIT_INSTALL=true
warn "[WARN] Invalid branch / version!"
warn "[WARN] Falling back to defaults. Installing latest development branch from git."
fi
info "### Photobooth version / branch: $1"
;;
-p | --php)
shift
PHP_VERSION=$1
info "### PHP Version: $1"
;;
--update)
RUN_UPDATE=true
GIT_INSTALL=false
info "### Trying to update Photobooth..."
;;
-u | --username)
shift
USERNAME=$1
info "### Username: $1"
;;
-m | --mjpeg)
MJPEG_PREVIEW=true
GPHOTO_PREVIEW=false
info "### Mjpeg mode enabled"
;;
-M | --mjpeg-only)
MJPEG_PREVIEW_ONLY=true
info "### Only install mjpeg"
;;
-s | --silent)
SILENT_INSTALL=true
info "### Silent installtion starting..."
;;
-r | --raspberry)
FORCE_RASPBERRY_PI=true
info "### Skipping Pi detection and add specific adjustments..."
;;
-V | --verbose)
set -xv
info "### Set xtrace and verbose mode."
;;
-w | --webserver)
shift
WEBSERVER=$1
info "### Webserver: $1"
;;
--)
shift
break
;;
esac
shift
done
print_spaces
if [ "$(dpkg-query -W -f='${Status}' "lxde" 2>/dev/null | grep -c "ok installed")" -eq 1 ]; then
DESKTOP_OS=true
else
DESKTOP_OS=false
fi
function check_username() {
info "[Info] Checking if user $USERNAME exists..."
if id "$USERNAME" &>/dev/null; then
info "[Info] User $USERNAME found. Installation process continues."
else
error "ERROR: An valid OS username is needed! Please re-run the installer."
view_help
exit
fi
}
function check_nodejs() {
NODE_VERSION=$(node -v || echo "0")
IFS=. read -r -a VER <<<"${NODE_VERSION##*v}"
major=${VER[0]}
minor=${VER[1]}
info "[Info] Node.js on Photobooth is only supported on v$NODEJS_MAJOR.$NODEJS_MINOR!"
info "[Info] Found Node.js $NODE_VERSION".
if [[ -n "$major" ]] && [[ "$major" -ge "$NODEJS_MAJOR" ]]; then
if [[ -n "$major" ]] && [[ "$major" -ge "19" ]]; then
info "[Info] Node.js downgrade suggested."
if [ "$NODEJS_CHECKED" = true ]; then
warn "[WARN] Downgrade of Node.js was not possible or skipped."
else
update_nodejs
fi
else
if [[ "$major" -eq "$NODEJS_MAJOR" ]] && [[ "$minor" -lt "$NODEJS_MINOR" ]]; then
if [ "$NODEJS_CHECKED" = true ]; then
error "[ERROR] Update of Node.js was not possible. Aborting Photobooth installation!"
exit 1
else
warn "[WARN] Node.js needs to be updated."
update_nodejs
fi
else
info "[Info] Node.js matches our requirements.".
fi
fi
elif [[ -n "$major" ]]; then
if [ "$NODEJS_CHECKED" = true ]; then
error "[ERROR] Update of Node.js was not possible. Aborting Photobooth installation!"
exit 1
else
update_nodejs
fi
else
error "[ERROR] Unable to handle Node.js version string (major)"
exit 1
fi
}
function update_nodejs() {
echo -e "\033[0;33m### Node.js should be updated/downgraded. Node.js version not matching our requirements"
echo -e "### Found Node.js $NODE_VERSION, but $NEEDED_NODE_VERSION is suggested."
echo -e "### NOTE: Currently Node.js on Photobooth is only supported on v$NODEJS_MAJOR.$NODEJS_MINOR."
echo -e "### The installation of Photobooth will fail on Node.js versions below v$NODEJS_MAJOR.$NODEJS_MINOR."
ask_yes_no "### Would you like to update/downgrade Node.js to $NEEDED_NODE_VERSION ? [y/N] " "Y"
echo -e "\033[0m"
if [[ $REPLY =~ ^[Yy]$ ]]; then
if [ "$(dpkg-query -W -f='${Status}' "nodejs" 2>/dev/null | grep -c "ok installed")" -eq 1 ]; then
info "[Cleanup] Removing nodejs package"
apt-get -qq purge -y nodejs
apt-get -qq autoremove --purge -y
fi
if [ "$(dpkg-query -W -f='${Status}' "nodejs-doc" 2>/dev/null | grep -c "ok installed")" -eq 1 ]; then
info "[Cleanup] Removing nodejs-doc package"
apt-get -qq purge -y nodejs-doc
fi
if [ "$(dpkg-query -W -f='${Status}' "libnode72" 2>/dev/null | grep -c "ok installed")" -eq 1 ]; then
info "[Cleanup] Removing libnode72 package"
apt-get -qq purge -y libnode72
fi
if [ "$(dpkg-query -W -f='${Status}' "npm" 2>/dev/null | grep -c "ok installed")" -eq 1 ]; then
info "[Cleanup] Removing npm package"
apt-get -qq purge -y npm
fi
info "[Package] Installing latest Node.js v18"
apt-get -qq install -y ca-certificates curl gnupg
mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
apt-get -qq update
apt-get -qq install -y nodejs
NODEJS_CHECKED=true
check_nodejs
else
info "### We won't update Node.js."
NODEJS_CHECKED=true
check_nodejs
fi
}
function proof_npm() {
npm_version=$(npm -v)
npm_major=$(echo "$npm_version" | cut -d. -f1)
npm_minor=$(echo "$npm_version" | cut -d. -f2)
info "[Info] Found npm $npm_version"
if [[ "$npm_major" -gt 9 ]] || [[ "$npm_major" -eq 9 ]] && [[ "$npm_minor" -ge 6 ]]; then
info "[Info] npm version matches our requirements."
else
warn "[WARN] npm needs to be updated!"
apt-get -qq --only-upgrade install npm
npm install npm@9.6.7 -g
hash -r
npm_version_updated=$(npm -v)
npm_major_updated=$(echo "$npm_version_updated" | cut -d. -f1)
npm_minor_updated=$(echo "$npm_version_updated" | cut -d. -f2)
info "[Info] Found Node.js $npm_version_updated".
if [[ "$npm_major_updated" -gt 9 ]] || [[ "$npm_major_updated" -eq 9 ]] && [[ "$npm_minor_updated" -ge 6 ]]; then
info "[Info] npm version matches our requirements."
else
error "[ERROR] Update of npm was not possible. Aborting Photobooth installation!"
exit 1
fi
fi
}
function check_npm() {
if command -v npm &>/dev/null; then
info "[Info] npm available.".
else
info "[Info] npm not installed. Trying to install...".
apt-get -qq update
apt-get -qq install -y npm
fi
proof_npm
}
function common_software() {
info "### Updating the system"
apt-get -qq update
apt-get -qq install apt-transport-https lsb-release ca-certificates software-properties-common -y
OS=$(lsb_release -sc)
if [[ "${DEBIAN[*]}" =~ $OS ]]; then
wget -qO /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list
elif [[ "$OS" == "mantic" ]]; then
info "### No source lists available."
else
if [[ "$OS" == "jammy" ]]; then
echo "deb http://archive.ubuntu.com/ubuntu/ jammy-updates main restricted" >>/etc/apt/sources.lst
fi
add-apt-repository ppa:ondrej/php -y
fi
apt-get -qq update
if [ "$RUN_UPDATE" = false ]; then
info "### Photobooth needs some software to run."
if [ "$WEBSERVER" == "nginx" ]; then
nginx_webserver
elif [ "$WEBSERVER" == "lighttpd" ]; then
lighttpd_webserver
else
apache_webserver
fi
fi
if [ "$GIT_INSTALL" = true ]; then
EXTRA_PACKAGES+=(
'git'
)
else
EXTRA_PACKAGES+=(
'jq'
)
fi
# Note: raspberrypi-kernel-header are needed before v4l2loopback-dkms
if [ "$RUNNING_ON_PI" = true ]; then
EXTRA_PACKAGES+=('raspberrypi-kernel-headers')
fi
if [ "$GPHOTO_PREVIEW" = true ]; then
EXTRA_PACKAGES+=(
'ffmpeg'
'python3-gphoto2'
'python3-psutil'
'python3-zmq'
'v4l2loopback-dkms'
'v4l-utils'
)
fi
# Additional packages
INSTALL_PACKAGES+=("${EXTRA_PACKAGES[@]}")
# All required packages independend of Raspberry Pi.
INSTALL_PACKAGES+=("${COMMON_PACKAGES[@]}")
info "### Installing common software:"
for required in "${INSTALL_PACKAGES[@]}"; do
info "[Required] ${required}"
done
for package in "${INSTALL_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}"
apt-get -qq install -y "$package"
fi
done
if [ "$NEEDS_NODEJS_CHECK" = true ]; then
check_nodejs
fi
if [ "$NEEDS_NPM_CHECK" = true ]; then
check_npm
fi
}
function apache_webserver() {
info "### Installing Apache Webserver..."
apt-get -qq install -y apache2 libapache2-mod-php"$PHP_VERSION"
sudo systemctl enable --now apache2
}
function nginx_webserver() {
nginx_site_conf="/etc/nginx/sites-enabled/default"
nginx_conf="/etc/nginx/nginx.conf"
info "### Installing NGINX Webserver..."
apt-get -qq install -y nginx php"$PHP_VERSION" php"$PHP_VERSION"-fpm
if [ -f "$nginx_site_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_site_conf"
sed -i '/location ~ \\.php$ {/s/^\(\s*\)#/\1/g' "$nginx_site_conf"
sed -i '/include snippets\/fastcgi-php.conf/s/^\(\s*\)#/\1/g' "$nginx_site_conf"
sed -i '/fastcgi_pass unix:\/run\/php\//s/^\(\s*\)#/\1/g' "$nginx_site_conf"
sed -i '/.*fastcgi_pass unix:\/run\/php\//,// { /}/s/^\(\s*\)#/\1/g; }' "$nginx_site_conf"
sed -i "/fastcgi_pass unix:/s/php\([[:digit:]].*\)-fpm/php${PHP_VERSION}-fpm/g" "$nginx_site_conf"
sed -i '/^include \/etc\/nginx\/sites-enabled\/\*;/a client_max_body_size 100M;' "$nginx_conf"
info "### Testing NGINX config"
/usr/sbin/nginx -t -c "$nginx_conf"
info "### Restarting NGINX"
systemctl reload-or-restart nginx
systemctl enable nginx
systemctl reload-or-restart php"$PHP_VERSION"-fpm
systemctl enable php"$PHP_VERSION"-fpm
else
error "Can not find ${nginx_conf} !"
info "Using Apache Webserver !"
apt-get -qq remove -y nginx php"$PHP_VERSION"-fpm
apache_webserver
fi
}
function lighttpd_webserver() {
info "### Installing Lighttpd Webserver..."
apt-get -qq install -y lighttpd php"$PHP_VERSION"-fpm
lighttpd-enable-mod fastcgi
lighttpd-enable-mod fastcgi-php
lighttpd_php_conf="/etc/lighttpd/conf-available/15-fastcgi-php.conf"
if [ -f "$lighttpd_php_conf" ]; then
info "### Enable PHP for Lighttpd"
cp "$lighttpd_php_conf" "$lighttpd_php_conf".bak
cat >"$lighttpd_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/php${PHP_VERSION}-fpm.sock",
"broken-scriptfilename" => "enable"
))
)
EOF
systemctl reload-or-restart lighttpd
systemctl enable lighttpd
systemctl reload-or-restart php"$PHP_VERSION"-fpm.service
systemctl enable php"$PHP_VERSION"-fpm.service
else
error "Can not find ${lighttpd_php_conf} !"
info "Using Apache Webserver !"
apt-get -qq remove -y lighttpd php"$PHP_VERSION"-fpm
apache_webserver
fi
}
function general_setup() {
if [ "$SUBFOLDER" = true ]; then
cd /var/www/html/
INSTALLFOLDER="photobooth"
INSTALLFOLDERPATH="/var/www/html/$INSTALLFOLDER"
URL="http://$IPADDRESS/$INSTALLFOLDER"
else
cd /var/www/
INSTALLFOLDER="html"
INSTALLFOLDERPATH="/var/www/html"
URL="http://$IPADDRESS"
fi
if [ -d "$INSTALLFOLDERPATH" ]; then
BACKUPFOLDER="html-$DATE"
info "${INSTALLFOLDERPATH} found. Creating backup as ${BACKUPFOLDER}."
mv "$INSTALLFOLDER" "$BACKUPFOLDER"
else
info "$INSTALLFOLDERPATH not found."
fi
mkdir -p "$INSTALLFOLDERPATH"
chown www-data:www-data "$INSTALLFOLDERPATH"
chown www-data:www-data /var/www
PHOTOBOOTH_LOG="$INSTALLFOLDERPATH/private/install.log"
}
function add_git_remote() {
cd "$INSTALLFOLDERPATH"/
info "### Checking needed remote information..."
if sudo -u www-data git config remote.photoboothproject.url >/dev/null; then
info "### photoboothproject remote exist already"
if sudo -u www-data git config remote.origin.url == "git@github.com:andi34/photobooth" || sudo -u www-data git config remote.origin.url == "https://github.com/andi34/photobooth.git"; then
info "origin remote is andi34"
fi
else
info "### Adding photoboothproject remote..."
sudo -u www-data git remote add photoboothproject https://github.com/snmabaur/photobooth
fi
}
function check_git_install() {
cd "$INSTALLFOLDERPATH"
info "### Checking for git Installation"
if [ "$(sudo -u www-data git rev-parse --is-inside-work-tree)" = true ]; then
info "### Photobooth installed via git."
GIT_INSTALL=true
add_git_remote
else
warn "WARN: Not a git Installation."
fi
}
function start_git_install() {
cd "$INSTALLFOLDERPATH"
info "### We are installing/updating Photobooth via git."
info "### Ignoring filemode changes on git."
sudo -u www-data git config core.fileMode false
sudo -u www-data git fetch photoboothproject "$BRANCH"
sudo -u www-data git checkout photoboothproject/"$BRANCH"
sudo -u www-data git submodule update --init
if [ -f "0001-backup-changes.patch" ]; then
info "### Trying to apply your local changes again..."
sudo -u www-data git am --whitespace=nowarn "0001-backup-changes.patch" && PATCH_SUCCESS=true || PATCH_SUCCESS=false
if [ "$PATCH_SUCCESS" = true ]; then
info "### Changes applied successfully!"
sudo -u www-data git reset --soft HEAD^
else
error "ERROR: can not apply your local changes automatically!"
sudo -u www-data git am --abort
fi
sudo -u www-data mv 0001-backup-changes.patch "$INSTALLFOLDERPATH/private/$DATE"-backup-changes.patch
fi
info "### Get yourself a hot beverage. The following step can take up to 15 minutes."
mkdir -p /var/www/.npm
chown www-data:www-data /var/www/.npm
mkdir -p /var/www/.cache
chown www-data:www-data /var/www/.cache
sudo -u www-data npm install
sudo -u www-data npm run build
}
function start_install() {
info "### Now we are going to install Photobooth."
if [ "$GIT_INSTALL" = true ]; then
sudo -u www-data git clone https://github.com/snmabaur/photobooth "$INSTALLFOLDER"
cd "$INSTALLFOLDERPATH"
add_git_remote
start_git_install
else
info "### We are downloading the latest release and extracting it to $INSTALLFOLDERPATH."
sudo -u www-data curl -s https://api.github.com/repos/PhotoboothProject/photobooth/releases/latest |
jq '.assets[].browser_download_url | select(endswith(".tar.gz"))' |
xargs curl -L --output /tmp/photobooth-latest.tar.gz
sudo -u www-data mkdir -p "$INSTALLFOLDERPATH"
sudo -u www-data tar -xzvf /tmp/photobooth-latest.tar.gz -C "$INSTALLFOLDERPATH"
cd "$INSTALLFOLDERPATH"
fi
}
function detect_browser() {
if [ "$(dpkg-query -W -f='${Status}' "firefox" 2>/dev/null | grep -c "ok installed")" -eq 1 ]; then
WEBBROWSER="firefox"
CHROME_FLAGS=false
elif [ "$(dpkg-query -W -f='${Status}' "firefox-esr" 2>/dev/null | grep -c "ok installed")" -eq 1 ]; then
WEBBROWSER="firefox-esr"
CHROME_FLAGS=false
elif [ "$(dpkg-query -W -f='${Status}' "chromium-browser" 2>/dev/null | grep -c "ok installed")" -eq 1 ]; then
WEBBROWSER="chromium-browser"
CHROME_FLAGS=true
elif [ "$(dpkg-query -W -f='${Status}' "chromium" 2>/dev/null | grep -c "ok installed")" -eq 1 ]; then
WEBBROWSER="chromium"
CHROME_FLAGS=true
elif [ "$(dpkg-query -W -f='${Status}' "google-chrome" 2>/dev/null | grep -c "ok installed")" -eq 1 ]; then
WEBBROWSER="google-chrome"
CHROME_FLAGS=true
elif [ "$(dpkg-query -W -f='${Status}' "google-chrome-stable" 2>/dev/null | grep -c "ok installed")" -eq 1 ]; then
WEBBROWSER="google-chrome-stable"
CHROME_FLAGS=true
elif [ "$(dpkg-query -W -f='${Status}' "google-chrome-beta" 2>/dev/null | grep -c "ok installed")" -eq 1 ]; then
WEBBROWSER="google-chrome-beta"
CHROME_FLAGS=true
else
WEBBROWSER="unknown"
CHROME_FLAGS=false
fi
}
function browser_shortcut() {
if [ "$CHROME_FLAGS" = true ]; then
if [ "$RUNNING_ON_PI" = true ]; then
if [ "$WAYLAND_ENV" = true ]; then
EXTRA_FLAGS="$CHROME_DEFAULT_FLAGS --ozone-platform=wayland --start-maximized"
else
EXTRA_FLAGS="$CHROME_DEFAULT_FLAGS --use-gl=egl"
fi
else
EXTRA_FLAGS="$CHROME_DEFAULT_FLAGS"
fi
else
EXTRA_FLAGS=""
fi
echo "[Desktop Entry]" >"$AUTOSTART_FILE"
{
echo "Version=1.3"
echo "Terminal=false"
echo "Type=Application"
echo "Name=Photobooth"
} >>"$AUTOSTART_FILE"
if [ "$SUBFOLDER" = true ]; then
echo "Exec=$WEBBROWSER $KIOSK_FLAG/$INSTALLFOLDER $EXTRA_FLAGS" >>"$AUTOSTART_FILE"
else
echo "Exec=$WEBBROWSER $KIOSK_FLAG $EXTRA_FLAGS" >>"$AUTOSTART_FILE"
fi
{
echo "Icon=$INSTALLFOLDERPATH/resources/img/favicon-96x96.png"
echo "StartupNotify=false"
echo "Terminal=false"
} >>"$AUTOSTART_FILE"
}
function browser_desktop_shortcut() {
if [ -d "/home/$USERNAME/Desktop" ] && [ "$USERNAME" != "" ]; then
info "### Adding photobooth shortcut to Desktop"
AUTOSTART_FILE="/home/$USERNAME/Desktop/photobooth.desktop"
browser_shortcut
chmod +x /home/"$USERNAME"/Desktop/photobooth.desktop
chown "$USERNAME:$USERNAME" /home/"$USERNAME"/Desktop/photobooth.desktop
fi
}
function browser_autostart() {
AUTOSTART_FILE="/etc/xdg/autostart/photobooth.desktop"
browser_shortcut
}
function ask_kiosk_mode() {
echo -e "\033[0;33m### You probably like to start $WEBBROWSER on every start."
ask_yes_no "### Open $WEBBROWSER in Kiosk Mode at every boot? [y/N] " "Y"
echo -e "\033[0m"
if [[ $REPLY =~ ^[Yy]$ ]]; then
KIOSK_MODE=true
info "### We will open $WEBBROWSER in Kiosk Mode at every boot."
else
KIOSK_MODE=false
info "### We won't open $WEBBROWSER in Kiosk Mode at every boot."
fi
}
function ask_hide_mouse() {
echo -e "\033[0;33m### You probably like hide the mouse cursor on every start."
ask_yes_no "### Hide the mouse cursor? [y/N] " "Y"
echo -e "\033[0m"
if [[ $REPLY =~ ^[Yy]$ ]]; then
HIDE_MOUSE=true
if [ "$WAYLAND_ENV" = false ]; then
EXTRA_PACKAGES+=('unclutter')
fi
info "### We will hide the mouse cursor on every start."
else
HIDE_MOUSE=false
info "### We won't hide the mouse cursor on every start."
fi
}
function ask_usb_sync() {
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 your OS first."
ask_yes_no "### Would you like to setup your OS to use the USB sync file backup? [y/N] " "Y"
echo -e "\033[0m"
if [[ $REPLY =~ ^[Yy]$ ]]; then
USB_SYNC=true
info "### We will setup your OS to be able to use the USB sync file backup."
info "### Note: automount can only be avoided on Pi OS."
else
USB_SYNC=false
info "### We won't setup your OS to use the USB sync file backup."
fi
}
function raspberry_permission() {
info "### Remote Buzzer Feature"
info "### Configure Raspberry PI GPIOs for Photobooth - please reboot in order use the Remote Buzzer Feature"
if [ -f '/boot/firmware/config.txt' ]; then
BOOT_CONFIG="/boot/firmware/config.txt"
else
BOOT_CONFIG="/boot/config.txt"
fi
usermod -a -G gpio www-data
# 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"
fi
# add configuration required for onoff library
sed -i '/Photobooth/,/Photobooth End/d' "$BOOT_CONFIG"
if [ "$RASPBERRY_PI_5" = true ]; then
cat >>"$BOOT_CONFIG" <<EOF
# Photobooth
#IN
gpio=404,405,406,407,415,416,419,420,421,425,426=pu
#OUT
gpio=408,409,410,411,417,418,422,423,424=op
# Photobooth End
EOF
else
cat >>"$BOOT_CONFIG" <<EOF
# Photobooth
#IN
gpio=5,6,7,8,16,17,20,21,22,26,27=pu
#OUT
gpio=9,10,11,12,18,19,23,24,25=op
# Photobooth End
EOF
fi
# update artifacts in user configuration from old remotebuzzer implementation
if [ -f "$INSTALLFOLDERPATH/config/my.config.inc.php" ]; then
sed -i '/remotebuzzer/{n;n;s/enabled/usebuttons/}' "$INSTALLFOLDERPATH"/config/my.config.inc.php
fi
if [ "$RUN_UPDATE" = false ]; then
if [ "$USB_SYNC" = true ] && [ "$DESKTOP_OS" = true ]; then
info "### Disabling automount for user $USERNAME."
mkdir -p /home/"$USERNAME"/.config/pcmanfm/LXDE-pi/
cat >>/home/"$USERNAME"/.config/pcmanfm/LXDE-pi/pcmanfm.conf <<EOF
[volume]
mount_on_startup=0
mount_removable=0
autorun=0
EOF
chown -R "$USERNAME:$USERNAME" /home/"$USERNAME"/.config
else
info "### lxde is not installed. Can not add automount config for user $USERNAME."
fi
fi
}
function general_permissions() {
info "### Setting permissions."
chown -R www-data:www-data "$INSTALLFOLDERPATH"/
chmod g+s "$INSTALLFOLDERPATH/private"
gpasswd -a www-data plugdev
gpasswd -a www-data video
gpasswd -a "$USERNAME" www-data
info "### Fixing permissions on cache folder."
mkdir -p "/var/www/.cache"
chown -R www-data:www-data "/var/www/.cache"
info "### Fixing permissions on npm folder."
mkdir -p "/var/www/.npm"
chown -R www-data:www-data "/var/www/.npm"
info "### Disabling camera automount."
chmod -x /usr/lib/gvfs/gvfs-gphoto2-volume-monitor || true
# Add configuration required for www-data to be able to initiate system shutdown / reboot
info "### Note: In order for the shutdown and reboot button to work we install /etc/sudoers.d/020_www-data-shutdown"
cat >/etc/sudoers.d/020_www-data-shutdown <<EOF
# Photobooth buttons for www-data to shutdown or reboot the system from admin panel or via remotebuzzer
www-data ALL=(ALL) NOPASSWD: /sbin/shutdown
EOF
if [ "$USB_SYNC" = true ]; then
info "### Adding polkit rule so www-data can (un)mount drives"
cat >/etc/polkit-1/localauthority/50-local.d/photobooth.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
}
function hide_mouse() {
if [ "$WAYLAND_ENV" = true ]; then
if [ -f "/usr/share/icons/PiXflat/cursors/left_ptr" ]; then
mv /usr/share/icons/PiXflat/cursors/left_ptr /usr/share/icons/PiXflat/cursors/left_ptr.bak
fi
else
if [ -f "/etc/xdg/lxsession/LXDE-pi/autostart" ]; then
sed -i '/Photobooth/,/Photobooth End/d' /etc/xdg/lxsession/LXDE-pi/autostart
fi
cat >>/etc/xdg/lxsession/LXDE-pi/autostart <<EOF
# Photobooth
# turn off display power management system
@xset -dpms
# turn off screen blanking
@xset s noblank
# turn off screen saver
@xset s off
# Hide mousecursor
@unclutter -idle 3
# Photobooth End
EOF
fi
}
function cups_setup() {
info "### Setting printer permissions."
gpasswd -a www-data lp
gpasswd -a www-data lpadmin
if [ "$CUPS_REMOTE_ANY" = true ]; then
info "### Access to CUPS will be allowed from all devices in your network."
cupsctl --remote-any
/etc/init.d/cups restart
fi
}
gphoto_preview() {
# make configs persistent
[[ ! -d /etc/modules-load.d ]] && mkdir /etc/modules-load.d
echo v4l2loopback >/etc/modules-load.d/v4l2loopback.conf
[[ ! -d /etc/modprobe.d ]] && mkdir /etc/modprobe.d
cat >/etc/modprobe.d/v4l2loopback.conf <<EOF
options v4l2loopback exclusive_caps=1 card_label="GPhoto2 Webcam"
blacklist bcm2835-isp
EOF
# adjust current runtime
modprobe v4l2loopback exclusive_caps=1 card_label="GPhoto2 Webcam"
rmmod bcm2835-isp || true
if [[ ! -f $INSTALLFOLDERPATH/config/my.config.inc.php ]]; then
info "### Creating default Photobooth config."
cat >$INSTALLFOLDERPATH/config/my.config.inc.php << EOF
<?php
\$config = array (
'preview' =>
array (
'mode' => 'device_cam',
'cmd' => 'python3 cameracontrol.py',
'bsm' => false,
),
'take_picture' =>
array (
'cmd' => 'python3 cameracontrol.py --capture-image-and-download %s',
),
);
EOF
chown www-data:www-data $INSTALLFOLDERPATH/config/my.config.inc.php
else
info "### Can not set default config!"
info " Please adjust your Photobooth configuration:"
info " Preview mode: from device cam"
info " Command to generate a live preview: python3 cameracontrol.py"
info " Execute start command for preview on take picture/collage: disabled"
info " Take picture command: python3 cameracontrol.py --capture-image-and-download %s"
fi
}
function mjpeg_preview() {
local arch