-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·3106 lines (3088 loc) · 164 KB
/
install.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
#!/usr/bin/env bash
# shellcheck shell=bash
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
##@Version : 202410081855-git
# @@Author : Jason Hempstead
# @@Contact : jason@casjaysdev.pro
# @@License : LICENSE.md
# @@ReadME : install.sh --help
# @@Copyright : Copyright: (c) 2024 Jason Hempstead, Casjays Developments
# @@Created : Tuesday, Oct 08, 2024 18:55 EDT
# @@File : install.sh
# @@Description : Container installer script for pihole
# @@Changelog : New script
# @@TODO : Completely rewrite/refactor/variable cleanup
# @@Other :
# @@Resource :
# @@Terminal App : no
# @@sudo/root : no
# @@Template : installers/dockermgr
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# shell check options
# shellcheck disable=SC1003
# shellcheck disable=SC2001
# shellcheck disable=SC2016
# shellcheck disable=SC2031
# shellcheck disable=SC2120
# shellcheck disable=SC2155
# shellcheck disable=SC2199
# shellcheck disable=SC2317
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
export APPNAME="pihole"
export VERSION="202410081855-git"
export REPO_BRANCH="${GIT_REPO_BRANCH:-main}"
export USER="${SUDO_USER:-$USER}"
export RUN_USER="${RUN_USER:-$USER}"
export USER_HOME="${USER_HOME:-$HOME}"
export SCRIPT_SRC_DIR="${BASH_SOURCE%/*}"
export SCRIPTS_PREFIX="dockermgr"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set bash options
trap 'retVal=$?;trap_exit' ERR EXIT SIGINT
[ "$1" = "--debug" ] && set -x && export SCRIPT_OPTS="--debug" && export _DEBUG="on"
[ "$1" = "--raw" ] && export SHOW_RAW="true"
set -o pipefail -o noglob
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Import functions
CASJAYSDEVDIR="${CASJAYSDEVDIR:-/usr/local/share/CasjaysDev/scripts}"
SCRIPTSFUNCTDIR="${CASJAYSDEVDIR:-/usr/local/share/CasjaysDev/scripts}/functions"
SCRIPTSFUNCTFILE="${SCRIPTSAPPFUNCTFILE:-mgr-installers.bash}"
SCRIPTSFUNCTURL="${SCRIPTSAPPFUNCTURL:-https://github.com/$SCRIPTS_PREFIX/installer/raw/main/functions}"
connect_test() { curl -q -ILSsf --retry 1 --max-time 2 "https://1.1.1.1" 2>&1 | grep -iq 'server:*.cloudflare' || return 1; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -f "$PWD/$SCRIPTSFUNCTFILE" ]; then
. "$PWD/$SCRIPTSFUNCTFILE"
elif [ -f "$SCRIPTSFUNCTDIR/$SCRIPTSFUNCTFILE" ]; then
. "$SCRIPTSFUNCTDIR/$SCRIPTSFUNCTFILE"
elif connect_test; then
curl -q -LSsf "$SCRIPTSFUNCTURL/$SCRIPTSFUNCTFILE" -o "/tmp/$SCRIPTSFUNCTFILE" || exit 1
. "/tmp/$SCRIPTSFUNCTFILE"
else
echo "Can not load the functions file: $SCRIPTSFUNCTDIR/$SCRIPTSFUNCTFILE" 1>&2
exit 90
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Make sure the scripts repo is installed
scripts_check
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# image tag - [docker pull DOCKER_HUB_IMAGE_URL:tag]
DOCKER_HUB_IMAGE_TAG="latest"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# docker registry settings
DOCKER_REGISTRY_URL="docker.io"
DOCKER_REGISTRY_REPO_NAME="pihole"
DOCKER_REGISTRY_USER_NAME="casjaysdevdocker"
DOCKER_REGISTRY_IMAGE_TAG="$DOCKER_HUB_IMAGE_TAG"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# URL to container image - docker pull - [URL]
DOCKER_HUB_IMAGE_URL="$DOCKER_REGISTRY_URL/$DOCKER_REGISTRY_USER_NAME/$DOCKER_REGISTRY_REPO_NAME"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SET_CONTAINER_NAME="${DOCKER_REGISTRY_USER_NAME}-${DOCKER_REGISTRY_REPO_NAME}-${DOCKER_HUB_IMAGE_TAG}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Repository variables
REPO="${DOCKERMGRREPO:-https://github.com/$SCRIPTS_PREFIX}/$APPNAME"
APPVERSION="$(__appversion "$REPO/raw/$REPO_BRANCH/version.txt")"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Defaults variables
DOCKERMGR_CONFIG_DIR="$HOME/.config/myscripts/$SCRIPTS_PREFIX"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SET_INSTDIR="$HOME/.local/share/CasjaysDev/$SCRIPTS_PREFIX/$APPNAME"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set default docker home for containers - $SET_APPDIR/$CONTAINER_NAME [APPDIR]
SET_APPDIR="/var/lib/srv/$USER/docker/$DOCKER_REGISTRY_USER_NAME/$DOCKER_REGISTRY_REPO_NAME/$DOCKER_HUB_IMAGE_TAG"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set the base data directory - mounted files live in $SET_DATADIR/$CONTAINER_NAME/rootfs [DATADIR]
SET_DATADIR="/var/lib/srv/$USER/docker/$DOCKER_REGISTRY_USER_NAME/$DOCKER_REGISTRY_REPO_NAME/$DOCKER_HUB_IMAGE_TAG"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Call the main function
dockermgr_install
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Script options IE: --help
show_optvars "$@"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# trap the cleanup function
trap_exit
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Require a certain version
dockermgr_req_version "$APPVERSION"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Custom required functions
__sudo_root() { [ "$DOCKERMGR_USER_CAN_SUDO" = "true" ] && sudo "$@" || { [ "$USER" = "root" ] && eval "$*"; } || eval "$*" 2>/dev/null || return 1; }
__sudo_exec() { [ "$DOCKERMGR_USER_CAN_SUDO" = "true" ] && sudo -HE "$@" || { [ "$USER" = "root" ] && eval "$*"; } || eval "$*" 2>/dev/null || return 1; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__rport() {
local port=""
port="$(__port)"
while :; do
{ [ $port -lt 50000 ] && [ $port -gt 50999 ]; } && port="$(__port)"
__port_in_use "$port" && break
done
echo "$port" | head -n1
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__test_public_reachable() {
local exitCode=0
local port="${1:-$(__port)}"
local nc="$(builtin type -P nc || builtin type -P netcat || false)"
if [ -n "$nc" ]; then
(timeout 20 $nc -l $port &) &>/dev/null
curl -q -LSsf -4 "https://ifconfig.co/port/$port" | jq -rc '.reachable' | grep -q 'true' || exitCode=1
else
exitCode=1
fi
return $exitCode
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# printf_space spacing color message value
__printf_space() {
local color padlength
test -n "$1" && test -z "${1//[0-9]/}" && color="$1" && shift 1 || color="7"
test -n "$1" && test -z "${1//[0-9]/}" && padlength="$1" && shift 1 || padlength="40"
printf '%b%s %s%b' "$(tput setaf "$color" 2>/dev/null)" "$1" "$2" "$(tput sgr0 2>/dev/null)"
printf '\n'
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__printf_spacing_file() { __printf_space "7" "40" "$1" "$2"; }
__printf_spacing_color() { __printf_space "$1" "40" "$2" "$3"; }
__printf_color() { printf "%b" "$(tput setaf "$1" 2>/dev/null)" "$2" "$(tput sgr0 2>/dev/null)" && printf '\n'; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__cmd_exists() { type -p $1 &>/dev/null || return 1; }
__grep_char() { grep '[a-zA-Z0-9].[a-zA-Z0-9]' | grep '^' || return 1; }
__docker_check() { [ -n "$(type -p docker 2>/dev/null)" ] || return 1; }
__remove_extra_spaces() { sed 's/\( \)*/\1/g;s|^ ||g' | sed 's/^[ \t]*//'; }
__set_vhost_alias() { echo "$1" | __remove_extra_spaces | grep "$2$" | sed "s|$2$|$3|g"; }
__docker_ps_all() { docker ps -a 2>&1 | grep -i ${1:-} "$CONTAINER_NAME" && return 0 || return 1; }
__password() { head -n1000 -c 10000 "/dev/urandom" | tr -dc '0-9a-zA-Z' | head -c${1:-16} && echo ""; }
__total_memory() { mem="$(free | grep -i 'mem: ' | awk -F ' ' '{print $2}')" && echo $((mem / 1000)); }
__docker_is_running() { ps aux 2>/dev/null | grep 'dockerd' | grep -v ' grep ' | grep -q '^' || return 1; }
__container_name() { echo "$DOCKER_REGISTRY_USER_NAME-$DOCKER_REGISTRY_REPO_NAME-$DOCKER_HUB_IMAGE_TAG" | sed 's|/|-|g' | grep '^' || return 1; }
__is_server() { echo "${SET_HOST_FULL_NAME:-$HOSTNAME}" | grep -q '^server\..*\..*[a-zA-Z0-9][a-zA-Z0-9]$' || return 1; }
__host_name() { hostname -f 2>/dev/null | grep -F '.' | grep '^' || hostname -f 2>/dev/null | grep '^' || echo "$HOSTNAME"; }
__container_is_running() { docker ps 2>&1 | grep -i "$CONTAINER_NAME" | grep -qi 'ago.* Up.* [0-9].* ' && return 0 || return 1; }
__docker_init() { [ -n "$(type -p dockermgr 2>/dev/null)" ] && dockermgr init || printf_exit "Failed to Initialize the docker installer"; }
__netstat() { netstat -taupln 2>/dev/null | grep -vE 'WAIT|ESTABLISHED|docker-pro' | awk -F ' ' '{print $4}' | sed 's|.*:||g' | grep -E '[0-9]' | sort -Vu | grep "^${1:-.*}$" || return 1; }
__retrieve_custom_env() { [ -f "$DOCKERMGR_CONFIG_DIR/env/$CONTAINER_NAME.${1:-custom}.conf" ] && cat "$DOCKERMGR_CONFIG_DIR/env/$CONTAINER_NAME.${1:-custom}.conf" | grep -Ev '^$|^#' | grep '=' | grep '^' || __custom_docker_env | grep -Ev '^$|^#' | grep '=' | grep '^' || return 1; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__get_user_id() { grep -s "^$1:" /etc/passwd | awk -F: '{print $3}' | grep '^[0-9]' || echo "$(id -u)"; }
__get_group_id() { grep -s "^$1:" /etc/group | awk -F: '{print $3}' | grep '^[0-9]' || echo "$(id -g)"; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__get_proxy_url() { echo "${1//\/*{/}" | grep -q '[0-9]:.*:[0-9]' && echo "${1%:*}" || echo "$1"; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__ping_host() { ping -c1 -i1 -w1 "${1:-$CONTAINER_HOSTNAME}" >/dev/null 2>&1 || return 1; }
__domain_name() { hostname -d 2>/dev/null | grep -vF '(none)' | grep -F '.' | grep '^' || hostname -f 2>/dev/null | sed 's/^[^.:]*[.:]//' | __grep_char || return 1; }
__get_records() { __cmd_exists dig && dig $SET_LONG_HOSTNAME 2>&1 | grep -E 'A|AAAA|CNAME' | grep -E '[0-9]\.|[0-9]:' | awk '{print $NF}' | head -n1 | grep '^' || return 1; }
__docker_gateway_ip() { sudo docker network inspect -f '{{json .IPAM.Config}}' ${HOST_DOCKER_NETWORK:-bridge} 2>/dev/null | jq -r '.[].Gateway' | grep -Ev '^$|null' | head -n1 | grep '^' || return 1; }
__docker_net_create() { __docker_net_ls | grep -q "$HOST_DOCKER_NETWORK" && return 0 || { docker network create -d bridge --attachable $HOST_DOCKER_NETWORK &>/dev/null && __docker_net_ls | grep -q "$HOST_DOCKER_NETWORK" && echo "$HOST_DOCKER_NETWORK" && return 0 || return 1; }; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__ifconfig() { [ -n "$(type -P ifconfig)" ] && eval ifconfig "$*" 2>/dev/null || return 1; }
__docker_net_ls() { docker network ls 2>&1 | grep -v 'NETWORK ID' | awk -F ' ' '{print $2}'; }
__route() { [ -n "$(type -P ip)" ] && eval ip route 2>/dev/null | grep "${1:-default}" | grep -v '^$' | head -n1 || return 1; }
__is_private_ip() { grep -E '192\.168\.[0-255]\.[0-255]|10\.[0-255]\.[0-255]\.[0-255]|172\.[10-32]|172\.[10-15]' 2>/dev/null | grep -vE '127\.[0-255]\.[0-255]\.[0-255]|172\.17'; }
__public_ip() { curl -q -LSsf ${1:--4} "http://ifconfig.co" | grep -v '^$' | head -n1 | grep '^'; }
__local_lan_ip() { __ifconfig $SET_LAN_DEV | grep -w 'inet' | awk -F ' ' '{print $2}' | __is_private_ip | head -n1 | grep '^' || ip address show $SET_LAN_DEV 2>&1 | grep 'inet ' | awk -F ' ' '{print $2}' | sed 's|/.*||g' | __is_private_ip | grep -v '^$' | head -n1 | grep '^' || echo "$CURRENT_IP_4" | grep '^' || return 1; }
__my_default_lan_address() { __ifconfig $SET_LAN_DEV | grep -w 'inet' | awk -F ' ' '{print $2}' | head -n1 | grep '^' || ip address show $SET_LAN_DEV 2>&1 | grep 'inet ' | awk -F ' ' '{print $2}' | sed 's|/.*||g' | grep -v '^$' | head -n1 | grep '^' || echo "$CURRENT_IP_4" | grep '^' || return 1; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__port() { echo "$((50000 + $RANDOM % 1000))" | grep '^' || return 1; }
__port_in_use() { { [ -d "/etc/nginx/vhosts.d" ] && grep -wRsq "${1:-443}" "/etc/nginx/vhosts.d" || __netstat | grep -q "${1:-443}"; } && return 1 || return 0; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__if_file_contains() { grep -sR "$1" "$2" | grep -Ev '#|^$' | grep -q '^' || return 1; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__enable_ssl() { { [ "$SSL_ENABLED" = "yes" ] || [ "$SSL_ENABLED" = "true" ]; } && return 0 || return 1; }
__ssl_certs() { [ -f "$HOST_SSL_CA" ] && [ -f "$HOST_SSL_CRT" ] && [ -f "$HOST_SSL_KEY" ] && return 0 || return 1; }
__check_ssl_cert() { if curl -q -viLSsf "${1:-$CONTAINER_HOSTNAME}" 2>&1 | grep -qE 'SSL certificate problem|does not match'; then return 0; else return 1; fi; }
__create_cert() { if __cmd_exists certbot && [ -f "/etc/certbot/dns.conf" ]; then certbot certonly -vvvv --agree-tos --email ssl-admin@$HOSTNAME -n --expand --dns-rfc2136 --dns-rfc2136-credentials "/etc/certbot/dns.conf" -d "$CONTAINER_HOSTNAME" -d "*.$CONTAINER_HOSTNAME" >/dev/null 2>&1 || return 2; fi; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Ensure docker is installed and running
__docker_check || __docker_init
__docker_is_running || printf_exit "Docker is not running"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__create_password() { __password "${1:-16}"; }
__create_api_key() { __password "${1:-32}"; }
__create_secret_key() { __cmd_exists openssl && openssl rand -hex ${1:-64} || __create_api_key "${1:-64}"; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# hash the password
__hash_password() { __cmd_exists htpasswd && htpasswd -bnBC 10 "" "$1" | tr -d ':\n' | sed 's/$2y/$2a/' || return 1; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Define any pre-install scripts
__run_pre_install() {
return 0
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__pre_docker_install_commands() {
return 0
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Define any post-install scripts
run_post_install() {
return 0
}
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Define any post-install scripts
run_post_custom() {
return 0
}
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__show_post_message() {
return 0
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Setup application options
setopts=$(getopt -o "i,s:,h:,d:,e:,m:,p:" --long "init,server:,host:,domain:,env:,mount:,port:" -n "$APPNAME" -- "$@" 2>/dev/null)
set -- "${setopts[@]}" 2>/dev/null
while :; do
case "$1" in #
-i | --init) ENV_INIT_SCRIPT_ONLY="yes" && shift 1 ;;
-s | --server) CONTAINER_FULL_HOST="$2" && shift 2 ;;
-h | --host) CONTAINER_OPT_HOSTNAME="$2" && shift 2 ;;
-d | --domain) CONTAINER_OPT_DOMAINNAME="$2" && shift 2 ;;
-e | --env) CONTAINER_OPT_ENV_VAR="$2 $CONTAINER_OPT_ENV_VAR" && shift 2 ;;
-m | --mount) CONTAINER_OPT_MOUNT_VAR="$2 $CONTAINER_OPT_MOUNT_VAR" && shift 2 ;;
-p | --port) CONTAINER_OPT_PORT_VAR="$2 $CONTAINER_OPT_PORT_VAR" && shift 2 ;;
--) shift 1 && break ;;
*) break ;;
esac
done
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[ -n "$(type -P sudo)" ] && sudo -n true && sudo true && DOCKERMGR_USER_CAN_SUDO="true"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set system options
SET_HOST_CORES="$({ [ -n "$(type -P getconf 2>/dev/null)" ] && getconf _NPROCESSORS_ONLN 2>/dev/null || getconf NPROCESSORS_ONLN 2>/dev/null; } || grep -shhc ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo "${NUMBER_OF_PROCESSORS:-1}")"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Setup networking
SET_LAN_DEV=$(__route | sed -e "s/^.*dev.//" -e "s/.proto.*//" | awk '{print $1}' | grep '^' || echo 'eth0')
SET_DOCKER_IP="$(__docker_gateway_ip || echo '172.17.0.1')"
SET_LAN_IP=$(__local_lan_ip || echo '127.0.0.1')
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# get variables from env
ENV_HOSTNAME="${CONTAINER_OPT_HOSTNAME:-$ENV_HOSTNAME}"
ENV_DOMAINNAME="${CONTAINER_OPT_DOMAINNAME:-$ENV_DOMAINNAME}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# get variables from host
SET_DOMAIN_NAME=$(__domain_name)
SET_SHORT_HOSTNAME=$(hostname -s 2>/dev/null | grep '^')
SET_LONG_HOSTNAME="$(hostname -f 2>/dev/null | grep -F '.' || echo "$HOSTNAME" | grep -F "$SET_SHORT_HOSTNAME." || echo "$SET_SHORT_HOSTNAME.$SET_DOMAIN_NAME")"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set hostname and domain
SET_HOST_FULL_NAME="${ENV_HOSTNAME:-$SET_LONG_HOSTNAME}"
SET_HOST_FULL_DOMAIN="${ENV_DOMAINNAME:-$SET_DOMAIN_NAME}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# SSL Setup server mounts - [/etc/ssl/CA/certs/ca.crt] [/etc/ssl/CA/certs/host.crt] [/etc/ssl/CA/certs/host.key]
HOST_SSL_CA=""
HOST_SSL_CRT=""
HOST_SSL_KEY=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# SSL Setup container mounts - [/config/ssl/ca.crt] [/config/ssl/localhost.crt] [/config/ssl/localhost.key]
CONTAINER_SSL_CA=""
CONTAINER_SSL_CRT=""
CONTAINER_SSL_KEY=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set this if the container depend on external file/app
CONTAINER_REQUIRES=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set container timezone - Default: [America/New_York]
CONTAINER_TIMEZONE=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set the working dir - [/root]
CONTAINER_WORK_DIR=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set container user and group ID - [yes/no] [id] [id]
USER_ID_ENABLED="no"
CONTAINER_USER_ID=""
CONTAINER_GROUP_ID=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set user to docker run --user [userName]
DOCKER_ADD_USER=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set group to docker run --group-add [groupName]
DOCKER_ADD_GROUP=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set runas user - default root - [mysql]
CONTAINER_USER_RUN=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Enable privileged container - [ yes/no ]
CONTAINER_PRIVILEGED_ENABLED="yes"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set the SHM Size - Default: 64M - [128M]
CONTAINER_SHM_SIZE="128M"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set the RAM Size in Megs - [1024]
CONTAINER_RAM_SIZE=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set the SWAP Size in Megs - [512]
CONTAINER_SWAP_SIZE=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set the number of cpus - [2]
CONTAINER_CPU_COUNT="2"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set - default yes - [yes/no]
CONTAINER_PROXY_SIGNAL="yes"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Restart container - [no/always/on-failure/unless-stopped]
CONTAINER_AUTO_RESTART="always"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Delete container after exit - [yes/no]
CONTAINER_AUTO_DELETE="no"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Enable tty and interactive - [yes/no]
CONTAINER_TTY_ENABLED="yes"
CONTAINER_INTERACTIVE_ENABLED="no"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# create an env file - [yes/no] [/config/.env]
CONTAINER_ENV_FILE_ENABLED="no"
CONTAINER_ENV_FILE_MOUNT=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Enable cgroups - [yes/no] [/sys/fs/cgroup]
CGROUPS_ENABLED="no"
CGROUPS_MOUNTS=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set location to resolv.conf - [yes/no] [/etc/resolv.conf]
HOST_RESOLVE_ENABLED="no"
HOST_ETC_RESOLVE_INIT_FILE=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Enable hosts /etc/hosts file - [yes/no] [/etc/hosts]
HOST_ETC_HOSTS_ENABLED="no"
HOST_ETC_HOSTS_INIT_FILE=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Mount docker socket - [yes/no] [yes/no] [/var/run/docker.sock] [/var/run/docker.sock]
DOCKER_SOCKET_ENABLED="no"
DOCKER_SOCKER_READONLY="yes"
HOST_DOCKER_SOCKET_MOUNT=""
CONTAINER_DOCKER_SOCKET_MOUNT=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Will set --env-file "$DOCKERMGR_CONFIG_DIR/env/$CONTAINER_NAME.env" to docker run [yes/no]
DOCKER_ENV_FILE_ENABLED=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Mount docker config - [yes/no] [~/.docker/config.json] [/root/.docker/config.json]
DOCKER_CONFIG_ENABLED="no"
HOST_DOCKER_CONFIG_FILE=""
CONTAINER_DOCKER_CONFIG_FILE=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Mount soundcard - [yes/no] [/dev/snd] [/dev/snd]
DOCKER_SOUND_ENABLED="no"
HOST_SOUND_DEVICE="/dev/snd"
CONTAINER_SOUND_DEVICE_FILE="/dev/snd"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Enable display in container - [yes/no] [0] [/tmp/.X11-unix] [~/.Xauthority]
CONTAINER_X11_ENABLED="no"
HOST_X11_DISPLAY=""
HOST_X11_SOCKET=""
HOST_X11_XAUTH=""
CONTAINER_X11_SOCKET="/tmp/.X11-unix"
CONTAINER_X11_XAUTH="/home/x11user/.Xauthority"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# /dev /sys /proc /lib/modules mounts
HOST_DEV_MOUNT_ENABLED="no"
HOST_SYS_MOUNT_ENABLED="no"
HOST_PROC_MOUNT_ENABLED="no"
HOST_MODULES_MOUNT_ENABLED="no"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set Container name - Default $DOCKER_REGISTRY_USER_NAME=$APPNAME-$DOCKER_HUB_IMAGE_TAG
CONTAINER_NAME=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set container hostname and domain - Default: [$APPNAME.$SET_HOST_FULL_NAME] [$SET_HOST_FULL_DOMAIN] or [hostname]
CONTAINER_HOSTNAME="pihole"
CONTAINER_DOMAINNAME="casjay.pro"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set the network type - default is bridge - [bridge/host]
HOST_DOCKER_NETWORK="bridge"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Link to an existing container - [name:alias,name]
HOST_DOCKER_LINK=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set listen type - Default all - [all/local/lan/docker/public]
HOST_NETWORK_ADDR="all"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set docker Security options [unconfined]
HOST_DOCKER_SECOPT=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set this to the protocol the the container will use - [http/https/git/ftp/postgres/mysql/mongodb]
CONTAINER_PROTOCOL="http"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set containers dns [127.0.0.1,1.1.1.1,8.8.8.8]
CONTAINER_DNS=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Setup nginx proxy variables - [yes/no] [yes/no] [http] [https] [yes/no] [ip_address]
HOST_NGINX_ENABLED="yes"
HOST_NGINX_SSL_ENABLED="yes"
HOST_NGINX_HTTP_PORT="80"
HOST_NGINX_HTTPS_PORT="443"
HOST_NGINX_UPDATE_CONF="yes"
HOST_NGINX_EXTERNAL_DOMAIN=""
HOST_NGINX_INTERNAL_DOMAIN=""
HOST_NGINX_INTERNAL_HOST=""
HOST_NGINX_LISTEN_ON_IP_ADDRESS=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set the nginx virtualhost config name - Default $CONTAINER_HOSTNAME
HOST_NGINX_VHOST_CONFIG_NAME=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Enable this if container is running a webserver - [yes/no] [internalPort] [yes/no] [yes/no] [listen]
CONTAINER_WEB_SERVER_ENABLED="yes"
CONTAINER_WEB_SERVER_INT_PORT="80"
CONTAINER_WEB_SERVER_SSL_ENABLED="no"
CONTAINER_WEB_SERVER_AUTH_ENABLED="no"
CONTAINER_WEB_SERVER_LISTEN_ON="127.0.0.10"
CONTAINER_WEB_SERVER_INT_PATH="/"
CONTAINER_WEB_SERVER_EXT_PATH="/"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set the html dir - [ENV_WWW_ROOT_DIR] [/data/www/html] [url/to/my/repo]
CONTAINER_WEB_SERVER_WWW_ENV=""
CONTAINER_WEB_SERVER_WWW_DIR=""
CONTAINER_WEB_SERVER_WWW_REPO=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Specify custom nginx vhosts - autoconfigure: [all.name/name.all/name.mydomain/name.myhost] - [virtualhost,othervhostdom]
CONTAINER_WEB_SERVER_VHOSTS="pihole.all"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Add random portmapping - [port,otherport] or [proxy|/location|port]
CONTAINER_ADD_RANDOM_PORTS=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Add custom port - [exter:inter] or [.all:exter:inter/[tcp,udp] [listen:exter:inter/[tcp,udp]] random:[inter]
CONTAINER_ADD_CUSTOM_PORT=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Create a single port mapping [listen]:[externalPort/random]:[internalPort]
CONTAINER_ADD_CUSTOM_SINGLE=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# mail settings - [yes/no] [user] [domainname] [server]
CONTAINER_EMAIL_ENABLED=""
CONTAINER_EMAIL_USER=""
CONTAINER_EMAIL_DOMAIN=""
CONTAINER_EMAIL_RELAY_SERVER=""
CONTAINER_EMAIL_RELAY_PORT="587"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Easy setup for services - [no/yes]
CONTAINER_SERVICE_PUBLIC="yes"
CONTAINER_IS_DNS_SERVER="yes"
CONTAINER_IS_DHCP_SERVER="no"
CONTAINER_IS_TFTP_SERVER="no"
CONTAINER_IS_SMTP_SERVER="no"
CONTAINER_IS_POP3_SERVER="no"
CONTAINER_IS_IMAP_SERVER="no"
CONTAINER_IS_TIME_SERVER="no"
CONTAINER_IS_NEWS_SERVER="no"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Create a database database - [name]
CONTAINER_DATABASE_CREATE=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Database settings - [listen] [yes/no]
CONTAINER_DATABASE_LISTEN=""
CONTAINER_REDIS_ENABLED="no"
CONTAINER_SQLITE_ENABLED="yes"
CONTAINER_MARIADB_ENABLED="no"
CONTAINER_MONGODB_ENABLED="no"
CONTAINER_COUCHDB_ENABLED="no"
CONTAINER_POSTGRES_ENABLED="no"
CONTAINER_SUPABASE_ENABLED="no"
CONTAINER_DEFAULT_DATABASE_TYPE="sqlite"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Should I set the create database variable? [name]
CONTAINER_CREATE_DATABASE_NAME=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Custom database setup - [yes/no] [db_name] [port] [/data/db/$CONTAINER_CUSTOM_DATABASE_NAME] [msql]
CONTAINER_CUSTOM_DATABASE_ENABLED=""
CONTAINER_CUSTOM_DATABASE_NAME=""
CONTAINER_CUSTOM_DATABASE_PORT=""
CONTAINER_CUSTOM_DATABASE_DIR=""
CONTAINER_CUSTOM_DATABASE_PROTOCOL=""
CONTAINER_CUSTOM_DATABASE_ADMIN_WWW_ROOT="/usr/local/share/httpd/admin/custom"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Database root user - [user] [pass/random]
CONTAINER_DATABASE_USER_ROOT=""
CONTAINER_DATABASE_PASS_ROOT=""
CONTAINER_DATABASE_LENGTH_ROOT="20"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Database non-root user - [user] [pass/random]
CONTAINER_DATABASE_USER_NORMAL=""
CONTAINER_DATABASE_PASS_NORMAL=""
CONTAINER_DATABASE_LENGTH_NORMAL="20"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set the database mount point [/app/db] [$HOST_DATA_DIR/db/custom/$CONTAINER_NAME]
CONTAINER_DATABASE_DIR=""
HOST_MOUNT_DATABASE_DIR=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set a username and password - [user] [pass/random]
CONTAINER_USER_NAME=""
CONTAINER_USER_PASS="random"
CONTAINER_PASS_LENGTH="24"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set container username and password enviroment name - [CONTAINER_ENV_USER_NAME=$CONTAINER_USER_NAME] [CONTAINER_ENV_PASS_NAME=$CONTAINER_USER_PASS]
CONTAINER_ENV_USER_NAME=""
CONTAINER_ENV_PASS_NAME="WEBPASSWORD"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# If container has an api token set it here - [ENV_NAME] [token/random]
CONTAINER_API_KEY_NAME=""
CONTAINER_API_KEY_TOKEN="random"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# If container has an secret key set it here - [ENV_NAME] [token/random]
CONTAINER_SECRET_KEY_NAME=""
CONTAINER_SECRET_KEY_TOKEN="random"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# If container has an admin password that needs to be hashed then set it here - [pass/random]
CONTAINER_USER_ADMIN_HASH_ENV=""
CONTAINER_USER_ADMIN_HASH_PASS=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Add the names of processes - [apache,mysql]
CONTAINER_SERVICES_LIST=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Mount container data dir - [yes/no] [/data]
CONTAINER_MOUNT_DATA_ENABLED="yes"
CONTAINER_MOUNT_DATA_MOUNT_DIR=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Mount container config dir - [yes/no] [/config]
CONTAINER_MOUNT_CONFIG_ENABLED="yes"
CONTAINER_MOUNT_CONFIG_MOUNT_DIR=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Define additional mounts - add HOST/ to use $DATA_DIR/rootfs - [/dir:/dir,/otherdir:/otherdir]
CONTAINER_MOUNTS=""
CONTAINER_MOUNTS+=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Define additional devices - [/dev:/dev,/otherdev:/otherdev]
CONTAINER_DEVICES=""
CONTAINER_DEVICES+=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Define additional variables - [myvar=var,myothervar=othervar]
CONTAINER_ENV=""
CONTAINER_ENV+=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set sysctl - []
CONTAINER_SYSCTL=""
CONTAINER_SYSCTL+=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# set the max log file - [0-9][k|m|g]
DOCKER_MAX_LOG_FILE="10m"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set custom capabilites - [NAME]
DOCKER_CUSTOM_CAP=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set capabilites - [yes/no]
DOCKER_CAP_SYS_TIME="yes"
DOCKER_CAP_SYS_ADMIN="yes"
DOCKER_CAP_CHOWN="yes"
DOCKER_CAP_NET_RAW="yes"
DOCKER_CAP_SYS_NICE="yes"
DOCKER_CAP_NET_ADMIN="yes"
DOCKER_CAP_SYS_MODULE="yes"
DOCKER_CAP_NET_BIND_SERVICE="yes"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Define labels - [traefik.enable=true,label=label,otherlabel=label2]
CONTAINER_LABELS=""
CONTAINER_LABELS+=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Specify container arguments - will run in container - [/path/to/script]
CONTAINER_COMMANDS=""
CONTAINER_COMMANDS+=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Define additional docker arguments - see docker run --help - [--option arg1,--option2]
DOCKER_CUSTOM_ARGUMENTS=""
DOCKER_CUSTOM_ARGUMENTS+=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Enable debugging - [yes/no] [Eex]
CONTAINER_DEBUG_ENABLED="no"
CONTAINER_DEBUG_OPTIONS=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# additional directories to create - [/config/dir1,/data/dir2]
CONTAINER_CREATE_DIRECTORY="/data/$APPNAME,/data/logs/$APPNAME,/config/$APPNAME "
CONTAINER_CREATE_DIRECTORY+=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# enable the health check - creates a cron script - [yes/no] [/health] [$CONTAINER_NGINX_PROXY_URL]
HOST_SERVER_HEALTH_CHECK_ENABLED=""
HOST_SERVER_HEALTH_CHECK_SERVER_URI=""
HOST_SERVER_HEALTH_CHECK_SERVER_NAME=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Containers default username/password
CONTAINER_DEFAULT_USERNAME=""
CONTAINER_DEFAULT_PASSWORD=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Show post install message
POST_SHOW_FINISHED_MESSAGE=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Run the script if it exists [yes/no]
DOCKERMGR_ENABLE_INSTALL_SCRIPT="yes"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Init only - This should be no [yes/no]
INIT_SCRIPT_ONLY="no"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# enable cron jobs [yes/no] [user] [command_to_execute] [[0-59] [0-23] [0-6] [1-31] [1-12] [file] or [@hourly/@daily/@monthly/@yearly]]
__setup_cron() {
HOST_CRON_ENABLED="no"
HOST_CRON_COMMAND=""
HOST_CRON_USER="root"
HOST_CRON_MIN='30'
HOST_CRON_HOUR='0'
HOST_CRON_WEEK_DAY='*'
HOST_CRON_MONTH_DAY='*'
HOST_CRON_MONTH_NAME='*'
HOST_CRON_LOG_FILE="/dev/null"
# [@hourly/@daily/@monthly/@yearly]
HOST_CRON_AT_SCHEDULE=''
# NO NEED TO CHANGE
if [ -n "$HOST_CRON_AT_SCHEDULE" ]; then
HOST_CRON_SCHEDULE="$(__trim "$HOST_CRON_AT_SCHEDULE")"
else
HOST_CRON_SCHEDULE="$(__trim "$HOST_CRON_MIN $HOST_CRON_HOUR $HOST_CRON_MONTH_DAY $HOST_CRON_MONTH_NAME $HOST_CRON_MONTH_DAY")"
fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set custom container enviroment variables - [MYVAR="VAR"]
__custom_docker_env() {
cat <<EOF | tee -p | grep -v '^$'
IPv6=true
DHCP_IPv6=true
TEMPERATUREUNIT=f
SOCKET_LISTENING=all
DNSMASQ_LISTENING=all
WEBTHEME=default-dark
VIRTUAL_HOST=${CONTAINER_HOSTNAME:-$HOSTNAME}
PROXY_LOCATION=${CONTAINER_HOSTNAME:-$HOSTNAME}
PIHOLE_DOMAIN=${CONTAINER_DOMAINNAME:-$HOSTNAME}
EOF
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set custom script - saves to /config/env/pihole.script.sh
__custom_docker_script() {
cat <<EOF | tee -p | grep -v '^$'
# Database settings
ENV_DATABASE_CREATE="${CONTAINER_DATABASE_CREATE:-}"
ENV_DATABASE_USER="${CONTAINER_DATABASE_USER_NORMAL:-}"
ENV_DATABASE_PASSWORD="${CONTAINER_DATABASE_PASS_NORMAL:-}"
ENV_DATABASE_ROOT_USER="${CONTAINER_DATABASE_USER_ROOT:-}"
ENV_DATABASE_ROOT_PASSWORD="${CONTAINER_DATABASE_PASS_ROOT:-}"
EOF
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# this function will create an env file in the containers filesystem - see CONTAINER_ENV_FILE_ENABLED
__container_import_variables() {
[ "$CONTAINER_ENV_FILE_ENABLED" = "yes" ] || return 0
local base_dir="" base_file="$1"
base_dir="$(realpath "$DATADIR")/$(dirname "$base_file")"
[ -d "$base_dir" ] || mkdir -p "$base_dir"
[ -f "$base_dir/$base_file" ] && return
cat <<EOF | __remove_extra_spaces | tee -p "$base_dir/$base_file" &>/dev/null
EOF
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__dockermgr_variables() {
[ -d "$DOCKERMGR_CONFIG_DIR/env" ] || mkdir -p "$DOCKERMGR_CONFIG_DIR/env"
cat <<EOF | tee -p | tr '|' '\n' | __remove_extra_spaces
# Enviroment variables for $CONTAINER_NAME
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ENV_CONTAINER_NAME="\${ENV_CONTAINER_NAME:-${CONTAINER_NAME:-$APPNAME}}"
ENV_DOCKER_HUB_IMAGE_TAG="\${ENV_DOCKER_HUB_IMAGE_TAG:-$DOCKER_HUB_IMAGE_TAG}"
ENV_DOCKER_REGISTRY_URL="\${ENV_DOCKER_REGISTRY_URL:-$DOCKER_REGISTRY_URL}"
ENV_DOCKER_REGISTRY_REPO_NAME="\${ENV_DOCKER_REGISTRY_REPO_NAME:-$DOCKER_REGISTRY_REPO_NAME}"
ENV_DOCKER_REGISTRY_USER_NAME="\${ENV_DOCKER_REGISTRY_USER_NAME:-$DOCKER_REGISTRY_USER_NAME}"
ENV_DOCKER_REGISTRY_IMAGE_TAG="\${ENV_DOCKER_REGISTRY_IMAGE_TAG:-$DOCKER_REGISTRY_IMAGE_TAG}"
ENV_DOCKER_HUB_IMAGE_URL="\${ENV_DOCKER_HUB_IMAGE_URL:-$DOCKER_HUB_IMAGE_URL}"
ENV_SET_CONTAINER_NAME="\${ENV_SET_CONTAINER_NAME:-$SET_CONTAINER_NAME}"
ENV_REPO="\${ENV_REPO:-$REPO}"
ENV_APPVERSION="\${ENV_APPVERSION:-$APPVERSION}"
ENV_DOCKERMGR_CONFIG_DIR="\${ENV_DOCKERMGR_CONFIG_DIR:-$DOCKERMGR_CONFIG_DIR}"
ENV_SET_INSTDIR="\${ENV_SET_INSTDIR:-$SET_INSTDIR}"
ENV_SET_APPDIR="\${ENV_SET_APPDIR:-$SET_APPDIR}"
ENV_SET_DATADIR="\${ENV_SET_DATADIR:-$SET_DATADIR}"
ENV_SETOPTS="\${ENV_SETOPTS:-$SETOPTS}"
ENV_SET_HOST_CORES="\${ENV_SET_HOST_CORES:-$SET_HOST_CORES}"
ENV_SET_LAN_DEV="\${ENV_SET_LAN_DEV:-$SET_LAN_DEV}"
ENV_SET_DOCKER_IP="\${ENV_SET_DOCKER_IP:-$SET_DOCKER_IP}"
ENV_SET_LAN_IP="\${ENV_SET_LAN_IP:-$SET_LAN_IP}"
ENV_ENV_HOSTNAME="\${ENV_ENV_HOSTNAME:-$ENV_HOSTNAME}"
ENV_ENV_DOMAINNAME="\${ENV_ENV_DOMAINNAME:-$ENV_DOMAINNAME}"
ENV_SET_DOMAIN_NAME="\${ENV_SET_DOMAIN_NAME:-$SET_DOMAIN_NAME}"
ENV_SET_SHORT_HOSTNAME="\${ENV_SET_SHORT_HOSTNAME:-$SET_SHORT_HOSTNAME}"
ENV_SET_LONG_HOSTNAME="\${ENV_SET_LONG_HOSTNAME:-$SET_LONG_HOSTNAME}"
ENV_SET_HOST_FULL_NAME="\${ENV_SET_HOST_FULL_NAME:-$SET_HOST_FULL_NAME}"
ENV_SET_HOST_FULL_DOMAIN="\${ENV_SET_HOST_FULL_DOMAIN:-$SET_HOST_FULL_DOMAIN}"
ENV_HOST_SSL_CA="\${ENV_HOST_SSL_CA:-$HOST_SSL_CA}"
ENV_HOST_SSL_CRT="\${ENV_HOST_SSL_CRT:-$HOST_SSL_CRT}"
ENV_HOST_SSL_KEY="\${ENV_HOST_SSL_KEY:-$HOST_SSL_KEY}"
ENV_CONTAINER_SSL_CA="\${ENV_CONTAINER_SSL_CA:-$CONTAINER_SSL_CA}"
ENV_CONTAINER_SSL_CRT="\${ENV_CONTAINER_SSL_CRT:-$CONTAINER_SSL_CRT}"
ENV_CONTAINER_SSL_KEY="\${ENV_CONTAINER_SSL_KEY:-$CONTAINER_SSL_KEY}"
ENV_CONTAINER_REQUIRES="\${ENV_CONTAINER_REQUIRES:-$CONTAINER_REQUIRES}"
ENV_CONTAINER_TIMEZONE="\${ENV_CONTAINER_TIMEZONE:-$CONTAINER_TIMEZONE}"
ENV_CONTAINER_WORK_DIR="\${ENV_CONTAINER_WORK_DIR:-$CONTAINER_WORK_DIR}"
ENV_USER_ID_ENABLED="\${ENV_USER_ID_ENABLED:-$USER_ID_ENABLED}"
ENV_CONTAINER_USER_ID="\${ENV_CONTAINER_USER_ID:-$CONTAINER_USER_ID}"
ENV_CONTAINER_GROUP_ID="\${ENV_CONTAINER_GROUP_ID:-$CONTAINER_GROUP_ID}"
ENV_DOCKER_ADD_USER="\${ENV_DOCKER_ADD_USER:-$DOCKER_ADD_USER}}"
ENV_DOCKER_ADD_GROUP="\${ENV_DOCKER_ADD_GROUP:-$DOCKER_ADD_GROUP}}"
ENV_CONTAINER_USER_RUN="\${ENV_CONTAINER_USER_RUN:-$CONTAINER_USER_RUN}"
ENV_CONTAINER_PRIVILEGED_ENABLED="\${ENV_CONTAINER_PRIVILEGED_ENABLED:-$CONTAINER_PRIVILEGED_ENABLED}"
ENV_CONTAINER_SHM_SIZE="\${ENV_CONTAINER_SHM_SIZE:-$CONTAINER_SHM_SIZE}"
ENV_CONTAINER_RAM_SIZE="\${ENV_CONTAINER_RAM_SIZE:-$CONTAINER_RAM_SIZE}"
ENV_CONTAINER_SWAP_SIZE="\${ENV_CONTAINER_SWAP_SIZE:-$CONTAINER_SWAP_SIZE}"
ENV_CONTAINER_CPU_COUNT="\${ENV_CONTAINER_CPU_COUNT:-$CONTAINER_CPU_COUNT}"
ENV_CONTAINER_PROXY_SIGNAL="\${ENV_CONTAINER_PROXY_SIGNAL:-$CONTAINER_PROXY_SIGNAL}"
ENV_CONTAINER_AUTO_RESTART="\${ENV_CONTAINER_AUTO_RESTART:-$CONTAINER_AUTO_RESTART}"
ENV_CONTAINER_AUTO_DELETE="\${ENV_CONTAINER_AUTO_DELETE:-$CONTAINER_AUTO_DELETE}"
ENV_CONTAINER_TTY_ENABLED="\${ENV_CONTAINER_TTY_ENABLED:-$CONTAINER_TTY_ENABLED}"
ENV_CONTAINER_INTERACTIVE_ENABLED="\${ENV_CONTAINER_INTERACTIVE_ENABLED:-$CONTAINER_INTERACTIVE_ENABLED}"
ENV_CONTAINER_ENV_FILE_ENABLED="\${ENV_CONTAINER_ENV_FILE_ENABLED:-$CONTAINER_ENV_FILE_ENABLED}"
ENV_CONTAINER_ENV_FILE_MOUNT="\${ENV_CONTAINER_ENV_FILE_MOUNT:-$CONTAINER_ENV_FILE_MOUNT}"
ENV_CGROUPS_ENABLED="\${ENV_CGROUPS_ENABLED:-$CGROUPS_ENABLED}"
ENV_CGROUPS_MOUNTS="\${ENV_CGROUPS_MOUNTS:-$CGROUPS_MOUNTS}"
ENV_HOST_RESOLVE_ENABLED="\${ENV_HOST_RESOLVE_ENABLED:-$HOST_RESOLVE_ENABLED}"
ENV_HOST_ETC_RESOLVE_INIT_FILE="\${ENV_HOST_ETC_RESOLVE_INIT_FILE:-$HOST_ETC_RESOLVE_INIT_FILE}"
ENV_HOST_ETC_HOSTS_ENABLED="\${ENV_HOST_ETC_HOSTS_ENABLED:-$HOST_ETC_HOSTS_ENABLED}"
ENV_HOST_ETC_HOSTS_INIT_FILE="\${ENV_HOST_ETC_HOSTS_INIT_FILE:-$HOST_ETC_HOSTS_INIT_FILE}"
ENV_DOCKER_SOCKET_ENABLED="\${ENV_DOCKER_SOCKET_ENABLED:-$DOCKER_SOCKET_ENABLED}"
ENV_DOCKER_SOCKER_READONLY="\${ENV_DOCKER_SOCKER_READONLY:-$DOCKER_SOCKER_READONLY}"
ENV_HOST_DOCKER_SOCKET_MOUNT="\${ENV_HOST_DOCKER_SOCKET_MOUNT:-$HOST_DOCKER_SOCKET_MOUNT}"
ENV_CONTAINER_DOCKER_SOCKET_MOUNT="\${ENV_CONTAINER_DOCKER_SOCKET_MOUNT:-$CONTAINER_DOCKER_SOCKET_MOUNT}"
ENV_DOCKER_ENV_FILE_ENABLED="\${ENV_DOCKER_ENV_FILE_ENABLED:-$DOCKER_ENV_FILE_ENABLED}"
ENV_DOCKER_CONFIG_ENABLED="\${ENV_DOCKER_CONFIG_ENABLED:-$DOCKER_CONFIG_ENABLED}"
ENV_HOST_DOCKER_CONFIG="\${ENV_HOST_DOCKER_CONFIG:-$HOST_DOCKER_CONFIG_FILE}"
ENV_CONTAINER_DOCKER_CONFIG_FILE="\${ENV_CONTAINER_DOCKER_CONFIG_FILE:-$CONTAINER_DOCKER_CONFIG_FILE}"
ENV_DOCKER_SOUND_ENABLED="\${ENV_DOCKER_SOUND_ENABLED:-$DOCKER_SOUND_ENABLED}"
ENV_HOST_SOUND_DEVICE="\${ENV_HOST_SOUND_DEVICE:-$HOST_SOUND_DEVICE}"
ENV_CONTAINER_SOUND_DEVICE_FILE="\${ENV_CONTAINER_SOUND_DEVICE_FILE:-$CONTAINER_SOUND_DEVICE_FILE}"
ENV_CONTAINER_X11_ENABLED="\${ENV_CONTAINER_X11_ENABLED:-$CONTAINER_X11_ENABLED}"
ENV_HOST_X11_DISPLAY="\${ENV_HOST_X11_DISPLAY:-$HOST_X11_DISPLAY}"
ENV_HOST_X11_SOCKET="\${ENV_HOST_X11_SOCKET:-$HOST_X11_SOCKET}"
ENV_HOST_X11_XAUTH="\${ENV_HOST_X11_XAUTH:-$HOST_X11_XAUTH}"
ENV_CONTAINER_X11_SOCKET="\${ENV_CONTAINER_X11_SOCKET:-$CONTAINER_X11_SOCKET}"
ENV_CONTAINER_X11_XAUTH="\${ENV_CONTAINER_X11_XAUTH:-$CONTAINER_X11_XAUTH}"
ENV_HOST_DEV_MOUNT_ENABLED="\${ENV_HOST_DEV_MOUNT_ENABLED:-$HOST_DEV_MOUNT_ENABLED}"
ENV_HOST_SYS_MOUNT_ENABLED="\${ENV_HOST_SYS_MOUNT_ENABLED:-$HOST_SYS_MOUNT_ENABLED}"
ENV_HOST_PROC_MOUNT_ENABLED="\${ENV_HOST_PROC_MOUNT_ENABLED:-$HOST_PROC_MOUNT_ENABLED}"
ENV_HOST_MODULES_MOUNT_ENABLED="\${ENV_HOST_MODULES_MOUNT_ENABLED:-$HOST_MODULES_MOUNT_ENABLED}"
ENV_CONTAINER_HOSTNAME="\${ENV_CONTAINER_HOSTNAME:-$CONTAINER_HOSTNAME}"
ENV_CONTAINER_DOMAINNAME="\${ENV_CONTAINER_DOMAINNAME:-$CONTAINER_DOMAINNAME}"
ENV_HOST_DOCKER_NETWORK="\${ENV_HOST_DOCKER_NETWORK:-$HOST_DOCKER_NETWORK}"
ENV_HOST_DOCKER_LINK="\${ENV_HOST_DOCKER_LINK:-$HOST_DOCKER_LINK}"
ENV_HOST_NETWORK_ADDR="\${ENV_HOST_NETWORK_ADDR:-$HOST_NETWORK_ADDR}"
ENV_HOST_DOCKER_SECOPT="\${ENV_HOST_DOCKER_SECOPT:-$HOST_DOCKER_SECOPT}"
ENV_CONTAINER_PROTOCOL="\${ENV_CONTAINER_PROTOCOL:-$CONTAINER_PROTOCOL}"
ENV_CONTAINER_DNS="\${ENV_CONTAINER_DNS:-$CONTAINER_DNS}"
ENV_HOST_NGINX_ENABLED="\${ENV_HOST_NGINX_ENABLED:-$HOST_NGINX_ENABLED}"
ENV_HOST_NGINX_SSL_ENABLED="\${ENV_HOST_NGINX_SSL_ENABLED:-$HOST_NGINX_SSL_ENABLED}"
ENV_HOST_NGINX_HTTP_PORT="\${ENV_HOST_NGINX_HTTP_PORT:-$HOST_NGINX_HTTP_PORT}"
ENV_HOST_NGINX_HTTPS_PORT="\${ENV_HOST_NGINX_HTTPS_PORT:-$HOST_NGINX_HTTPS_PORT}"
ENV_HOST_NGINX_UPDATE_CONF="\${ENV_HOST_NGINX_UPDATE_CONF:-$HOST_NGINX_UPDATE_CONF}"
ENV_HOST_NGINX_EXTERNAL_DOMAIN="\${ENV_HOST_NGINX_EXTERNAL_DOMAIN:-$HOST_NGINX_EXTERNAL_DOMAIN}"
ENV_HOST_NGINX_INTERNAL_DOMAIN="\${ENV_HOST_NGINX_INTERNAL_DOMAIN:-$HOST_NGINX_INTERNAL_DOMAIN}"
ENV_HOST_NGINX_INTERNAL_HOST="\${ENV_HOST_NGINX_INTERNAL_HOST:-$HOST_NGINX_INTERNAL_HOST}"
ENV_HOST_NGINX_LISTEN_ON_IP_ADDRESS="\${ENV_HOST_NGINX_LISTEN_ON_IP_ADDRESS:-$HOST_NGINX_LISTEN_ON_IP_ADDRESS}"
ENV_HOST_NGINX_VHOST_CONFIG_NAME="\${ENV_HOST_NGINX_VHOST_CONFIG_NAME:-$HOST_NGINX_VHOST_CONFIG_NAME}"
ENV_CONTAINER_WEB_SERVER_ENABLED="\${ENV_CONTAINER_WEB_SERVER_ENABLED:-$CONTAINER_WEB_SERVER_ENABLED}"
ENV_CONTAINER_WEB_SERVER_INT_PORT="\${ENV_CONTAINER_WEB_SERVER_INT_PORT:-$CONTAINER_WEB_SERVER_INT_PORT}"
ENV_CONTAINER_WEB_SERVER_SSL_ENABLED="\${ENV_CONTAINER_WEB_SERVER_SSL_ENABLED:-$CONTAINER_WEB_SERVER_SSL_ENABLED}"
ENV_CONTAINER_WEB_SERVER_AUTH_ENABLED="\${ENV_CONTAINER_WEB_SERVER_AUTH_ENABLED:-$CONTAINER_WEB_SERVER_AUTH_ENABLED}"
ENV_CONTAINER_WEB_SERVER_LISTEN_ON="\${ENV_CONTAINER_WEB_SERVER_LISTEN_ON:-$CONTAINER_WEB_SERVER_LISTEN_ON}"
ENV_CONTAINER_WEB_SERVER_INT_PATH="\${ENV_CONTAINER_WEB_SERVER_INT_PATH:-$CONTAINER_WEB_SERVER_INT_PATH}"
ENV_CONTAINER_WEB_SERVER_EXT_PATH="\${ENV_CONTAINER_WEB_SERVER_EXT_PATH:-$CONTAINER_WEB_SERVER_EXT_PATH}"
ENV_CONTAINER_WEB_SERVER_WWW_ENV="\${ENV_CONTAINER_WEB_SERVER_WWW_ENV:-$CONTAINER_WEB_SERVER_WWW_ENV}"
ENV_CONTAINER_WEB_SERVER_WWW_DIR="\${ENV_CONTAINER_WEB_SERVER_WWW_DIR:-$CONTAINER_WEB_SERVER_WWW_DIR}"
ENV_CONTAINER_WEB_SERVER_WWW_REPO="\${ENV_CONTAINER_WEB_SERVER_WWW_REPO:-$CONTAINER_WEB_SERVER_WWW_REPO}"
ENV_CONTAINER_WEB_SERVER_VHOSTS="\${ENV_CONTAINER_WEB_SERVER_VHOSTS:-$CONTAINER_WEB_SERVER_VHOSTS}"
ENV_CONTAINER_ADD_RANDOM_PORTS="\${ENV_CONTAINER_ADD_RANDOM_PORTS:-$CONTAINER_ADD_RANDOM_PORTS}"
ENV_CONTAINER_ADD_CUSTOM_PORT="\${ENV_CONTAINER_ADD_CUSTOM_PORT:-$CONTAINER_ADD_CUSTOM_PORT}"
ENV_CONTAINER_ADD_CUSTOM_SINGLE="\${ENV_CONTAINER_ADD_CUSTOM_SINGLE:-$CONTAINER_ADD_CUSTOM_SINGLE}"
ENV_CONTAINER_EMAIL_ENABLED="\${ENV_CONTAINER_EMAIL_ENABLED:-$CONTAINER_EMAIL_ENABLED}"
ENV_CONTAINER_EMAIL_USER="\${ENV_CONTAINER_EMAIL_USER:-$CONTAINER_EMAIL_USER}"
ENV_CONTAINER_EMAIL_DOMAIN="\${ENV_CONTAINER_EMAIL_DOMAIN:-$CONTAINER_EMAIL_DOMAIN}"
ENV_CONTAINER_EMAIL_RELAY_SERVER="\${ENV_CONTAINER_EMAIL_RELAY_SERVER:-$CONTAINER_EMAIL_RELAY_SERVER}"
ENV_CONTAINER_EMAIL_RELAY_PORT="\${ENV_CONTAINER_EMAIL_RELAY_PORT:-$CONTAINER_EMAIL_RELAY_PORT}"
ENV_CONTAINER_SERVICE_PUBLIC="\${ENV_CONTAINER_SERVICE_PUBLIC:-$CONTAINER_SERVICE_PUBLIC}"
ENV_CONTAINER_IS_DNS_SERVER="\${ENV_CONTAINER_IS_DNS_SERVER:-$CONTAINER_IS_DNS_SERVER}"
ENV_CONTAINER_IS_DHCP_SERVER="\${ENV_CONTAINER_IS_DHCP_SERVER:-$CONTAINER_IS_DHCP_SERVER}"
ENV_CONTAINER_IS_TFTP_SERVER="\${ENV_CONTAINER_IS_TFTP_SERVER:-$CONTAINER_IS_TFTP_SERVER}"
ENV_CONTAINER_IS_SMTP_SERVER="\${ENV_CONTAINER_IS_SMTP_SERVER:-$CONTAINER_IS_SMTP_SERVER}"
ENV_CONTAINER_IS_POP3_SERVER="\${ENV_CONTAINER_IS_POP3_SERVER:-$CONTAINER_IS_POP3_SERVER}"
ENV_CONTAINER_IS_IMAP_SERVER="\${ENV_CONTAINER_IS_IMAP_SERVER:-$CONTAINER_IS_IMAP_SERVER}"
ENV_CONTAINER_IS_TIME_SERVER="\${ENV_CONTAINER_IS_TIME_SERVER:-$CONTAINER_IS_TIME_SERVER}"
ENV_CONTAINER_IS_NEWS_SERVER="\${ENV_CONTAINER_IS_NEWS_SERVER:-$CONTAINER_IS_NEWS_SERVER}"
ENV_CONTAINER_DATABASE_CREATE="\${ENV_CONTAINER_DATABASE_CREATE:-$CONTAINER_DATABASE_CREATE}"
ENV_CONTAINER_DATABASE_LISTEN="\${ENV_CONTAINER_DATABASE_LISTEN:-$CONTAINER_DATABASE_LISTEN}"
ENV_CONTAINER_REDIS_ENABLED="\${ENV_CONTAINER_REDIS_ENABLED:-$CONTAINER_REDIS_ENABLED}"
ENV_CONTAINER_SQLITE_ENABLED="\${ENV_CONTAINER_SQLITE_ENABLED:-$CONTAINER_SQLITE_ENABLED}"
ENV_CONTAINER_MARIADB_ENABLED="\${ENV_CONTAINER_MARIADB_ENABLED:-$CONTAINER_MARIADB_ENABLED}"
ENV_CONTAINER_MONGODB_ENABLED="\${ENV_CONTAINER_MONGODB_ENABLED:-$CONTAINER_MONGODB_ENABLED}"
ENV_CONTAINER_COUCHDB_ENABLED="\${ENV_CONTAINER_COUCHDB_ENABLED:-$CONTAINER_COUCHDB_ENABLED}"
ENV_CONTAINER_POSTGRES_ENABLED="\${ENV_CONTAINER_POSTGRES_ENABLED:-$CONTAINER_POSTGRES_ENABLED}"
ENV_CONTAINER_SUPABASE_ENABLED="\${ENV_CONTAINER_SUPABASE_ENABLED:-$CONTAINER_SUPABASE_ENABLED}"
ENV_CONTAINER_DEFAULT_DATABASE_TYPE="\${ENV_CONTAINER_DEFAULT_DATABASE_TYPE:-$CONTAINER_DEFAULT_DATABASE_TYPE}"
ENV_CONTAINER_CREATE_DATABASE_NAME="\${ENV_CONTAINER_CREATE_DATABASE_NAME:-$CONTAINER_CREATE_DATABASE_NAME}"
ENV_CONTAINER_CUSTOM_DATABASE_ENABLED="\${ENV_CONTAINER_CUSTOM_DATABASE_ENABLED:-$CONTAINER_CUSTOM_DATABASE_ENABLED}"
ENV_CONTAINER_CUSTOM_DATABASE_NAME="\${ENV_CONTAINER_CUSTOM_DATABASE_NAME:-$CONTAINER_CUSTOM_DATABASE_NAME}"
ENV_CONTAINER_CUSTOM_DATABASE_PORT="\${ENV_CONTAINER_CUSTOM_DATABASE_PORT:-$CONTAINER_CUSTOM_DATABASE_PORT}"
ENV_CONTAINER_CUSTOM_DATABASE_DIR="\${ENV_CONTAINER_CUSTOM_DATABASE_DIR:-$CONTAINER_CUSTOM_DATABASE_DIR}"
ENV_CONTAINER_CUSTOM_DATABASE_PROTOCOL="\${ENV_CONTAINER_CUSTOM_DATABASE_PROTOCOL:-$CONTAINER_CUSTOM_DATABASE_PROTOCOL}"
ENV_CONTAINER_CUSTOM_DATABASE_ADMIN_WWW_ROOT="\${ENV_CONTAINER_CUSTOM_DATABASE_ADMIN_WWW_ROOT:-$CONTAINER_CUSTOM_DATABASE_ADMIN_WWW_ROOT}"
ENV_CONTAINER_DATABASE_USER_ROOT="\${ENV_CONTAINER_DATABASE_USER_ROOT:-$CONTAINER_DATABASE_USER_ROOT}"
ENV_CONTAINER_DATABASE_LENGTH_ROOT="\${ENV_CONTAINER_DATABASE_LENGTH_ROOT:-$CONTAINER_DATABASE_LENGTH_ROOT}"
ENV_CONTAINER_DATABASE_USER_NORMAL="\${ENV_CONTAINER_DATABASE_USER_NORMAL:-$CONTAINER_DATABASE_USER_NORMAL}"
ENV_CONTAINER_DATABASE_LENGTH_NORMAL="\${ENV_CONTAINER_DATABASE_LENGTH_NORMAL:-$CONTAINER_DATABASE_LENGTH_NORMAL}"
ENV_CONTAINER_DATABASE_DIR="\${ENV_CONTAINER_DATABASE_DIR:-$CONTAINER_DATABASE_DIR}"
ENV_HOST_MOUNT_DATABASE_DIR="\${ENV_HOST_MOUNT_DATABASE_DIR:-$HOST_MOUNT_DATABASE_DIR}"
ENV_CONTAINER_USER_NAME="\${ENV_CONTAINER_USER_NAME:-$CONTAINER_USER_NAME}"
ENV_CONTAINER_PASS_LENGTH="\${ENV_CONTAINER_PASS_LENGTH:-$CONTAINER_PASS_LENGTH}"
ENV_CONTAINER_ENV_USER_NAME="\${ENV_CONTAINER_ENV_USER_NAME:-$CONTAINER_ENV_USER_NAME}"
ENV_CONTAINER_ENV_PASS_NAME="\${ENV_CONTAINER_ENV_PASS_NAME:-$CONTAINER_ENV_PASS_NAME}"
ENV_CONTAINER_API_KEY_NAME="\${ENV_CONTAINER_API_KEY_NAME:-$CONTAINER_API_KEY_NAME}"
ENV_CONTAINER_SECRET_KEY_NAME="\${ENV_CONTAINER_SECRET_KEY_NAME:-$CONTAINER_SECRET_KEY_NAME}"
ENV_CONTAINER_USER_ADMIN_HASH_ENV="\${ENV_CONTAINER_USER_ADMIN_HASH_ENV:-$CONTAINER_USER_ADMIN_HASH_ENV}"
ENV_CONTAINER_SERVICES_LIST="\${ENV_CONTAINER_SERVICES_LIST:-$CONTAINER_SERVICES_LIST}"
ENV_CONTAINER_MOUNT_DATA_ENABLED="\${ENV_CONTAINER_MOUNT_DATA_ENABLED:-$CONTAINER_MOUNT_DATA_ENABLED}"
ENV_CONTAINER_MOUNT_DATA_MOUNT_DIR="\${ENV_CONTAINER_MOUNT_DATA_MOUNT_DIR:-$CONTAINER_MOUNT_DATA_MOUNT_DIR}"
ENV_CONTAINER_MOUNT_CONFIG_ENABLED="\${ENV_CONTAINER_MOUNT_CONFIG_ENABLED:-$CONTAINER_MOUNT_CONFIG_ENABLED}"
ENV_CONTAINER_MOUNT_CONFIG_MOUNT_DIR="\${ENV_CONTAINER_MOUNT_CONFIG_MOUNT_DIR:-$CONTAINER_MOUNT_CONFIG_MOUNT_DIR}"
ENV_CONTAINER_MOUNTS="\${ENV_CONTAINER_MOUNTS:-$CONTAINER_MOUNTS}"
ENV_CONTAINER_DEVICES="\${ENV_CONTAINER_DEVICES:-$CONTAINER_DEVICES}"
ENV_CONTAINER_ENV="\${ENV_CONTAINER_ENV:-$CONTAINER_ENV}"
ENV_CONTAINER_SYSCTL="\${ENV_CONTAINER_SYSCTL:-$CONTAINER_SYSCTL}"
ENV_DOCKER_MAX_LOG_FILE="\${ENV_DOCKER_MAX_LOG_FILE:-$DOCKER_MAX_LOG_FILE}"
ENV_DOCKER_CUSTOM_CAP="\${ENV_DOCKER_CUSTOM_CAP:-$DOCKER_CUSTOM_CAP}"
ENV_DOCKER_CAP_SYS_TIME="\${ENV_DOCKER_CAP_SYS_TIME:-$DOCKER_CAP_SYS_TIME}"
ENV_DOCKER_CAP_SYS_ADMIN="\${ENV_DOCKER_CAP_SYS_ADMIN:-$DOCKER_CAP_SYS_ADMIN}"
ENV_DOCKER_CAP_CHOWN="\${ENV_DOCKER_CAP_CHOWN:-$DOCKER_CAP_CHOWN}"
ENV_DOCKER_CAP_NET_RAW="\${ENV_DOCKER_CAP_NET_RAW:-$DOCKER_CAP_NET_RAW}"
ENV_DOCKER_CAP_SYS_NICE="\${ENV_DOCKER_CAP_SYS_NICE:-$DOCKER_CAP_SYS_NICE}"
ENV_DOCKER_CAP_NET_ADMIN="\${ENV_DOCKER_CAP_NET_ADMIN:-$DOCKER_CAP_NET_ADMIN}"
ENV_DOCKER_CAP_SYS_MODULE="\${ENV_DOCKER_CAP_SYS_MODULE:-$DOCKER_CAP_SYS_MODULE}"
ENV_DOCKER_CAP_NET_BIND_SERVICE="\${ENV_DOCKER_CAP_NET_BIND_SERVICE:-$DOCKER_CAP_NET_BIND_SERVICE}"
ENV_CONTAINER_LABELS="\${ENV_CONTAINER_LABELS:-$CONTAINER_LABELS}"
ENV_CONTAINER_COMMANDS="\${ENV_CONTAINER_COMMANDS:-$CONTAINER_COMMANDS}"
ENV_DOCKER_CUSTOM_ARGUMENTS="\${ENV_DOCKER_CUSTOM_ARGUMENTS:-$DOCKER_CUSTOM_ARGUMENTS}"
ENV_CONTAINER_DEBUG_ENABLED="\${ENV_CONTAINER_DEBUG_ENABLED:-$CONTAINER_DEBUG_ENABLED}"
ENV_CONTAINER_DEBUG_OPTIONS="\${ENV_CONTAINER_DEBUG_OPTIONS:-$CONTAINER_DEBUG_OPTIONS}"
ENV_CONTAINER_CREATE_DIRECTORY="\${ENV_CONTAINER_CREATE_DIRECTORY:-$CONTAINER_CREATE_DIRECTORY}"
ENV_HOST_SERVER_HEALTH_CHECK_ENABLED="\${ENV_HOST_SERVER_HEALTH_CHECK_ENABLED:-$HOST_SERVER_HEALTH_CHECK_ENABLED}"
ENV_HOST_SERVER_HEALTH_CHECK_SERVER_URI="\${ENV_HOST_SERVER_HEALTH_CHECK_SERVER_URI:-$HOST_SERVER_HEALTH_CHECK_SERVER_URI}"
ENV_HOST_SERVER_HEALTH_CHECK_SERVER_NAME="\${ENV_HOST_SERVER_HEALTH_CHECK_SERVER_NAME:-$HOST_SERVER_HEALTH_CHECK_SERVER_NAME}"
ENV_CONTAINER_DEFAULT_USERNAME="\${ENV_CONTAINER_DEFAULT_USERNAME:-$CONTAINER_DEFAULT_USERNAME}"
ENV_POST_SHOW_FINISHED_MESSAGE="\${ENV_POST_SHOW_FINISHED_MESSAGE:-$POST_SHOW_FINISHED_MESSAGE}"
ENV_DOCKERMGR_ENABLE_INSTALL_SCRIPT="\${ENV_DOCKERMGR_ENABLE_INSTALL_SCRIPT:-$DOCKERMGR_ENABLE_INSTALL_SCRIPT}"
ENV_INIT_SCRIPT_ONLY="\${ENV_INIT_SCRIPT_ONLY:-$INIT_SCRIPT_ONLY}"
ENV_HOST_CRON_ENABLED="\${ENV_HOST_CRON_ENABLED:-$HOST_CRON_ENABLED}"
ENV_HOST_CRON_COMMAND="\${ENV_HOST_CRON_COMMAND:-$HOST_CRON_COMMAND}"
ENV_HOST_CRON_USER="\${ENV_HOST_CRON_USER:-$HOST_CRON_USER}"
ENV_HOST_CRON_MIN="\${ENV_HOST_CRON_MIN:-$HOST_CRON_MIN}"
ENV_HOST_CRON_HOUR="\${ENV_HOST_CRON_HOUR:-$HOST_CRON_HOUR}"
ENV_HOST_CRON_WEEK_DAY="\${ENV_HOST_CRON_WEEK_DAY:-$HOST_CRON_WEEK_DAY}"
ENV_HOST_CRON_MONTH_DAY="\${ENV_HOST_CRON_MONTH_DAY:-$HOST_CRON_MONTH_DAY}"
ENV_HOST_CRON_MONTH_NAME="\${ENV_HOST_CRON_MONTH_NAME:-$HOST_CRON_MONTH_NAME}"
ENV_HOST_CRON_LOG_FILE="\${ENV_HOST_CRON_LOG_FILE:-$HOST_CRON_LOG_FILE}"
ENV_HOST_CRON_AT_SCHEDULE="\${ENV_HOST_CRON_AT_SCHEDULE:-$HOST_CRON_AT_SCHEDULE}"
ENV_HOST_CRON_SCHEDULE="\${ENV_HOST_CRON_SCHEDULE:-$HOST_CRON_SCHEDULE}"
ENV_CONTAINER_PUBLISHED_PORT="\${ENV_CONTAINER_PUBLISHED_PORT:-$CONTAINER_PUBLISHED_PORT}"
ENV_HOST_NGINX_PROXY_URL="\${ENV_HOST_NGINX_PROXY_URL:-$HOST_NGINX_PROXY_URL}"
ENV_CONTAINER_NGINX_PROXY_URL="\${ENV_CONTAINER_NGINX_PROXY_URL:-$NGINX_PROXY_URL}"
EOF
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__dockermgr_password_variables() {
[ -d "$DOCKERMGR_CONFIG_DIR/secure" ] || mkdir -p "$DOCKERMGR_CONFIG_DIR/secure"
cat <<EOF | tee -p | tr '|' '\n' | __remove_extra_spaces
# Password Enviroment variables for $CONTAINER_NAME
ENV_CONTAINER_DATABASE_PASS_ROOT="\${ENV_CONTAINER_DATABASE_PASS_ROOT:-$CONTAINER_DATABASE_PASS_ROOT}"
ENV_CONTAINER_DATABASE_PASS_NORMAL="\${ENV_CONTAINER_DATABASE_PASS_NORMAL:-$CONTAINER_DATABASE_PASS_NORMAL}"
ENV_CONTAINER_USER_PASS="\${ENV_CONTAINER_USER_PASS:-$CONTAINER_USER_PASS}"
ENV_CONTAINER_API_KEY_TOKEN="\${ENV_CONTAINER_API_KEY_TOKEN:-$CONTAINER_API_KEY_TOKEN}"
ENV_CONTAINER_SECRET_KEY_TOKEN="\${ENV_CONTAINER_SECRET_KEY_TOKEN:-$CONTAINER_SECRET_KEY_TOKEN}"
ENV_CONTAINER_USER_ADMIN_HASH_PASS="\${ENV_CONTAINER_USER_ADMIN_HASH_PASS:-$CONTAINER_USER_ADMIN_HASH_PASS}"
ENV_CONTAINER_DEFAULT_PASSWORD="\${ENV_CONTAINER_DEFAULT_PASSWORD:-$CONTAINER_DEFAULT_PASSWORD}"
EOF
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__create_uninstall() {
NGINX_FILES="$(echo "$NGINX_CONF_FILE $NGINX_INC_CONFIG $NGINX_VHOST_CONFIG $NGINX_INTERNAL_IS_SET" | tr ' ' '\n' | grep -v '^$' | sort -u | tr '\n' ' ')"
mkdir -p "$DOCKERMGR_CONFIG_DIR/uninstall"
cat <<EOF >"$DOCKERMGR_CONFIG_DIR/uninstall/$APPNAME"
# Uninstaller for $CONTAINER_NAME
INSTDIR="$INSTDIR"
APPDIR="$APPDIR"
DATADIR="$DATADIR"
ROOTFS_DIR="$ROOTFS_DIR"
DOCKERMGR_CONFIG_DIR="$DOCKERMGR_CONFIG_DIR"
CONTAINER_NAME="$CONTAINER_NAME"
DOCKER_NAME="$CONTAINER_NAME"
DOCKER_REGISTRY_USER_NAME="$DOCKER_REGISTRY_USER_NAME"
DOCKER_REGISTRY_REPO_NAME="$DOCKER_REGISTRY_REPO_NAME"
DOCKER_REGISTRY_URL="$DOCKER_REGISTRY_URL"
ADD_REMOVE_FILES="$DOCKERMGR_CONFIG_DIR/*/$CONTAINER_NAME*"
NGINX_FILES="$(__trim "$NGINX_FILES")"
DATABASE_BASE_DIR="$LOCAL_DATA_DIR/$DATABASE_BASE_DIR"
CONTAINER_INFO="$DOCKERMGR_CONFIG_DIR/installed/$APPNAME"
EOF
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Define extra functions
__custom_docker_clean_env() { grep -Ev '^$|^#' | sed 's|^|--env |g' | grep '\--' | grep -v '\--env \\' | tr '\n' ' ' | __remove_extra_spaces; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__trim() {
local var="$*"
var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters
var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters
printf '%s' "$var" | grep -v '^$' | sort -u | __remove_extra_spaces
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__create_docker_script() {
[ -n "$EXECUTE_DOCKER_CMD" ] || return
local replace_with exec_docker_cmd create_docker_script_message_pre create_docker_script_message_post
replace_with="$DOCKER_HUB_IMAGE_URL:$DOCKER_HUB_IMAGE_TAG $CONTAINER_COMMANDS"
exec_docker_cmd="$(echo "$EXECUTE_DOCKER_CMD" | grep -v '^$' | sed 's/ --/\n --/g;s| -d| -d \\|g' | grep -v '^$' | sed '/ --/ s/$/ \\/' | grep '^')"
create_docker_script_message_pre="${create_docker_script_message_pre:-Failed to execute $EXECUTE_PRE_INSTALL}"
create_docker_script_message_post="${create_docker_script_message_post:-Failed to create $CONTAINER_NAME}"
cat <<EOF | tee -p "$DOCKERMGR_INSTALL_SCRIPT" >/dev/null
#!/usr/bin/env bash
# Install script for $CONTAINER_NAME
statusCode=0
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$EXECUTE_PRE_INSTALL
statusCode=\$?
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if [ \$statusCode -ne 0 ]; then
echo "$create_docker_script_message_pre" >&2
exit 1
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$exec_docker_cmd
$DOCKER_HUB_IMAGE_URL:$DOCKER_HUB_IMAGE_TAG $CONTAINER_COMMANDS
statusCode=\$?
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if [ \$statusCode -ne 0 ]; then
echo "$create_docker_script_message_post" >&2
exit 1
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if ! docker ps -a 2>&1 | grep -qi "$CONTAINER_NAME"; then
echo "$CONTAINER_NAME is not running" >&2
exit 1
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
exit 0
# end script
EOF
[ -f "$DOCKERMGR_INSTALL_SCRIPT" ] || return 1
sed -i 's| '$DOCKER_HUB_IMAGE_URL':'$DOCKER_HUB_IMAGE_TAG' .*\\| \\|g' "$DOCKERMGR_INSTALL_SCRIPT"
chmod -Rf 755 "$DOCKERMGR_INSTALL_SCRIPT"
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -z "$DOCKER_HUB_IMAGE_URL" ] || [ "$DOCKER_HUB_IMAGE_URL" = " " ]; then
printf_exit "Please set the url to the containers image"
elif echo "$DOCKER_HUB_IMAGE_URL" | grep -q ':'; then
DOCKER_HUB_IMAGE_URL="$(echo "$DOCKER_HUB_IMAGE_URL" | awk -F':' '{print $1}')"
DOCKER_HUB_IMAGE_TAG="${DOCKER_HUB_IMAGE_TAG:-$(echo "$DOCKER_HUB_IMAGE_URL" | awk -F':' '{print $2}')}"
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Ensure that the image has a tag
[ -n "$DOCKER_HUB_IMAGE_TAG" ] || DOCKER_HUB_IMAGE_TAG="latest"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# cleanup registry variables
DOCKER_HUB_IMAGE_TAG="${DOCKER_HUB_IMAGE_TAG//*:/}"
DOCKER_HUB_IMAGE_URL="${DOCKER_HUB_IMAGE_URL//*:\/\//}"
DOCKER_HUB_IMAGE_URL="${DOCKER_HUB_IMAGE_URL//:*/}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set containers name
CONTAINER_NAME="${CONTAINER_NAME:-$SET_CONTAINER_NAME}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Define folders
export APPDIR="$SET_APPDIR"
export DATADIR="$SET_DATADIR"
export INSTDIR="$SET_INSTDIR"
export HOST_ROOTFS_DIR="$SET_DATADIR/rootfs"
export HOST_DATA_DIR="$HOST_ROOTFS_DIR/data"
export HOST_CONFIG_DIR="$HOST_ROOTFS_DIR/config"
export LOCAL_DATA_DIR="${LOCAL_DATA_DIR:-$HOST_DATA_DIR}"
export LOCAL_CONFIG_DIR="${LOCAL_CONFIG_DIR:-$HOST_CONFIG_DIR}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# import variables from a file