Repository navigation
Expand file tree
/
Copy pathinstallarr.sh
More file actions
1711 lines (1495 loc) · 56.9 KB
/
Copy pathinstallarr.sh
File metadata and controls
1711 lines (1495 loc) · 56.9 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
#!/usr/bin/env bash
# Copyright (c) 2021-2026 community-scripts ORG
# Author: community-scripts
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/core.func)
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/tools.func)
set -eEo pipefail
color
formatting
icons
set_std_mode
SILENT_LOGFILE="/tmp/installarr-$$.log"
silent() { "$@" >>"$SILENT_LOGFILE" 2>&1; }
msg_info() { echo -e "${INFO:-[i]} ${YW}${1}${CL}"; }
msg_ok() { echo -e "${CM:-[ok]} ${GN}${1}${CL}"; }
msg_warn() { echo -e "${YW}[WARN]${CL} ${1}"; }
msg_error() { echo -e "${CROSS:-[x]} ${RD}${1}${CL}"; }
msg_step() { echo -e "${BL}==>${CL} ${1}"; }
cancelled() { msg_warn "Cancelled at $1."; exit 0; }
var_container_storage="${var_container_storage:-}"
var_template_storage="${var_template_storage:-}"
var_bridge="${var_bridge:-}"
var_gateway="${var_gateway:-}"
var_cidr="${var_cidr:-24}"
var_vlan="${var_vlan:-}"
var_start_ctid="${var_start_ctid:-}"
var_repo="${var_repo:-ProxmoxVE}"
var_qbt_password="${var_qbt_password:-}"
SUMMARY_FILE="${SUMMARY_FILE:-/root/installarr-summary.txt}"
STATE_FILE="${STATE_FILE:-/root/installarr-state.conf}"
# Helper files are fetched from this repo at the same ref as the installer,
# so a pinned installer never pairs itself with a drifted helper.
var_installarr_repo="${var_installarr_repo:-JVKeller/arr-script}"
var_installarr_ref="${var_installarr_ref:-main}"
# Read by upstream set_std_mode(): "yes" leaves STD empty so output streams.
VERBOSE="${VERBOSE:-no}"
# Governs the optional prompts. "default" leaves them at their standard
# values without asking; "advanced" collects them. Preset in the environment
# to skip the mode dialog.
INSTALL_MODE="${INSTALL_MODE:-}"
QBT_PERMANENT=0
# All five are replaced by installarr-vpn.func when the user opts into the VPN
# gateway. main() calls them unconditionally, so they must exist even when the
# module is never fetched -- otherwise declining the VPN trips `set -e`.
VPN_ENABLED=0
vpn_prompt_settings() { :; }
vpn_plan_addresses() { :; }
vpn_ensure_bridge() { :; }
vpn_configure_gateway() { :; }
vpn_summary_lines() { :; }
BACKTITLE="Proxmox VE Helper Scripts — Installarr"
TEMP_DIR=$(mktemp -d)
_on_exit() {
local rc=$?
# install_loop's progress gauge owns the whole screen and is only closed on
# the success path. Tear it down first, or every failure message below gets
# painted over and the run looks like a silent death.
exec 4>&- 2>/dev/null || true
sleep 0.5
if (( rc != 0 )); then
if (( ${#INSTALLED_SLUGS[@]} > 0 )); then orphan_report; fi
if [[ -s "$SILENT_LOGFILE" ]]; then
echo
msg_error "Last 20 lines of ${SILENT_LOGFILE}:"
tail -n 20 "$SILENT_LOGFILE"
fi
fi
rm -rf "$TEMP_DIR"
}
trap _on_exit EXIT
# `set -e` aborts silently, which makes a failure look like a clean exit.
# -E (already set above) propagates this into functions so the message names
# the actual failing line and command.
_on_err() {
local rc=$? line=$1 cmd=$2
msg_error "Aborted at line ${line} (exit ${rc}): ${cmd}"
}
trap '_on_err "$LINENO" "$BASH_COMMAND"' ERR
declare -A APP
SELECTED_ARRS=""
SELECTED_CLIENTS=""
SELECTED_MEDIA=""
EXAMPLE_INDEXER=""
ORDERED_SLUGS=()
INSTALLED_SLUGS=()
WIRING_RESULTS=()
WIRING_FAILURES=()
SYNC_CATEGORIES_SONARR='[5000,5010,5020,5030,5040,5045,5050]'
SYNC_CATEGORIES_RADARR='[2000,2010,2020,2030,2040,2045,2050,2060]'
SYNC_CATEGORIES_LIDARR='[3000,3010,3020,3030,3040]'
# The banner already shades with █ vs ▓, so those get bright and dim green to
# make the depth read as deliberate. Revealed a line at a time.
header_info() {
clear
local -a lines=(
" █ █▀▀ █▄▄ ▀▀█ ▀▀█ "
" █ ▓▀▀█ ▀▀▀█ █ █▀▀▓ ▓ ▓ █▀▀▓ ▓▀▀█ ▓▀▀█ "
" █ █ ▓ █▄▄▓ █▄▄ ▓▄▄▓ █▄▄ █▄▄ ▓▄▄▓ ▓ ▓"
)
# core.func stores its colors as the literal text \033[..m, which only renders
# via `echo -e`/%b. Embedding those in a sed replacement loses the backslash,
# so build real escape bytes here instead.
local bright dim reset
bright=$(printf '\033[1;92m')
dim=$(printf '\033[32m')
reset=$(printf '\033[m')
echo
local l
for l in "${lines[@]}"; do
if [[ -t 1 ]]; then
printf '%s%s%s\n' "$bright" "${l//▓/${dim}▓${bright}}" "$reset"
sleep 0.15
else
printf '%s\n' "$l"
fi
done
echo
}
# Runs before ensure_dependencies, so whiptail is not guaranteed to be present
# yet -- fall back to plain text rather than dying before we can install it.
welcome() {
if ! command -v whiptail >/dev/null 2>&1; then
msg_info "Installarr builds your Arr Stack as separate LXC containers and wires them together."
msg_warn "This could take a long time. Do not close this session."
return 0
fi
whiptail --backtitle "$BACKTITLE" \
--title "Welcome to Installarr" \
--msgbox "This will automate much of the build process for your personal Arr Stack as separate LXC containers and wires them together for you.\n\n\
You will be asked a handful of questions first, then it runs unattended.\n\n\
WARNING: This could take a long time depending on how many apps you pick and your download speed. Do not close this session." \
17 72 || cancelled "welcome screen"
}
check_root() {
if [[ $EUID -ne 0 ]]; then
msg_error "Run this script as root."
exit 1
fi
}
check_pve_tools() {
local missing=()
for cmd in pct pvesh pvesm pveam; do
command -v "$cmd" >/dev/null 2>&1 || missing+=("$cmd")
done
if (( ${#missing[@]} > 0 )); then
msg_error "Missing Proxmox VE tools: ${missing[*]}. Run this on a PVE node."
exit 1
fi
}
# Make sure one template is downloaded to the template storage. Upstream
# searches the storage, not the catalog, so a fresh catalog is not enough.
ensure_template() {
local tmpl=$1 file
if pveam list "$var_template_storage" 2>/dev/null | grep -q "${tmpl}_"; then
return 0
fi
file=$(pveam available --section system 2>/dev/null \
| awk -v t="${tmpl}_" '$2 ~ t {print $2; exit}')
# An untouched node has never run `pveam update`, so its catalog is empty.
if [[ -z "$file" ]]; then
msg_info "Refreshing the LXC template catalog..."
$STD pveam update || true
file=$(pveam available --section system 2>/dev/null \
| awk -v t="${tmpl}_" '$2 ~ t {print $2; exit}')
fi
if [[ -z "$file" ]]; then
msg_error "This node's catalog offers no ${tmpl} template."
msg_error "Check: pveam available --section system | grep ${tmpl%%-*}"
exit 1
fi
msg_info "Downloading ${file} (this can take a few minutes)..."
if ! $STD pveam download "$var_template_storage" "$file"; then
# Verbose mode streams to the terminal instead, leaving the log empty.
local hint=""
if [[ "$VERBOSE" != "yes" ]]; then hint=" See ${SILENT_LOGFILE} for details."; fi
msg_error "Failed to download ${file}.${hint}"
exit 1
fi
msg_ok "Template ${file} ready."
}
# Upstream writes these as var_os="${var_os:-debian}" so the value has to be
# pulled out of the parameter-expansion default. Plain var_os="debian" also works.
read_ct_var() {
local file=$1 name=$2 raw
raw=$(sed -n "s/^${name}=//p" "$file" | head -n1)
raw="${raw%\"}"
raw="${raw#\"}"
if [[ "$raw" =~ ^\$\{[A-Za-z_][A-Za-z0-9_]*:-(.+)\}$ ]]; then
raw="${BASH_REMATCH[1]}"
fi
printf '%s' "$raw"
}
# The apps do not all share an OS -- Jellyfin is Ubuntu-based while the *arrs
# are Debian -- and each upstream ct/*.sh declares what it needs via var_os and
# var_version. Read those, then make sure every template is actually on disk
# before a single container is created.
prepare_templates() {
local s script_file os ver tmpl
local -a needed=()
declare -A seen=()
msg_info "Checking LXC templates for the selected apps..."
for s in "${ORDERED_SLUGS[@]}"; do
script_file="$TEMP_DIR/${s}.sh"
if [[ ! -s "$script_file" ]]; then
$STD curl -fsSL \
"https://raw.githubusercontent.com/community-scripts/${var_repo}/main/ct/${s}.sh" \
-o "$script_file" || true
fi
if [[ ! -s "$script_file" ]]; then
msg_error "Could not download ct/${s}.sh"
exit 1
fi
os=$(read_ct_var "$script_file" var_os)
ver=$(read_ct_var "$script_file" var_version)
# A leftover $ means the line was some other shape we do not understand;
# a bad template name would fail later and much less clearly.
if [[ "$os" == *'$'* || "$ver" == *'$'* ]]; then
msg_warn "Could not parse the OS in ct/${s}.sh (got '${os}-${ver}'); skipping its template check."
continue
fi
if [[ -z "$os" || -z "$ver" ]]; then
msg_warn "Could not read the OS that ct/${s}.sh needs; skipping its template check."
continue
fi
tmpl="${os}-${ver}-standard"
if [[ -z "${seen[$tmpl]:-}" ]]; then
seen[$tmpl]=1
needed+=("$tmpl")
fi
done
local t
for t in "${needed[@]}"; do
ensure_template "$t"
done
msg_ok "Templates ready: ${needed[*]:-none required}"
}
wait_for_port() {
local ip=$1 port=$2 timeout=${3:-60} elapsed=0
while ! (echo > "/dev/tcp/${ip}/${port}") >/dev/null 2>&1; do
sleep 2
elapsed=$((elapsed + 2))
if (( elapsed >= timeout )); then return 1; fi
done
return 0
}
is_valid_ipv4() {
local ip=$1
[[ "$ip" =~ ^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$ ]] || return 1
local a=${BASH_REMATCH[1]} b=${BASH_REMATCH[2]} c=${BASH_REMATCH[3]} d=${BASH_REMATCH[4]}
(( a <= 255 && b <= 255 && c <= 255 && d <= 255 )) || return 1
return 0
}
# Blank is valid and means untagged -- upstream build.func reads an empty
# var_vlan as "no VLAN" rather than an error.
is_valid_vlan_tag() {
local tag=$1
[[ -z "$tag" ]] && return 0
[[ "$tag" =~ ^[0-9]+$ ]] || return 1
(( tag >= 1 && tag <= 4094 ))
}
form_input_program() {
if command -v dialog >/dev/null 2>&1; then
echo "dialog"
elif whiptail --help 2>&1 | grep -q -- '--form'; then
echo "whiptail"
else
echo "none"
fi
}
seed_catalog() {
while IFS='|' read -r slug script port impl apiver kind name contract; do
[[ -z "$slug" ]] && continue
APP[$slug.script]="$script"
APP[$slug.port]="$port"
APP[$slug.impl]="$impl"
APP[$slug.apiver]="$apiver"
APP[$slug.kind]="$kind"
APP[$slug.name]="$name"
APP[$slug.contract]="$contract"
done <<'EOF'
prowlarr|prowlarr.sh|9696||v1|indexer|Prowlarr|
sonarr|sonarr.sh|8989|Sonarr|v3|arr|Sonarr|SonarrSettings
radarr|radarr.sh|7878|Radarr|v3|arr|Radarr|RadarrSettings
lidarr|lidarr.sh|8686|Lidarr|v1|arr|Lidarr|LidarrSettings
bazarr|bazarr.sh|6767|Bazarr|-|arr|Bazarr|BazarrSettings
seerr|seerr.sh|5055||-|requests|Seerr|
jellyfin|jellyfin.sh|8096|Jellyfin|-|media|Jellyfin|
qbittorrent|qbittorrent.sh|8090|QBittorrent|-|client|qBittorrent|QBittorrentSettings
sabnzbd|sabnzbd.sh|7777|Sabnzbd|-|client|SABnzbd|SabnzbdSettings
gluetun|gluetun.sh|8000|||vpn|Gluetun|
EOF
}
# "default" is the flat untagged LAN most home setups run, so it asks nothing
# extra; "advanced" adds the VLAN tag prompt.
pick_install_mode() {
if [[ "$INSTALL_MODE" == "default" || "$INSTALL_MODE" == "advanced" ]]; then
msg_info "Install mode (from env): ${INSTALL_MODE}"
return 0
fi
INSTALL_MODE=$(whiptail --backtitle "$BACKTITLE" \
--title "Install Mode" \
--menu "How much do you want to be asked about the network?" 15 74 2 \
"default" "Standard settings, untagged network" \
"advanced" "Also set a VLAN tag for the containers" \
3>&1 1>&2 2>&3) || cancelled "install mode pick"
}
pick_storage() {
if [[ -n "$var_container_storage" ]]; then
msg_info "Container storage (from env): ${var_container_storage}"
else
local options=() row name type
while IFS= read -r row; do
name=$(awk '{print $1}' <<<"$row")
type=$(awk '{print $2}' <<<"$row")
[[ -z "$name" ]] && continue
options+=("$name" "$type")
done < <(pvesm status -content rootdir 2>/dev/null | awk 'NR>1')
if (( ${#options[@]} == 0 )); then
msg_error "No PVE storage with content 'rootdir' available."
exit 1
fi
if (( ${#options[@]} == 2 )); then
var_container_storage="${options[0]}"
msg_info "Container storage (only option): ${var_container_storage}"
else
var_container_storage=$(whiptail --backtitle "$BACKTITLE" \
--title "Container Storage" \
--menu "Pick a PVE storage for the container rootfs:" 20 70 10 \
"${options[@]}" 3>&1 1>&2 2>&3) || cancelled "storage pick"
fi
fi
if [[ -z "$var_template_storage" ]]; then
var_template_storage=$(pvesm status -content vztmpl 2>/dev/null \
| awk 'NR>1 && $1=="local" {print $1; exit}')
[[ -z "$var_template_storage" ]] && var_template_storage=$(pvesm status -content vztmpl 2>/dev/null \
| awk 'NR>1 {print $1; exit}')
fi
[[ -n "$var_template_storage" ]] && msg_info "Template storage: ${var_template_storage}"
}
pick_network_defaults() {
if [[ -z "$var_bridge" ]]; then
local options=() b
while IFS= read -r b; do
[[ -n "$b" ]] && options+=("$b" "")
done < <(awk '/^iface vmbr/ {print $2}' /etc/network/interfaces 2>/dev/null)
if (( ${#options[@]} == 0 )); then
options=("vmbr0" "")
fi
var_bridge=$(whiptail --backtitle "$BACKTITLE" \
--title "Network Bridge" \
--menu "Pick the Linux bridge for all containers:" 15 60 6 \
"${options[@]}" 3>&1 1>&2 2>&3) || cancelled "bridge pick"
fi
# Prefill from this node's own default route so the field usually arrives
# already correct and the user just presses OK.
local default_gw default_mask="" dev
default_gw=$(ip -4 route show default | awk '{print $3}' | head -n1)
dev=$(ip -4 route show default | awk '{print $5}' | head -n1)
if [[ -n "$dev" ]]; then
default_mask=$(ip -4 -o addr show dev "$dev" 2>/dev/null \
| awk '{print $4}' | head -n1 | cut -d/ -f2)
fi
[[ "$default_mask" =~ ^[0-9]+$ ]] || default_mask=24
# Fully specified by env: nothing to ask.
if is_valid_ipv4 "$var_gateway" \
&& [[ "$var_cidr" =~ ^[0-9]+$ ]] && (( var_cidr >= 1 && var_cidr <= 32 )); then
msg_info "Bridge ${var_bridge} | gateway ${var_gateway} | mask /${var_cidr}"
return 0
fi
local answer="${var_gateway:-$default_gw}/${var_cidr:-$default_mask}"
while true; do
answer=$(whiptail --backtitle "$BACKTITLE" \
--title "Gateway and Subnet" \
--inputbox "IPv4 gateway and mask for the containers, e.g. 10.0.0.1/24:" 10 70 \
"$answer" 3>&1 1>&2 2>&3) || cancelled "gateway prompt"
local gw="${answer%%/*}" mask="${answer##*/}"
if [[ "$answer" != */* ]] || ! is_valid_ipv4 "$gw"; then
whiptail --backtitle "$BACKTITLE" --title "Invalid" \
--msgbox "Enter an address and mask together, like 10.0.0.1/24.\n\nNot valid: ${answer}" 10 64
continue
fi
if ! [[ "$mask" =~ ^[0-9]+$ ]] || (( mask < 1 || mask > 32 )); then
whiptail --backtitle "$BACKTITLE" --title "Invalid" \
--msgbox "Mask must be an integer between 1 and 32.\n\nGot: /${mask}" 10 64
continue
fi
var_gateway="$gw"
var_cidr="$mask"
break
done
msg_info "Bridge ${var_bridge} | gateway ${var_gateway} | mask /${var_cidr}"
}
# Only asked in advanced mode. Blank stays a legitimate answer either way: an
# empty var_vlan is exactly how upstream expresses "untagged".
pick_vlan_tag() {
if [[ "$INSTALL_MODE" != "advanced" ]]; then
var_vlan=""
return 0
fi
if [[ -n "$var_vlan" ]] && is_valid_vlan_tag "$var_vlan"; then
msg_info "VLAN tag ${var_vlan} (from env)"
return 0
fi
local answer="$var_vlan"
while true; do
answer=$(whiptail --backtitle "$BACKTITLE" \
--title "VLAN Tag" \
--inputbox "VLAN tag applied to every container on ${var_bridge} (1-4094).\n\nLeave blank if ${var_bridge} is not VLAN-aware or your network is untagged." 12 72 \
"$answer" 3>&1 1>&2 2>&3) || cancelled "VLAN tag prompt"
if is_valid_vlan_tag "$answer"; then
var_vlan="$answer"
break
fi
whiptail --backtitle "$BACKTITLE" --title "Invalid" \
--msgbox "VLAN tag must be an integer between 1 and 4094, or blank for no VLAN.\n\nGot: ${answer}" 10 64
done
if [[ -n "$var_vlan" ]]; then
msg_info "VLAN tag ${var_vlan}"
else
msg_info "No VLAN tag (untagged)"
fi
}
pick_apps() {
while true; do
local choice
choice=$(whiptail --backtitle "$BACKTITLE" \
--title "Pick *arr Apps" \
--checklist "Prowlarr is always installed. Pick additional apps:" 18 70 7 \
"sonarr" "Sonarr (TV)" ON \
"radarr" "Radarr (Movies)" ON \
"lidarr" "Lidarr (Music)" OFF \
"bazarr" "Bazarr (Subtitles)" OFF \
"seerr" "Seerr (Requests)" OFF \
3>&1 1>&2 2>&3) || cancelled "*arr app pick"
SELECTED_ARRS=$(echo "$choice" | tr -d '"')
if [[ -z "$SELECTED_ARRS" ]]; then
if whiptail --backtitle "$BACKTITLE" --title "Confirm" \
--yesno "You picked no *arr apps. Only Prowlarr will be installed and there will be nothing to wire. Continue anyway?" 10 70; then
return
fi
continue
fi
return
done
}
pick_clients() {
local choice
choice=$(whiptail --backtitle "$BACKTITLE" \
--title "Pick Download Clients" \
--checklist "Optional download clients to install + wire:" 14 70 4 \
"qbittorrent" "qBittorrent (Torrents)" ON \
"sabnzbd" "SABnzbd (Usenet)" OFF \
3>&1 1>&2 2>&3) || cancelled "download client pick"
SELECTED_CLIENTS=$(echo "$choice" | tr -d '"')
}
pick_verbose() {
if whiptail --backtitle "$BACKTITLE" \
--title "Verbose Mode" \
--defaultno \
--yesno "Show full installation output?\n\nNo - progress bar only (details in ${SILENT_LOGFILE})\nYes - stream every command as it runs" 12 70; then
VERBOSE="yes"
else
VERBOSE="no"
fi
set_std_mode
}
pick_jellyfin() {
# whiptail draws its UI on stdout, so this must not be captured in a
# command substitution or the dialog is never painted to the terminal.
if whiptail --backtitle "$BACKTITLE" \
--title "Media Server" \
--yesno "Install Jellyfin (media player/server)?" 10 70; then
SELECTED_MEDIA="jellyfin"
fi
}
pick_example_indexer() {
if whiptail --backtitle "$BACKTITLE" \
--title "Example Indexer" \
--yesno "Add example public indexer to Prowlarr?\n\n⚠ WARNING: Public indexers can contain malicious content.\nIt will be DISABLED by default. You must verify and enable manually." 13 70; then
EXAMPLE_INDEXER="yes"
fi
}
_gen_password() {
local p
p=$(openssl rand -base64 18 2>/dev/null | tr -dc 'A-Za-z0-9' | cut -c1-16)
[[ -z "$p" ]] && p="ChangeMe${RANDOM}${RANDOM}"
printf '%s' "$p"
}
pick_qbittorrent_password() {
# `return` with no argument inherits the failed test's status, which under
# `set -e` kills the whole run when qBittorrent is deselected. Be explicit.
[[ " $SELECTED_CLIENTS " == *" qbittorrent "* ]] || return 0
[[ -n "$var_qbt_password" ]] && { msg_info "qBittorrent password (from env) will be used."; return; }
local choice
choice=$(whiptail --backtitle "$BACKTITLE" \
--title "qBittorrent WebUI Password" \
--menu "Set the qBittorrent admin password:" 15 70 2 \
"generate" "Auto-generate a strong random password (recommended)" \
"manual" "Enter my own password" \
3>&1 1>&2 2>&3) || cancelled "qBittorrent password pick"
if [[ "$choice" == "generate" ]]; then
var_qbt_password=$(_gen_password)
msg_info "A random qBittorrent password was generated (shown in the final summary)."
return
fi
local pw1 pw2
while true; do
pw1=$(whiptail --backtitle "$BACKTITLE" --title "qBittorrent Password" \
--passwordbox "Enter a WebUI password (min 6 chars):" 10 60 \
3>&1 1>&2 2>&3) || cancelled "qBittorrent password entry"
pw2=$(whiptail --backtitle "$BACKTITLE" --title "Confirm Password" \
--passwordbox "Re-enter the password:" 10 60 \
3>&1 1>&2 2>&3) || cancelled "qBittorrent password confirm"
if [[ "$pw1" != "$pw2" ]]; then
whiptail --backtitle "$BACKTITLE" --title "Mismatch" \
--msgbox "Passwords do not match. Try again." 8 50
continue
fi
if (( ${#pw1} < 6 )); then
whiptail --backtitle "$BACKTITLE" --title "Too short" \
--msgbox "Password must be at least 6 characters." 8 50
continue
fi
var_qbt_password="$pw1"
return
done
}
# Fetched only after the user opts in, mirroring how core.func/tools.func are
# sourced at the top of this file. installarr-vpn.sh is left on disk for the
# operator to run later -- the summary tells them to.
pick_vpn() {
local base="https://raw.githubusercontent.com/${var_installarr_repo}/${var_installarr_ref}"
if ! curl -fsSL "${base}/installarr-vpn.func" -o "$TEMP_DIR/installarr-vpn.func"; then
msg_warn "Could not fetch installarr-vpn.func; skipping the VPN gateway option."
return 0
fi
# shellcheck source=/dev/null
source "$TEMP_DIR/installarr-vpn.func"
vpn_prompt_settings
(( VPN_ENABLED )) || return 0
if curl -fsSL "${base}/installarr-vpn.sh" -o /root/installarr-vpn.sh; then
chmod +x /root/installarr-vpn.sh
msg_ok "Post-install script saved to /root/installarr-vpn.sh"
else
msg_warn "Could not fetch installarr-vpn.sh -- download it manually before finishing VPN setup."
fi
}
# Written on every run, VPN or not: a machine-readable record of what was built,
# so the stack can be extended later without re-running the installer.
write_state() {
local s
{
echo "# Written by installarr.sh on $(date '+%Y-%m-%d %H:%M:%S %Z')"
echo "LAN_BRIDGE=${var_bridge}"
echo "LAN_GW=${var_gateway}"
echo "LAN_CIDR=${var_cidr}"
echo "LAN_VLAN=${var_vlan}"
echo "VPN_ENABLED=${VPN_ENABLED}"
echo "VPN_BRIDGE=${VPN_BRIDGE:-}"
echo "VPN_GW=${VPN_GW:-}"
echo "VPN_MASK=${VPN_MASK:-}"
echo "VPN_SUBNET=${VPN_SUBNET:-}"
echo "VPN_MGMT_SUBNET=${VPN_MGMT_SUBNET:-}"
echo "GLUETUN_CTID=${APP[gluetun.ctid]:-}"
echo "GLUETUN_LAN_IP=${APP[gluetun.ip]:-}"
# slug:ctid:lan_ip:port:kind:planned_vpn_ip -- the VPN address is empty for
# anything that is not a tunnel member, and for every container when no VPN
# was configured. installarr-vpn.sh treats a non-empty one as "convert me".
printf 'CONTAINERS="'
for s in "${ORDERED_SLUGS[@]}"; do
printf '%s:%s:%s:%s:%s:%s ' "$s" "${APP[$s.ctid]:-}" "${APP[$s.ip]:-}" "${APP[$s.port]:-}" "${APP[$s.kind]:-}" "${APP[$s.vpnip]:-}"
done
echo '"'
} >"$STATE_FILE"
chmod 600 "$STATE_FILE"
msg_ok "Wrote ${STATE_FILE}"
}
compute_ordered_slugs() {
ORDERED_SLUGS=()
(( VPN_ENABLED )) && ORDERED_SLUGS+=("gluetun")
ORDERED_SLUGS+=("prowlarr")
local s
for s in $SELECTED_ARRS; do
[[ "$s" == "seerr" ]] && continue
ORDERED_SLUGS+=("$s")
done
for s in $SELECTED_CLIENTS; do
ORDERED_SLUGS+=("$s")
done
for s in $SELECTED_ARRS; do
[[ "$s" == "seerr" ]] && ORDERED_SLUGS+=("seerr")
done
[[ -n "$SELECTED_MEDIA" ]] && ORDERED_SLUGS+=("$SELECTED_MEDIA")
# A false trailing [[ ]] && would return 1 and trip `set -e` in main.
return 0
}
pick_ip_mode_and_ips() {
while true; do
local mode
mode=$(whiptail --backtitle "$BACKTITLE" \
--title "IP Entry Mode" \
--menu "How would you like to enter IP addresses?" 15 75 2 \
"list" "Enter all IPs at once (space- or comma-separated)" \
"form" "Enter each IP in a form" \
3>&1 1>&2 2>&3) || cancelled "IP entry mode pick"
case "$mode" in
list) _collect_ips_list_mode; return ;;
form)
if _collect_ips_one_by_one; then
return
fi
;;
esac
done
}
# Validation shared by every IP entry mode. check_live gates the reachability
# probe: the two form modes ping before accepting, list mode never has.
_validate_ip_set() {
local check_live=$1; shift
local -a ips=("$@")
local expected_n=${#ORDERED_SLUGS[@]}
local i ip dup
if (( ${#ips[@]} != expected_n )); then
whiptail --backtitle "$BACKTITLE" --title "Wrong count" --msgbox "Expected ${expected_n} IPs, got ${#ips[@]}. Please re-enter." 8 60
return 1
fi
for i in "${!ips[@]}"; do
ip="${ips[$i]}"
if ! is_valid_ipv4 "$ip"; then
whiptail --backtitle "$BACKTITLE" --title "Invalid" --msgbox "Entry $((i+1)) is not a valid IPv4: ${ip}" 8 60
return 1
fi
if [[ "$ip" == "$var_gateway" ]]; then
whiptail --backtitle "$BACKTITLE" --title "Invalid" --msgbox "Entry $((i+1)) collides with the gateway: ${ip}" 8 60
return 1
fi
if (( check_live )) && ping -c 1 -W 1 "$ip" >/dev/null 2>&1; then
whiptail --backtitle "$BACKTITLE" --title "IP In Use" --msgbox "Entry $((i+1)) is already in use by another device: ${ip}" 8 60
return 1
fi
done
dup=$(printf '%s
' "${ips[@]}" | sort | uniq -d | head -n1)
if [[ -n "$dup" ]]; then
whiptail --backtitle "$BACKTITLE" --title "Duplicate IP" --msgbox "IP appears more than once: ${dup}" 8 60
return 1
fi
return 0
}
# Runs whichever form UI is available and emits one IP per line. The dialog and
# whiptail forms differ only in the invocation and its fd plumbing.
# Returns 1 if the user cancelled, 2 if neither UI supports --form (the caller
# then falls back to one inputbox per container).
_run_ip_form() {
local ui expected_n=${#ORDERED_SLUGS[@]}
local -a form_fields=()
local slug
ui=$(form_input_program)
for slug in "${ORDERED_SLUGS[@]}"; do
form_fields+=("$slug" "")
done
case "$ui" in
dialog)
dialog --backtitle "$BACKTITLE" --title "Container IP Addresses" --form "Enter an IPv4 address for each container:" 22 78 0 "${form_fields[@]}" 2>&1 >/dev/tty || return 1
;;
whiptail)
whiptail --backtitle "$BACKTITLE" --title "Container IP Addresses" --separate-output --form "Enter an IPv4 address for each container:" 22 78 "$((expected_n + 4))" "${form_fields[@]}" 3>&1 1>&2 2>&3 || return 1
;;
*)
return 2
;;
esac
}
_assign_ips_in_order() {
local -a ips=("$@")
local i
for i in "${!ORDERED_SLUGS[@]}"; do
APP[${ORDERED_SLUGS[$i]}.ip]=${ips[$i]}
done
}
_collect_ips_list_mode() {
local expected_n=${#ORDERED_SLUGS[@]}
local hint="" s
for s in "${ORDERED_SLUGS[@]}"; do hint+=" ${s}"$'
'; done
while true; do
local raw
raw=$(whiptail --backtitle "$BACKTITLE" --title "Enter ${expected_n} IPv4 addresses" --inputbox "Enter ${expected_n} IPs separated by spaces or commas, in this order:"$'
'"${hint}" 22 78 "" 3>&1 1>&2 2>&3) || cancelled "IP list entry"
local normalized="${raw//,/ }"
local -a ips=()
# shellcheck disable=SC2206
ips=( $normalized )
_validate_ip_set 0 "${ips[@]}" || continue
_assign_ips_in_order "${ips[@]}"
return
done
}
_collect_ips_one_by_one() {
local raw_values rc
local -a ips=()
while true; do
rc=0
raw_values=$(_run_ip_form) || rc=$?
# No --form-capable UI: drop to the one-inputbox-per-container loop below.
(( rc == 2 )) && break
if (( rc != 0 )); then
msg_warn "IP form entry cancelled."
return 1
fi
mapfile -t ips <<< "$raw_values"
_validate_ip_set 1 "${ips[@]}" || continue
_assign_ips_in_order "${ips[@]}"
return 0
done
local slug ip running="" last_ip="" default_ip=""
for slug in "${ORDERED_SLUGS[@]}"; do
if [[ -n "$last_ip" ]]; then
local prefix="${last_ip%.*}"
local host="${last_ip##*.}"
if [[ "$host" =~ ^[0-9]+$ ]] && (( host < 254 )); then
default_ip="${prefix}.$((host + 1))"
fi
fi
while true; do
local prompt="Enter IPv4 for ${slug}:"
[[ -n "$running" ]] && prompt+=$'\n\nAlready assigned:'"$running"
ip=$(whiptail --backtitle "$BACKTITLE" \
--title "Container IP Addresses" \
--inputbox "$prompt" 16 60 "$default_ip" 3>&1 1>&2 2>&3) || { msg_warn "IP entry cancelled."; return 1; }
if ! is_valid_ipv4 "$ip"; then
whiptail --backtitle "$BACKTITLE" --title "Invalid" \
--msgbox "Not a valid IPv4: ${ip}" 8 60
continue
fi
if [[ "$ip" == "$var_gateway" ]]; then
whiptail --backtitle "$BACKTITLE" --title "Invalid" \
--msgbox "Collides with the gateway: ${ip}" 8 60
continue
fi
local dup=0 other_slug other_ip
for other_slug in "${ORDERED_SLUGS[@]}"; do
[[ "$other_slug" == "$slug" ]] && continue
other_ip="${APP[${other_slug}.ip]:-}"
[[ -n "$other_ip" && "$other_ip" == "$ip" ]] && { dup=1; break; }
done
if (( dup )); then
whiptail --backtitle "$BACKTITLE" --title "Duplicate" \
--msgbox "Already used by another container: ${ip}" 8 60
continue
fi
APP[$slug.ip]=$ip
running+=$'\n '"${slug} -> ${ip}"
last_ip=$ip
break
done
done
return 0
}
pick_ctids() {
local default_start id s
if [[ -n "$var_start_ctid" ]]; then
default_start="$var_start_ctid"
else
default_start=$(pvesh get /cluster/nextid 2>/dev/null || echo "100")
fi
[[ "$default_start" =~ ^[0-9]+$ ]] || default_start=100
# Sequential IDs, skipping ones already taken. These only prefill the prompt;
# the user is free to replace any of them with non-sequential values.
local -a defaults=()
id=$default_start
for s in "${ORDERED_SLUGS[@]}"; do
while pct status "$id" >/dev/null 2>&1; do
id=$((id + 1))
(( id > 999999 )) && { msg_error "Ran out of CTID space."; exit 1; }
done
defaults+=("$id")
id=$((id + 1))
done
local expected_n=${#ORDERED_SLUGS[@]}
local hint=""
for s in "${ORDERED_SLUGS[@]}"; do hint+=" ${s}"; done
local answer="${defaults[*]}"
while true; do
answer=$(whiptail --backtitle "$BACKTITLE" \
--title "Container IDs" \
--inputbox "Assign a CTID to each container, in this order:"$'\n\n'"${hint}" \
14 78 "$answer" 3>&1 1>&2 2>&3) || cancelled "CTID entry"
local -a ids=()
# shellcheck disable=SC2206
ids=( ${answer//,/ } )
if (( ${#ids[@]} != expected_n )); then
whiptail --backtitle "$BACKTITLE" --title "Wrong count" \
--msgbox "Expected ${expected_n} IDs, got ${#ids[@]}. Please re-enter." 8 60
continue
fi
local ok=1 i
for i in "${!ids[@]}"; do
if ! [[ "${ids[$i]}" =~ ^[0-9]+$ ]] || (( ids[i] < 100 )); then
whiptail --backtitle "$BACKTITLE" --title "Invalid" \
--msgbox "Entry $((i+1)) must be a number >= 100: ${ids[$i]}" 8 64
ok=0; break
fi
if pct status "${ids[$i]}" >/dev/null 2>&1; then
whiptail --backtitle "$BACKTITLE" --title "CTID In Use" \
--msgbox "CTID ${ids[$i]} is already in use on this node." 8 60
ok=0; break
fi
done
(( ok == 0 )) && continue
local dup
dup=$(printf '%s\n' "${ids[@]}" | sort | uniq -d | head -n1)
if [[ -n "$dup" ]]; then
whiptail --backtitle "$BACKTITLE" --title "Duplicate CTID" \
--msgbox "CTID appears more than once: ${dup}" 8 60
continue
fi
for i in "${!ORDERED_SLUGS[@]}"; do
APP[${ORDERED_SLUGS[$i]}.ctid]=${ids[$i]}
done
return 0
done
}
confirm_summary() {
local lines="" s
for s in "${ORDERED_SLUGS[@]}"; do
lines+=" $(printf '%-12s ctid=%-5s ip=%-16s port=%s' \
"$s" "${APP[$s.ctid]}" "${APP[$s.ip]}" "${APP[$s.port]}")"$'\n'
done
local body="About to create these containers and wire them together:"$'\n\n'"${lines}"$'\n'"Storage: ${var_container_storage} | Bridge: ${var_bridge} | Gateway: ${var_gateway} | Mask: /${var_cidr}${var_vlan:+ | VLAN: ${var_vlan}}"
whiptail --backtitle "$BACKTITLE" --title "Confirm" \
--yesno "$body" 22 78 || { msg_warn "User cancelled."; exit 0; }
}
orphan_report() {
if (( ${#INSTALLED_SLUGS[@]} == 0 )); then return; fi
msg_error "Containers already created (to clean up, run):"
local s
for s in "${INSTALLED_SLUGS[@]}"; do
echo " pct stop ${APP[$s.ctid]} && pct destroy ${APP[$s.ctid]} # ${s}"
done
}
# The gauge is fullscreen, so it would paint over streamed output. In verbose
# mode it is never opened and there is no fd 4 to write to.
progress() {
local pct=$1 text=$2
if [[ "$VERBOSE" == "yes" ]]; then
msg_step "$text"
else
echo -e "XXX\n${pct}\n${text}\nXXX" >&4
fi
}
install_loop() {
local total=${#ORDERED_SLUGS[@]} idx=0
local s script_file ip ctid port
# Upstream's diagnostics_check() opens a whiptail prompt when this file is
# absent. $STD swallows stderr, so that prompt paints into the log and blocks
# on a keypress nobody can see. Seed the opt-out; an existing file is kept.
mkdir -p /usr/local/community-scripts
[[ -f /usr/local/community-scripts/diagnostics ]] || echo "DIAGNOSTICS=no" > /usr/local/community-scripts/diagnostics
if [[ "$VERBOSE" != "yes" ]]; then
exec 4> >(whiptail --backtitle "$BACKTITLE" --title "Installing Containers" --gauge "Starting installation..." 10 70 0)
fi
for s in "${ORDERED_SLUGS[@]}"; do
idx=$((idx + 1))
ip="${APP[$s.ip]}"