-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathinstall-photobooth.sh
More file actions
executable file
·4147 lines (3658 loc) · 140 KB
/
install-photobooth.sh
File metadata and controls
executable file
·4147 lines (3658 loc) · 140 KB
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
export LC_ALL=C
export LANG=C
# Initial Variables
LOGFILE="/var/log/photobooth_install.log"
SILENT=false
UPDATE=false
SKIP_AUTO_UPDATE=false
SKIP_WEBSERVER=false
SKIP_PHP=false
SKIP_NODE=false
SKIP_PYTHON=false
PHOTOBOOTH_FOUND=false
INSTALLFOLDERPATH=""
PHOTOBOOTH_SUBFOLDER=""
# Webbrowser
WEBBROWSER="unknown"
# GitHub
GIT_INSTALLED=false
BRANCH="dev"
REMOTE_BRANCH_API="https://api.github.com/repos/PhotoboothProject/photobooth/branches/${BRANCH}"
REMOTE_BRANCH_SHA=""
# OS environment
FORCE_RASPBERRY_PI=false
RUNNING_ON_PI=false
HAS_SYSTEMD=$([[ -x "$(command -v systemctl)" && "$(ps -p 1 -o comm=)" == "systemd" ]] && echo true || echo false)
LOCAL_ARCH=$(uname -m)
OS_CODENAME="unknown"
# PHP
PHP_VERSION="8.4"
DEBIAN=(
"bullseye"
"bookworm"
"trixie"
)
# Node.js
NODEJS_MAJOR="20"
NODEJS_MINOR="15"
# Packages
COMMON_PACKAGES=(
"gphoto2"
"libimage-exiftool-perl"
"nodejs"
"python3"
"rsync"
"udisks2"
)
APACHE_PACKAGES=(
"apache2"
"libapache2-mod-php${PHP_VERSION}"
)
PHP_PACKAGES=(
"php${PHP_VERSION}"
"php${PHP_VERSION}-cli"
"php${PHP_VERSION}-gd"
"php${PHP_VERSION}-xml"
"php${PHP_VERSION}-zip"
"php${PHP_VERSION}-mbstring"
)
EXTRA_PACKAGES=(
"git"
"jq"
"curl"
"gcc"
"g++"
"make"
"apt-transport-https"
"lsb-release"
"ca-certificates"
"software-properties-common"
)
# go2rtc
DEFAULT_GO2RTC_VERSION="1.9.13"
GO2RTC_VERSIONS=("1.9.13" "1.9.12" "1.9.11" "1.9.10" "1.9.9" "1.9.8" "1.9.7" "1.9.6" "1.9.4" "1.9.2")
GO2RTC_UPDATE_ONLY=false
GO2RTC_EXTRA_PACKAGES=(
"ffmpeg"
"fswebcam"
)
# gphoto2 webcam
GPHOTO2_WEBCAM_EXTRA_PACKAGES=(
"v4l2loopback-dkms"
"v4l-utils"
"python3"
"python3-gphoto2"
"python3-psutil"
"python3-zmq"
)
# rembg
REMBG_PACKAGES=(
"python3"
"python3-pip"
"python3-venv"
"php${PHP_VERSION}-curl"
)
REMBG_PIP_PACKAGES=(
"rembg[cpu,cli]"
"pillow"
"filetype"
"watchdog"
"aiohttp"
)
# ==================================================
# Logging / helper functions
# ==================================================
function log() {
echo "$(date '+%Y-%m-%d %H:%M:%S') - $*" >>"$LOGFILE"
}
function confirm() {
local title=$1
local message=$2
local height=${3:-10}
local width=${4:-60}
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1: $2" >>"$LOGFILE"
if [ "$SILENT" = true ]; then
echo "$title: $message"
sleep 2
else
whiptail --title "$title" --msgbox "$message" "$height" "$width"
fi
}
function info() {
local title=$1
local message=$2
local height=${3:-10}
local width=${4:-60}
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1: $2" >>"$LOGFILE"
if [ "$SILENT" = true ]; then
echo "$title: $message"
else
whiptail --title "$title" --infobox "$message" "$height" "$width" < /dev/tty > /dev/tty 2>&1
fi
sleep 1
}
function warn() {
local title="Warning"
local message=$1
local height=${2:-10}
local width=${3:-60}
info "$title" "$message" "$height" "$width"
}
function error() {
local title="Error"
local message=$1
local height=${2:-10}
local width=${3:-60}
info "$title" "$message" "$height" "$width"
}
function print_logo() {
local logo="
%@@@@.
@@ @@*
@@@@@@@@@@@@@@@@@@@@@@
@@%%%%%%%%%%%%%%%%%%%%%@
@@ @@@@@@ @@
@@ @@ @@ @@
@@ @@ @@ @@
@@ @@ @@ @@
@@ @@ @@ @@
@@ @@@@@@ @@
@@%%%%%%%%%%%%%%%%%%%%%@
P H O T O B O O T H
@@%%%%%%%%%%%%%%%%%%%%%@
"
if [ "$SILENT" = true ]; then
echo "$logo"
else
local height=22
local width=50
whiptail --title "Welcome!" --infobox "$logo" "$height" "$width"
fi
sleep 2
}
function show_help() {
echo "Photobooth Setup Wizard"
echo ""
echo "Adjust your setup for Photobooth. Available options:"
echo ""
echo " --branch=<branch> Specify the Git branch to use for installation or updates."
echo " --php=<version> Set the PHP version for the setup (e.g., --php=8.3)."
echo " --silent Run the Photobooth Setup Wizard in silent mode"
echo " for automated installation or updates."
echo " --username=\"<username>\" Required if --silent is used."
echo " Provide a username for installation or updates."
echo " --raspberry Skip automatic Raspberry Pi detection and enable Raspberry Pi specific configuration."
echo " --wayland Skip automatic Wayland detection and enable Wayland configuration."
echo " --update Requires --silent to update Photobooth if installed already."
echo " --skip-webserver Skip web server setup"
echo " (if already configured or e.g. Nginx is used as Webserver)."
echo " --skip-php Skip PHP installation"
echo " (if already configured for used Webserver)."
echo " --skip-node Skip Node.js and npm installation"
echo " (if already installed as required)."
echo " --skip-python Skip python3 installation"
echo " (if already installed as required)."
echo " --skip-auto-update Skip automatic updates for Photobooth Setup Wizard."
echo ""
echo "Examples:"
echo " $0 --silent --branch=dev --php=8.3 --username=\"photobooth\" --update"
echo " $0 --branch=stable4 --skip-webserver"
echo ""
echo "For more information, refer to the documentation at"
echo "https://photoboothproject.github.io"
exit 0
}
function photobooth_installed() {
local search_paths=("/var/www/html/photobooth" "/var/www/html")
for full_path in "${search_paths[@]}"; do
if [[ -d "$full_path" && -f "$full_path/lib/configsetup.inc.php" ]]; then
PHOTOBOOTH_FOUND=true
INSTALLFOLDERPATH="$full_path"
PHOTOBOOTH_SUBFOLDER="${INSTALLFOLDERPATH#/var/www/html}"
return 0
fi
done
return 1
}
function check_installfolderpath() {
if [[ -z "$INSTALLFOLDERPATH" ]]; then
if ! photobooth_installed; then
error "INSTALLFOLDERPATH is not defined or empty!"
return 1
fi
fi
return 0
}
function is_wayland_env() {
if [ "${WAYLAND_ENV:-}" = "true" ]; then
return 0
fi
local conf="/etc/lightdm/lightdm.conf"
if [ -f "$conf" ]; then
session=$(grep -E "^user-session=" "$conf" | cut -d= -f2)
case "$session" in
rpd-labwc|LXDE-pi-labwc|rpd-wayfire|LXDE-pi-wayfire)
return 0
;;
esac
fi
# Fallback: check if wayfire or labwc is running
if pgrep wayfire >/dev/null || pgrep labwc >/dev/null; then
return 0
else
return 1
fi
}
function install_system_icon() {
local icon_dir="/usr/share/icons/hicolor/scalable/apps"
local icon_file="$icon_dir/photobooth.svg"
local icon_url="https://github.com/PhotoboothProject/photobooth/raw/refs/heads/dev/resources/img/favicon.svg"
local local_file=""
# Return if icon already exists
if [[ -f "$icon_file" ]]; then
info "System Icon" "Photobooth icon exists already."
return 0
fi
mkdir -p "$icon_dir"
# Only set local_file if INSTALLFOLDERPATH is valid
if check_installfolderpath; then
local_file="$INSTALLFOLDERPATH/resources/img/favicon.svg"
fi
# Prefer local file over download
if [[ -n "$local_file" && -f "$local_file" ]]; then
cp "$local_file" "$icon_file"
info "System Icon" "Copied Photobooth icon."
elif command -v wget >/dev/null 2>&1; then
if wget -qO "$icon_file" "$icon_url"; then
info "System Icon" "Downloaded Photobooth icon."
else
error "Failed to download icon!"
return 1
fi
else
error "wget not available and no local icon found!"
return 1
fi
chmod 644 "$icon_file"
if command -v update-icon-caches >/dev/null 2>&1; then
update-icon-caches /usr/share/icons/hicolor > /dev/null 2>&1
fi
info "System Icon" "Photobooth system icon installed successfully"
return 0
}
function install_package() {
local package=$1
if dpkg-query -W -f='${Status}' "$package" 2>/dev/null | grep -q "ok installed"; then
info "Package installation" "${package} is already installed."
return 0
else
info "[Package]" "Installing missing package: ${package}"
# Handle PHP versioned packages with fallback
if [[ "$package" =~ ^php[0-9]+\.[0-9]+- ]] || [[ "$package" =~ ^libapache2-mod-php[0-9]+\.[0-9]+$ ]]; then
local pkg_generic
pkg_generic=$(echo "$package" | sed -E "s/[0-9]+\.[0-9]+-/-/; s/[0-9]+\.[0-9]+$//")
if apt-get -qq install -y "$package" >/dev/null 2>&1; then
info "Package installation" "Successfully installed ${package}."
return 0
else
warn "Package ${package} not available, falling back to ${pkg_generic}..."
if apt-get -qq install -y "$pkg_generic" >/dev/null 2>&1; then
info "Package installation" "Successfully installed ${pkg_generic}."
return 0
else
error "Failed to install ${package} and fallback ${pkg_generic}."
return 1
fi
fi
else
# Regular package install
if apt-get -qq install -y "$package" >/dev/null 2>&1; then
info "Package installation" "Successfully installed ${package}."
return 0
else
# Special case: ignore failure on software-properties-common, unavailable on Debian Trixie
if [[ "$package" == "software-properties-common" ]]; then
warn "Ignoring failed install of ${package}."
return 0
fi
warn "Failed to install ${package}."
return 1
fi
fi
fi
}
function install_packages() {
local packages=("$@")
for package in "${packages[@]}"; do
if ! install_package "$package"; then
error "Aborting package installation due to failure: ${package}."
return 1
fi
done
return 0
}
function remove_package() {
local package=$1
if dpkg-query -W -f='${Status}' "$package" 2>/dev/null | grep -q "ok installed"; then
info "Package uninstall" "Removing package: ${package}"
if apt-get -qq remove -y "$package" >/dev/null 2>&1; then
info "Package uninstall" "Successfully removed ${package}."
return 0
else
error "Failed to remove ${package}."
return 1
fi
else
info "Package uninstall" "${package} is not installed."
return 0
fi
}
function remove_packages() {
local packages=("$@")
for package in "${packages[@]}"; do
if ! remove_package "$package"; then
error "Aborting package removal due to failure: ${package}."
return 1
fi
done
return 0
}
function test_command() {
local cmd="$1"
eval "$cmd" &>/dev/null
local status=$?
if [[ -f "test.mjpeg" ]]; then
info "go2rtc installation" "Deleting existing test.mjpeg file."
rm test.mjpeg
fi
return $status
}
function add_source_list() {
local source_entry="$1"
local source_file="$2"
if grep -Fxq "$source_entry" "$source_file" 2>/dev/null; then
info "Source list" "Source list entry already exists: $source_entry"
else
echo "$source_entry" >>"$source_file"
info "Source list" "Added source list entry: $source_entry"
fi
}
function ensure_add_apt_repository() {
if ! command -v add-apt-repository >/dev/null 2>&1; then
info "Setup" "add-apt-repository not found. Installing software-properties-common..."
if ! apt-get update -y >/dev/null 2>&1; then
error "Failed to update package lists (needed for software-properties-common)."
return 1
fi
if ! apt-get install -y --no-install-recommends software-properties-common >/dev/null 2>&1; then
error "Failed to install software-properties-common."
return 1
fi
info "Setup" "Installed software-properties-common successfully."
fi
return 0
}
function add_apt_repository_once() {
local repo="$1"
local clean_repo="${repo#ppa:}"
# Sanity check
if [[ -z "$repo" ]]; then
error "No repository provided to add_apt_repository_once"
return 1
fi
# Check if repository already exists
if grep -q "$clean_repo" /etc/apt/sources.list /etc/apt/sources.list.d/*.list 2>/dev/null; then
info "Add apt repository" "Repository '$repo' is already added."
return 0
fi
if grep -q "^deb .*$repo" /etc/apt/sources.list /etc/apt/sources.list.d/*.list 2>/dev/null; then
info "Add apt repository" "Repository '$repo' is already added."
return 0
fi
# Ensure add-apt-repository is available
if ! ensure_add_apt_repository; then
return 1
fi
# Add repository
info "Add apt repository" "Adding repository: $repo"
if add-apt-repository -y "$repo" >/dev/null 2>&1; then
info "Add apt repository" "Successfully added repository: $repo"
return 0
else
error "Failed to add repository: $repo"
return 1
fi
}
# ==================================================
# Environment detection
# ==================================================
# Photobooth Setup Wizard update
function self_update() {
local all_args=("$@")
local curr_date
curr_date="$(date +%Y%m%d%H%M%S)"
local script_name="install-photobooth.sh"
local script_remote_url="https://raw.githubusercontent.com/PhotoboothProject/photobooth/refs/heads/dev/$script_name"
local script_temp_file="/tmp/$script_name"
local script_backup_file="/tmp/${script_name}.bak_${curr_date}"
local script_abs_path
script_abs_path="$(realpath "$0")"
info "Photobooth Setup Wizard" "Checking for Photobooth Setup Wizard updates..."
if ! wget -q -O "$script_temp_file" "$script_remote_url"; then
confirm "Error" "Unable to download the latest Photobooth Setup Wizard."
return 1
fi
if ! cmp -s "$script_temp_file" "$script_abs_path"; then
confirm "Photobooth Setup Wizard" "Updated Photobooth Setup Wizard found!"
if ! whiptail --title "Photobooth Setup Wizard" \
--yesno "Update Photobooth Setup Wizard to latest version?" \
12 60; then
info "Photobooth Setup Wizard" "Skipping Photobooth Setup Wizard update."
sleep 2
return 0
fi
info "Photobooth Setup Wizard" "Updating the Photobooth Setup Wizard..."
if ! cp "$script_abs_path" "$script_backup_file"; then
confirm "Photobooth Setup Wizard" "Failed to create a backup of $script_abs_path. Update aborted."
return 1
fi
info "Photobooth Setup Wizard" "Backup created: $script_backup_file"
if mv -f "$script_temp_file" "$script_abs_path"; then
if ! chmod +x "$script_abs_path"; then
confirm "Photobooth Setup Wizard" "Failed to add execution permission to $script_abs_path. Update aborted."
return 1
fi
confirm "Photobooth Setup Wizard" "Photobooth Setup Wizard updated successfully."
info "Photobooth Setup Wizard" "Restarting Photobooth Setup Wizard..."
sleep 2
exec "$script_abs_path" "${all_args[@]}"
else
confirm "Photobooth Setup Wizard" "Failed to update Photobooth Setup Wizard!"
return 1
fi
else
info "Photobooth Setup Wizard" "No updates available."
rm -f "$script_temp_file"
fi
}
function detect_os_codename() {
local os=""
if command -v lsb_release >/dev/null 2>&1; then
os=$(lsb_release -sc 2>/dev/null)
elif [[ -r /etc/os-release ]]; then
# Try VERSION_CODENAME first
os=$(grep -E '^VERSION_CODENAME=' /etc/os-release | cut -d= -f2)
if [[ -z "$os" ]]; then
# Extract from VERSION string as fallback
os=$(grep -E '^VERSION=' /etc/os-release | sed -E 's/.*\((.*)\).*/\1/')
fi
fi
if [[ -n "$os" ]]; then
echo "$os"
fi
}
# Check if running on Raspberry Pi
function detect_pi() {
if [ "$FORCE_RASPBERRY_PI" = false ]; then
local pi_model
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
else
RUNNING_ON_PI=true
fi
fi
else
RUNNING_ON_PI=true
fi
}
function no_raspberry() {
info "WARNING" "This script is intended to run on a Raspberry Pi.\nRunning the script on other devices running Debian or a Debian-based distribution is possible, but Raspberry Pi-specific features will be missing!"
sleep 2
RUNNING_ON_PI=false
}
# Detect a single user under /home
# Prints the username if exactly one exists, returns 0
# Prints nothing and returns 1 otherwise
function detect_single_home_user() {
local user_dirs=()
for dir in /home/*; do
[[ -d "$dir" ]] && user_dirs+=("$(basename "$dir")")
done
if [[ ${#user_dirs[@]} -eq 1 ]]; then
echo "${user_dirs[0]}"
return 0
fi
return 1
}
function check_username() {
while true; do
# Try auto-detect first
if [ -z "$USERNAME" ]; then
local detected_user
detected_user=$(detect_single_home_user)
if [[ -n "$detected_user" ]]; then
USERNAME="$detected_user"
info "Setup Wizard" "Automatically detected username: $USERNAME"
fi
fi
if [ -z "$USERNAME" ] && [ "$SILENT" = false ]; then
if ! USERNAME=$(whiptail --title "Welcome to Photobooth Setup Wizard" \
--inputbox "Enter your username to proceed:" \
8 50 "$(who -m | awk '{ print $1 }')" \
--cancel-button Exit --ok-button Proof \
3>&1 1>&2 2>&3); then
if whiptail --title "Photobooth Setup Wizard" \
--yesno "Are you sure you want to exit?" \
8 50; then
exit 0
else
continue
fi
fi
fi
# Validate username
if [ -n "$USERNAME" ]; then
if id "$USERNAME" &>/dev/null; then
break
else
if [ "$SILENT" = true ]; then
confirm "Invalid Username" "Error: The username '$USERNAME' does not exist. Continuing without a defined user."
USERNAME=""
break
else
confirm "Invalid Username" "The username '$USERNAME' does not exist. Please try again."
USERNAME=""
fi
fi
else
if [ "$SILENT" = true ]; then
confirm "Setup Wizard" "Username not defined. Ignoring..."
break
else
confirm "Setup Wizard" "Username cannot be empty. Please try again."
fi
fi
done
}
function check_webserver() {
local servers=("apache2" "nginx" "lighttpd")
local installed_but_not_running=false
for server in "${servers[@]}"; do
# Check if package is installed
if dpkg-query -W -f='${Status}' "$server" 2>/dev/null | grep -q "ok installed"; then
# Check if systemctl exists and service is active
if [[ "$HAS_SYSTEMD" == true ]] && systemctl is-active --quiet "$server"; then
info "Webserver Check" "$server is installed and running."
case $server in
apache2) return 1 ;;
nginx) return 2 ;;
lighttpd) return 3 ;;
esac
else
info "Webserver Check" "$server is installed but not running (or systemctl unavailable)."
installed_but_not_running=true
fi
fi
done
if [[ "$installed_but_not_running" == true ]]; then
info "Webserver Check" "One or more webservers are installed but not running."
return 4
fi
info "Webserver Check" "No webserver is installed and running."
return 0
}
function prepare_php_environment() {
if detected_os=$(detect_os_codename) && [[ $detected_os ]]; then
OS_CODENAME="$detected_os"
info "OS Detection" "Detected distribution codename: $OS_CODENAME"
else
confirm "Warning" "Could not detect OS codename."
fi
info "PHP preparation" "Detected OS: $OS_CODENAME"
# Add PHP repository based on OS
if [[ "${DEBIAN[*]}" =~ $OS_CODENAME ]]; then
info "PHP preparation" "Adding Sury PHP repository for Debian."
wget -qO /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg >/dev/null 2>&1
echo "deb https://packages.sury.org/php/ $OS_CODENAME main" \
| tee /etc/apt/sources.list.d/php.list >/dev/null 2>&1
elif [[ "$OS_CODENAME" == "mantic" ]]; then
info "PHP preparation" "No source lists available for 'mantic'."
else
if [[ "$OS_CODENAME" == "jammy" ]]; then
info "PHP preparation" "Checking for 'jammy-updates' in sources list."
add_source_list "deb http://archive.ubuntu.com/ubuntu/ jammy-updates main restricted" /etc/apt/sources.list
fi
if ! ensure_add_apt_repository; then
error "Failed to install software-properties-common (needed for add-apt-repository)."
return 2
fi
info "PHP preparation" "Adding Ondrej PHP PPA."
if ! add_apt_repository_once "ppa:ondrej/php"; then
error "Failed to add Ondrej PHP PPA."
return 1
fi
fi
if apt-get -qq update 2>&1 | grep -q "does not have a Release file"; then
info "PPA ondrej/php is not valid for $OS_CODENAME, removing..."
add-apt-repository --remove ppa:ondrej/php
rm -f /etc/apt/sources.list.d/ondrej-ubuntu-php*.list
fi
if ! apt-get -qq update >/dev/null 2>&1; then
error "Update after adding repositories failed."
return 1
fi
info "PHP preparation" "PHP preparation completed successfully."
return 0
}
function set_php_version_cli() {
local version="$1"
if [[ -z "$version" ]]; then
error "No PHP version provided to set_php_version_cli" >&2
return 1
fi
local php_bin="/usr/bin/php${version}"
if [[ ! -x "$php_bin" ]]; then
error "$php_bin not found (is php${version} installed?)" >&2
return 1
fi
local priority
priority=$(echo "$version" | tr -d '.')
update-alternatives --install /usr/bin/php php "$php_bin" "$priority" >/dev/null 2>&1 || warn "Failed to install PHP via update-alternatives."
update-alternatives --set php "$php_bin" >/dev/null 2>&1 || error "Failed to set default PHP CLI version."
info "PHP CLI" "CLI php now points to: $(php -v | head -n1)"
return 0
}
function set_php_version_apache() {
local version="$1"
if [[ -z "$version" ]]; then
error "No PHP version provided." >&2
return 1
fi
a2dismod -f php* >/dev/null 2>&1 || true
if a2enmod "php${version}" >/dev/null 2>&1; then
confirm "Apache Webserver" "Apache is now configured to use PHP ${version} "
if [[ "$HAS_SYSTEMD" == true ]]; then
if systemctl is-active --quiet apache2; then
# Restart if already running
if ! systemctl restart apache2 &>/dev/null; then
confirm "Apache Webserver" "Failed to restart Apache Webserver. Please reboot to apply."
fi
fi
fi
return 0
else
error "Could not enable php${version} for Apache" >&2
return 1
fi
}
# ==================================================
# Change defaults for install / update
# ==================================================
function set_branch() {
local new_branch
if new_branch=$(whiptail --title "Set Git Branch" \
--inputbox "Enter the branch you want to use (e.g., dev):" 10 50 "$BRANCH" 3>&1 1>&2 2>&3); then
BRANCH="$new_branch"
info "Git Branch" "Branch set to $BRANCH"
else
info "Git Branch" "No changes made to branch."
fi
}
function set_php_version() {
local new_php_version
if new_php_version=$(whiptail --title "Set PHP Version" \
--inputbox "Enter the PHP version you want to use (e.g., 8.3):" 10 50 "$PHP_VERSION" 3>&1 1>&2 2>&3); then
PHP_VERSION="$new_php_version"
info "PHP Version" "PHP version set to $PHP_VERSION"
else
info "PHP Version" "No changes made to PHP version."
fi
}
function toggle_skip_webserver() {
if whiptail --title "Web Server Setup" \
--yesno "Current value: Skip web server setup = $SKIP_WEBSERVER\n\nToggle this option?" 10 50; then
SKIP_WEBSERVER=$([ "$SKIP_WEBSERVER" = true ] && echo false || echo true)
info "Web Server Setup" "Skip web server setup toggled to $SKIP_WEBSERVER"
else
info "Web Server Setup" "No changes made."
fi
}
function toggle_skip_php() {
if whiptail --title "PHP Setup" \
--yesno "Current value: Skip PHP setup = $SKIP_PHP\n\nToggle this option?" 10 50; then
SKIP_PHP=$([ "$SKIP_PHP" = true ] && echo false || echo true)
info "PHP Setup" "Skip PHP setup toggled to $SKIP_PHP"
else
info "PHP Setup" "No changes made."
fi
}
function toggle_skip_node() {
if whiptail --title "Node.js Setup" \
--yesno "Current value: Skip Node.js and npm setup = $SKIP_NODE\n\nToggle this option?" 10 50; then
SKIP_NODE=$([ "$SKIP_NODE" = true ] && echo false || echo true)
info "Node.js Setup" "Skip Node.js and npm setup toggled to $SKIP_NODE"
else
info "Node.js Setup" "No changes made."
fi
}
function toggle_skip_python() {
if whiptail --title "Python3 Setup" \
--yesno "Current value: Skip Python3 setup = $SKIP_PYTHON\n\nToggle this option?" 10 50; then
SKIP_PYTHON=$([ "$SKIP_PYTHON" = true ] && echo false || echo true)
info "Python3 Setup" "Skip Python3 setup toggled to $SKIP_PYTHON"
else
info "Python3 Setup" "No changes made."
fi
}
# ==================================================
#
# ==================================================
function detect_browser() {
local browser=""
if update-alternatives --query x-www-browser &>/dev/null; then
browser=$(update-alternatives --display x-www-browser \
| grep 'currently' | awk -F/ '{print $4}')
fi
case "$browser" in
chromium-browser|chromium|google-chrome|google-chrome-stable|google-chrome-beta)
WEBBROWSER="$browser"
CHROME_FLAGS=true
;;
firefox|firefox-esr)
WEBBROWSER="$browser"
CHROME_FLAGS=false
;;
*)
for b in chromium chromium-browser google-chrome google-chrome-stable google-chrome-beta firefox firefox-esr; do
if command -v "$b" >/dev/null; then
WEBBROWSER="$b"
[[ "$b" =~ chrome|chromium ]] && CHROME_FLAGS=true || CHROME_FLAGS=false
return
fi
done
WEBBROWSER="unknown"
CHROME_FLAGS=false
;;
esac
}
# Returns the kiosk flag to be used
function setup_kiosk_browser() {
local kiosk_flag="${1:---kiosk http://localhost}"
echo "$kiosk_flag"
}
# Returns the full Chrome command flags including kiosk
# Usage: setup_chrome_flags <local_env> [kiosk_flag] [chrome_default_flags]
function setup_chrome_flags() {
local local_env="${1:-default}"
local kiosk_flag="${2:-$(setup_kiosk_browser "--kiosk http://localhost")}"
local chrome_default_flags="${3:---noerrdialogs --disable-infobars --disable-features=Translate --no-first-run --check-for-update-interval=31536000 --touch-events=enabled --password-store=basic}"
local flags=""
case "$local_env" in
pi-wayland)
flags="$chrome_default_flags --ozone-platform=wayland --start-maximized"
;;
pi)
flags="$chrome_default_flags --use-gl=egl"
;;
*)
flags="$chrome_default_flags"
;;
esac
echo "$flags $kiosk_flag"
}
function browser_shortcut() {
local flags=""
local shortcut="$1"
local local_env="default"
if [[ -z "$shortcut" ]]; then
confirm "Browser Shortcut" "Error: Shortcut path is required! Cannot create shortcut!"
return 1
fi
if ! photobooth_installed; then
confirm "Browser Shortcut" "Error: Photobooth not installed!"
return 1
fi
# Ensure parent directory exists
mkdir -p "$(dirname "$shortcut")" || {
confirm "Browser Shortcut" "Error: Could not create $(dirname "$shortcut")"
return 1
}
detect_browser
if [ "$WEBBROWSER" = "unknown" ]; then
confirm "Browser Shortcut" "No browser detected. Browser shortcut cannot proceed."
return 2
fi
if [ "$CHROME_FLAGS" = true ]; then
if [ "$RUNNING_ON_PI" = true ] && is_wayland_env; then
local_env="pi-wayland"
elif [ "$RUNNING_ON_PI" = true ]; then
local_env="pi"
fi
flags="$(setup_chrome_flags "$local_env")"
else
flags="$(setup_kiosk_browser)"
fi
cat >"$shortcut" <<EOF
[Desktop Entry]
Version=1.3
Terminal=false
Type=Application
Name=Photobooth
Exec=$WEBBROWSER $flags$PHOTOBOOTH_SUBFOLDER
Icon=photobooth
StartupNotify=false
EOF
if ! chmod 644 "$shortcut"; then
confirm "Browser Shortcut" "Error: Failed to set permissions on browser shortcut!"
return 3
fi
return 0
}
function browser_desktop_shortcut() {
local shortcut="$1"
local username="$2"
if [[ -z "$shortcut" ]]; then
confirm "Desktop Shortcut" "Error: Shortcut path is required! Can not create desktop shortcut!"
return 1
fi
if [ -z "$username" ]; then
local detected_user