-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·2275 lines (2262 loc) · 109 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 : 202305031641-git
# @@Author : Jason Hempstead
# @@Contact : [email protected]
# @@License : WTFPL
# @@ReadME : install.sh --help
# @@Copyright : Copyright: (c) 2023 Jason Hempstead, Casjays Developments
# @@Created : Wednesday, May 03, 2023 16:41 EDT
# @@File : install.sh
# @@Description : Container installer script for webvirtmgr
# @@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=SC2317
# shellcheck disable=SC2120
# shellcheck disable=SC2155
# shellcheck disable=SC2199
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
APPNAME="webvirtmgr"
VERSION="202305031641-git"
REPO_BRANCH="${GIT_REPO_BRANCH:-main}"
HOME="${USER_HOME:-$HOME}"
USER="${SUDO_USER:-$USER}"
RUN_USER="${SUDO_USER:-$USER}"
SCRIPT_SRC_DIR="${BASH_SOURCE%/*}"
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
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# 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
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Repository variables
REPO="${DOCKERMGRREPO:-https://github.com/$SCRIPTS_PREFIX}/webvirtmgr"
APPVERSION="$(__appversion "$REPO/raw/$REPO_BRANCH/version.txt")"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Defaults variables
APPNAME="webvirtmgr"
export INSTDIR="$HOME/.local/share/CasjaysDev/$SCRIPTS_PREFIX/webvirtmgr"
export DOCKERMGR_CONFIG_DIR="${DOCKERMGR_CONFIG_DIR:-$HOME/.config/myscripts/$SCRIPTS_PREFIX}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set the mountpoint directory
export APPDIR="$HOME/.local/share/srv/docker/webvirtmgr"
export DATADIR="$APPDIR/rootfs"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# 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; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__remove_extra_spaces() { sed 's/\( \)*/\1/g;s|^ ||g'; }
__port() { echo "$((50000 + $RANDOM % 1000))" | grep '^' || return 1; }
__docker_check() { [ -n "$(type -p docker 2>/dev/null)" ] || return 1; }
__password() { cat "/dev/urandom" | tr -dc '0-9a-zA-Z' | head -c${1:-16} && echo ""; }
__docker_ps_all() { docker ps -a 2>&1 | grep ${1:-} "$CONTAINER_NAME" && return 0 || return 1; }
__enable_ssl() { { [ "$SSL_ENABLED" = "yes" ] || [ "$SSL_ENABLED" = "true" ]; } && return 0 || return 1; }
__docker_is_running() { ps aux 2>/dev/null | grep 'dockerd' | grep -v ' grep ' | grep -q '^' || return 1; }
__ssl_certs() { [ -f "$HOST_SSL_CA" ] && [ -f "$HOST_SSL_CRT" ] && [ -f "$HOST_SSL_KEY" ] && return 0 || 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 "$CONTAINER_NAME" | grep -qi 'ago.* Up.* [0-9].* ' && return 0 || return 1; }
__container_name() { echo "$HUB_IMAGE_URL-${HUB_IMAGE_TAG:-latest}" | awk -F '/' '{print $(NF-1)"-"$NF}' | grep '^' || return 1; }
__docker_init() { [ -n "$(type -p dockermgr 2>/dev/null)" ] && dockermgr init || printf_exit "Failed to Initialize the docker installer"; }
__domain_name() { hostname -f 2>/dev/null | awk -F '.' '{print $(NF-1)"."$NF}' | grep '\.' | grep '^' || hostname -f 2>/dev/null | 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; }
__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; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__public_ip() { curl -q -LSsf "http://ifconfig.co" | grep -v '^$' | head -n1 | grep '^'; }
__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'; }
__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; }; }
__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; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Ensure docker is installed and running
__docker_check || __docker_init
__docker_is_running || printf_exit "Docker is not running"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Define any pre-install scripts
__run_pre_install() {
return 0
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Define any post-install scripts
run_post_install() {
return 0
}
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__show_post_message() {
return 0
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Setup application options
setopts=$(getopt -o "e:,m:,p:,h:,d:" --long "options,env:,mount:,port:,host:,domain:" -n "$APPNAME" -- "$@" 2>/dev/null)
set -- "${setopts[@]}" 2>/dev/null
while :; do
case "$1" in
-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_ENV_VAR" && shift 2 ;;
-p | --port) CONTAINER_OPT_PORT_VAR="$2 $CONTAINER_OPT_PORT_VAR" && shift 2 ;;
--options) shift 1 && echo "Options: -e -p -h -d --options --env --port --host --domain" && exit 1 ;;
*) break ;;
esac
done
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[ -n "$(type -P sudo)" ] && sudo -n true && sudo true && DOCKERMGR_USER_CAN_SUDO="true"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# 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="${ENV_HOSTNAME:-$SET_HOSTNAME}"
ENV_DOMAINNAME="${ENV_DOMAINNAME:-$SET_DOMAIN}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# get variables from host
SET_LOCAL_HOSTNAME=$(__host_name)
SET_LONG_HOSTNAME=$(hostname -f 2>/dev/null | grep '^')
SET_SHORT_HOSTNAME=$(hostname -s 2>/dev/null | grep '^')
SET_DOMAIN_NAME=$(__domain_name || hostname -d 2>/dev/null | grep -F '.' | grep '^' || echo 'home')
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set hostname and domain
SET_HOST_FULL_NAME="${FULL_HOST:-$SET_LONG_HOSTNAME}"
SET_HOST_FULL_DOMAIN="${FULL_DOMAIN:-$SET_DOMAIN_NAME}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Define folders
HOST_DATA_DIR="$DATADIR/data"
HOST_CONFIG_DIR="$DATADIR/config"
LOCAL_DATA_DIR="${LOCAL_DATA_DIR:-$HOST_DATA_DIR}"
LOCAL_CONFIG_DIR="${LOCAL_CONFIG_DIR:-$HOST_CONFIG_DIR}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# 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=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# URL to container image - docker pull - [URL]
HUB_IMAGE_URL="casjaysdevdocker/webvirtmgr"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# image tag - [docker pull HUB_IMAGE_URL:tag]
HUB_IMAGE_TAG="latest"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set the container name Default: [org-repo-tag]
CONTAINER_NAME=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# 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 the html dir - [/data/www/html] [WWW_ROOT_DIR]
CONTAINER_HTML_DIR=""
CONTAINER_HTML_ENV=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set container user and group ID - [yes/no] [id] [id]
USER_ID_ENABLED="no"
CONTAINER_USER_ID=""
CONTAINER_GROUP_ID=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# 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"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# 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="yes"
HOST_ETC_HOSTS_INIT_FILE=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Mount docker socket - [yes/no] [/var/run/docker.sock]
DOCKER_SOCKET_ENABLED="no"
DOCKER_SOCKET_MOUNT=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Mount docker config - [yes/no] [~/.docker/config.json] [/root/.docker/config.json]
DOCKER_CONFIG_ENABLED="no"
HOST_DOCKER_CONFIG=""
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"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set container hostname and domain - Default: [webvirtmgr.$SET_HOST_FULL_NAME] [$SET_HOST_FULL_DOMAIN]
CONTAINER_HOSTNAME=""
CONTAINER_DOMAINNAME=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# 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 this to the protocol the the container will use - [http/https/git/ftp/pgsql/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]
HOST_NGINX_ENABLED="yes"
HOST_NGINX_SSL_ENABLED="yes"
HOST_NGINX_HTTP_PORT="80"
HOST_NGINX_HTTPS_PORT="443"
HOST_NGINX_UPDATE_CONF="yes"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Enable this if container is running a webserver - [yes/no] [internalPort] [yes/no] [yes/no] [listen]
CONTAINER_WEB_SERVER_ENABLED="no"
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"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Specify custom nginx vhosts - autoconfigure: [*./name.all/name.mydomain/name.myhostname] - [virtualhost,othervhostdom]
CONTAINER_WEB_SERVER_VHOSTS=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Add random portmapping - [port,otherport] or [proxy|/location|port]
CONTAINER_ADD_RANDOM_PORTS=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Add custom port - [exter:inter] or [listen:exter:inter/[tcp,udp]] random:[inter]
CONTAINER_ADD_CUSTOM_PORT=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# mail settings - [yes/no] [user] [domainname] [server]
CONTAINER_EMAIL_ENABLED=""
CONTAINER_EMAIL_USER=""
CONTAINER_EMAIL_DOMAIN=""
CONTAINER_EMAIL_RELAY=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Easy setup for services - [no/yes]
CONTAINER_SERVICE_PUBLIC="yes"
CONTAINER_IS_DNS_SERVER="no"
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"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Database settings - [listen] [yes/no]
CONTAINER_DATABASE_LISTEN=""
CONTAINER_REDIS_ENABLED=""
CONTAINER_SQLITE3_ENABLED=""
CONTAINER_MARIADB_ENABLED=""
CONTAINER_MONGODB_ENABLED=""
CONTAINER_COUCHDB_ENABLED=""
CONTAINER_POSTGRES_ENABLED=""
CONTAINER_SUPABASE_ENABLED=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Custom database setup - [yes/no] [mysql] [port/directory] [/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=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# 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 a username and password - [user] [pass/random]
CONTAINER_USER_NAME=""
CONTAINER_USER_PASS=""
CONTAINER_PASS_LENGTH="24"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set container username and password env name - [CONTAINER_ENV_USER_NAME=$CONTAINER_USER_NAME]
CONTAINER_ENV_USER_NAME=""
CONTAINER_ENV_PASS_NAME=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# 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 - [/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 capabilites - [yes/no]
DOCKER_SYS_TIME="yes"
DOCKER_SYS_ADMIN="yes"
DOCKER_CAP_CHOWN="no"
DOCKER_CAP_NET_RAW="no"
DOCKER_CAP_SYS_NICE="no"
DOCKER_CAP_NET_ADMIN="no"
DOCKER_CAP_NET_BIND_SERVICE="no"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# 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,/config/$APPNAME,"
CONTAINER_CREATE_DIRECTORY+=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Show post install message
POST_SHOW_FINISHED_MESSAGE=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Run the script if it exists [yes/no]
DOCKERMGR_ENABLE_INSTALL_SCRIPT="yes"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set custom container enviroment variables - [--env MYVAR="VAR"]
__custom_docker_env() {
cat <<EOF | tee | sed 's|,| --env |g' | tr '\n' ' ' | __remove_extra_spaces
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"
cat <<EOF | __remove_extra_spaces | tee "$base_dir/$base_file" &>/dev/null
EOF
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__dockermgr_variables() {
[ -d "$DOCKERMGR_CONFIG_DIR/env" ] || mkdir -p "$DOCKERMGR_CONFIG_DIR/env"
cat <<EOF | tee | tr '|' '\n' | __remove_extra_spaces
# Enviroment variables for $APPNAME
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
HOST_DATA_DIR="\${ENV_HOST_DATA_DIR:-$HOST_DATA_DIR}"
HOST_CONFIG_DIR="\${ENV_HOST_CONFIG_DIR:-$HOST_CONFIG_DIR}"
HOST_SSL_DIR="\${ENV_HOST_SSL_DIR:-$HOST_SSL_DIR}"
HOST_SSL_CA="\${ENV_HOST_SSL_CA:-$HOST_SSL_CA}"
HOST_SSL_CRT="\${ENV_HOST_SSL_CRT:-$HOST_SSL_CRT}"
HOST_SSL_KEY="\${ENV_HOST_SSL_KEY:-$HOST_SSL_KEY}"
HOST_RESOLVE_ENABLED="\${ENV_HOST_RESOLVE_ENABLED:-$HOST_RESOLVE_ENABLED}"
HOST_RESOLVE_FILE="\${ENV_HOST_RESOLVE_FILE:-$HOST_RESOLVE_FILE}"
HOST_ETC_HOSTS_ENABLED="\${ENV_HOST_ETC_HOSTS_ENABLED:-$HOST_ETC_HOSTS_ENABLED}"
HOST_ETC_HOSTS_MOUNT="\${ENV_HOST_ETC_HOSTS_MOUNT:-$HOST_ETC_HOSTS_MOUNT}"
HOST_DOCKER_CONFIG="\${ENV_HOST_DOCKER_CONFIG:-$HOST_DOCKER_CONFIG}"
HOST_SOUND_DEVICE="\${ENV_HOST_SOUND_DEVICE:-$HOST_SOUND_DEVICE}"
HOST_X11_DISPLAY="\${ENV_HOST_X11_DISPLAY:-$HOST_X11_DISPLAY}"
HOST_X11_SOCKET="\${ENV_HOST_X11_SOCKET:-$HOST_X11_SOCKET}"
HOST_X11_XAUTH="\${ENV_HOST_X11_XAUTH:-$HOST_X11_XAUTH}"
HOST_DOCKER_NETWORK="\${ENV_HOST_DOCKER_NETWORK:-$HOST_DOCKER_NETWORK}"
HOST_DOCKER_LINK="\${ENV_HOST_DOCKER_LINK:-$HOST_DOCKER_LINK}"
HOST_NETWORK_ADDR="\${ENV_HOST_NETWORK_ADDR:-$HOST_NETWORK_ADDR}"
HOST_NGINX_ENABLED="\${ENV_HOST_NGINX_ENABLED:-$HOST_NGINX_ENABLED}"
HOST_NGINX_SSL_ENABLED="\${ENV_HOST_NGINX_SSL_ENABLED:-$HOST_NGINX_SSL_ENABLED}"
HOST_NGINX_HTTP_PORT="\${ENV_HOST_NGINX_HTTP_PORT:-$HOST_NGINX_HTTP_PORT}"
HOST_NGINX_HTTPS_PORT="\${ENV_HOST_NGINX_HTTPS_PORT:-$HOST_NGINX_HTTPS_PORT}"
HOST_NGINX_UPDATE_CONF="\${ENV_HOST_NGINX_UPDATE_CONF:-$HOST_NGINX_UPDATE_CONF}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CONTAINER_SSL_CA="${CONTAINER_SSL_CA:-}"
CONTAINER_SSL_CRT="${CONTAINER_SSL_CRT:-}"
CONTAINER_SSL_KEY="${CONTAINER_SSL_KEY:-}"
CONTAINER_NAME="${CONTAINER_NAME:-}"
CONTAINER_REQUIRES="${CONTAINER_REQUIRES:-}"
CONTAINER_TIMEZONE="${CONTAINER_TIMEZONE:-}"
CONTAINER_WORK_DIR="${CONTAINER_WORK_DIR:-}"
CONTAINER_HTML_DIR="${CONTAINER_HTML_DIR:-}"
CONTAINER_HTML_ENV="${CONTAINER_HTML_ENV:-}"
CONTAINER_USER_ID="${CONTAINER_USER_ID:-}"
CONTAINER_GROUP_ID="${CONTAINER_GROUP_ID:-}"
CONTAINER_USER_RUN="${CONTAINER_USER_RUN:-}"
CONTAINER_PRIVILEGED_ENABLED="${CONTAINER_PRIVILEGED_ENABLED:-}"
CONTAINER_SHM_SIZE="${CONTAINER_SHM_SIZE:-}"
CONTAINER_RAM_SIZE="${CONTAINER_RAM_SIZE:-}"
CONTAINER_SWAP_SIZE="${CONTAINER_SWAP_SIZE:-}"
CONTAINER_CPU_COUNT="${CONTAINER_CPU_COUNT:-}"
CONTAINER_AUTO_RESTART="${CONTAINER_AUTO_RESTART:-}"
CONTAINER_AUTO_DELETE="${CONTAINER_AUTO_DELETE:-}"
CONTAINER_TTY_ENABLED="${CONTAINER_TTY_ENABLED:-}"
CONTAINER_INTERACTIVE_ENABLED="${CONTAINER_INTERACTIVE_ENABLED:-}"
CONTAINER_ENV_FILE_ENABLED="${CONTAINER_ENV_FILE_ENABLED:-}"
CONTAINER_ENV_FILE_MOUNT="${CONTAINER_ENV_FILE_MOUNT:-}"
CONTAINER_DOCKER_CONFIG_FILE="${CONTAINER_DOCKER_CONFIG_FILE:-}"
CONTAINER_SOUND_DEVICE_FILE="${CONTAINER_SOUND_DEVICE_FILE:-}"
CONTAINER_X11_ENABLED="${CONTAINER_X11_ENABLED:-}"
CONTAINER_X11_SOCKET="${CONTAINER_X11_SOCKET:-}"
CONTAINER_X11_XAUTH="${CONTAINER_X11_XAUTH:-}"
CONTAINER_HOSTNAME="${CONTAINER_HOSTNAME:-}"
CONTAINER_DOMAINNAME="${CONTAINER_DOMAINNAME:-}"
CONTAINER_PROTOCOL="${CONTAINER_PROTOCOL:-}"
CONTAINER_DNS="${CONTAINER_DNS:-}"
CONTAINER_WEB_SERVER_ENABLED="${CONTAINER_WEB_SERVER_ENABLED:-}"
CONTAINER_WEB_SERVER_INT_PORT="${CONTAINER_WEB_SERVER_INT_PORT:-}"
CONTAINER_WEB_SERVER_SSL_ENABLED="${CONTAINER_WEB_SERVER_SSL_ENABLED:-}"
CONTAINER_WEB_SERVER_AUTH_ENABLED="${CONTAINER_WEB_SERVER_AUTH_ENABLED:-}"
CONTAINER_WEB_SERVER_LISTEN_ON="${CONTAINER_WEB_SERVER_LISTEN_ON:-}"
CONTAINER_WEB_SERVER_VHOSTS="${CONTAINER_WEB_SERVER_VHOSTS:-}"
CONTAINER_ADD_RANDOM_PORTS="${CONTAINER_ADD_RANDOM_PORTS:-}"
CONTAINER_ADD_CUSTOM_PORT="${CONTAINER_ADD_CUSTOM_PORT:-}"
CONTAINER_EMAIL_ENABLED="${CONTAINER_EMAIL_ENABLED:-}"
CONTAINER_EMAIL_USER="${CONTAINER_EMAIL_USER:-}"
CONTAINER_EMAIL_DOMAIN="${CONTAINER_EMAIL_DOMAIN:-}"
CONTAINER_EMAIL_RELAY="${CONTAINER_EMAIL_RELAY:-}"
CONTAINER_SERVICE_PUBLIC="${CONTAINER_SERVICE_PUBLIC:-}"
CONTAINER_IS_DNS_SERVER="${CONTAINER_IS_DNS_SERVER:-}"
CONTAINER_IS_DHCP_SERVER="${CONTAINER_IS_DHCP_SERVER:-}"
CONTAINER_IS_TFTP_SERVER="${CONTAINER_IS_TFTP_SERVER:-}"
CONTAINER_IS_SMTP_SERVER="${CONTAINER_IS_SMTP_SERVER:-}"
CONTAINER_IS_POP3_SERVER="${CONTAINER_IS_POP3_SERVER:-}"
CONTAINER_IS_IMAP_SERVER="${CONTAINER_IS_IMAP_SERVER:-}"
CONTAINER_IS_TIME_SERVER="${CONTAINER_IS_TIME_SERVER:-}"
CONTAINER_IS_NEWS_SERVER="${CONTAINER_IS_NEWS_SERVER:-}"
CONTAINER_DATABASE_LISTEN="${CONTAINER_DATABASE_LISTEN:-}"
CONTAINER_REDIS_ENABLED="${CONTAINER_REDIS_ENABLED:-}"
CONTAINER_SQLITE3_ENABLED="${CONTAINER_SQLITE3_ENABLED:-}"
CONTAINER_MARIADB_ENABLED="${CONTAINER_MARIADB_ENABLED:-}"
CONTAINER_MONGODB_ENABLED="${CONTAINER_MONGODB_ENABLED:-}"
CONTAINER_COUCHDB_ENABLED="${CONTAINER_COUCHDB_ENABLED:-}"
CONTAINER_POSTGRES_ENABLED="${CONTAINER_POSTGRES_ENABLED:-}"
CONTAINER_SUPABASE_ENABLED="${CONTAINER_SUPABASE_ENABLED:-}"
CONTAINER_CUSTOM_DATABASE_ENABLED="${CONTAINER_CUSTOM_DATABASE_ENABLED:-}"
CONTAINER_CUSTOM_DATABASE_NAME="${CONTAINER_CUSTOM_DATABASE_NAME:-}"
CONTAINER_CUSTOM_DATABASE_PORT="${CONTAINER_CUSTOM_DATABASE_PORT:-}"
CONTAINER_CUSTOM_DATABASE_DIR="${CONTAINER_CUSTOM_DATABASE_DIR:-}"
CONTAINER_CUSTOM_DATABASE_PROTOCOL="${CONTAINER_CUSTOM_DATABASE_PROTOCOL:-}"
CONTAINER_DATABASE_USER_ROOT="${CONTAINER_DATABASE_USER_ROOT:-}"
CONTAINER_DATABASE_PASS_ROOT="${CONTAINER_DATABASE_PASS_ROOT:-}"
CONTAINER_DATABASE_LENGTH_ROOT="${CONTAINER_DATABASE_LENGTH_ROOT:-}"
CONTAINER_DATABASE_USER_NORMAL="${CONTAINER_DATABASE_USER_NORMAL:-}"
CONTAINER_DATABASE_PASS_NORMAL="${CONTAINER_DATABASE_PASS_NORMAL:-}"
CONTAINER_DATABASE_LENGTH_NORMAL="${CONTAINER_DATABASE_LENGTH_NORMAL:-}"
CONTAINER_USER_NAME="${CONTAINER_USER_NAME:-}"
CONTAINER_USER_PASS="${CONTAINER_USER_PASS:-}"
CONTAINER_PASS_LENGTH="${CONTAINER_PASS_LENGTH:-}"
CONTAINER_ENV_USER_NAME="${CONTAINER_ENV_USER_NAME:-}"
CONTAINER_ENV_PASS_NAME="${CONTAINER_ENV_PASS_NAME:-}"
CONTAINER_SERVICES_LIST="${CONTAINER_SERVICES_LIST:-}"
CONTAINER_MOUNT_DATA_ENABLED="${CONTAINER_MOUNT_DATA_ENABLED:-}"
CONTAINER_MOUNT_DATA_MOUNT_DIR="${CONTAINER_MOUNT_DATA_MOUNT_DIR:-}"
CONTAINER_MOUNT_CONFIG_ENABLED="${CONTAINER_MOUNT_CONFIG_ENABLED:-}"
CONTAINER_MOUNT_CONFIG_MOUNT_DIR="${CONTAINER_MOUNT_CONFIG_MOUNT_DIR:-}"
CONTAINER_MOUNTS="${CONTAINER_MOUNTS:-}"
CONTAINER_DEVICES="${CONTAINER_DEVICES:-}"
CONTAINER_ENV="${CONTAINER_ENV:-}"
CONTAINER_SYSCTL="${CONTAINER_SYSCTL:-}"
CONTAINER_LABELS="${CONTAINER_LABELS:-}"
CONTAINER_COMMANDS="${CONTAINER_COMMANDS:-}"
CONTAINER_DEBUG_ENABLED="${CONTAINER_DEBUG_ENABLED:-}"
CONTAINER_DEBUG_OPTIONS="${CONTAINER_DEBUG_OPTIONS:-}"
CONTAINER_CREATE_DIRECTORY="${CONTAINER_CREATE_DIRECTORY:-}"
#
DOCKER_SYS_ADMIN="\${ENV_DOCKER_SYS_ADMIN:-$DOCKER_SYS_ADMIN}"
DOCKER_CAP_CHOWN="\${ENV_DOCKER_CAP_CHOWN:-$DOCKER_CAP_CHOWN}"
DOCKER_CAP_NET_RAW="\${ENV_DOCKER_CAP_NET_RAW:-$DOCKER_CAP_NET_RAW}"
DOCKER_CAP_SYS_NICE="\${ENV_DOCKER_DOCKER_CAP_SYS_NICE:-$DOCKER_CAP_SYS_NICE}"
DOCKER_CAP_NET_ADMIN="\${ENV_DOCKER_CAP_NET_ADMIN:-$DOCKER_CAP_NET_ADMIN}"
DOCKER_CAP_NET_BIND_SERVICE="\${ENV_DOCKER_CAP_NET_BIND_SERVICE:-$DOCKER_CAP_NET_BIND_SERVICE}"
EOF
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__dockermgr_password_variables() {
[ -d "$DOCKERMGR_CONFIG_DIR/secure" ] || mkdir -p "$DOCKERMGR_CONFIG_DIR/secure"
cat <<EOF | tee | tr '|' '\n' | __remove_extra_spaces
# Enviroment variables for $APPNAME
ENV_CONTAINER_ENV_PASS_NAME="${ENV_CONTAINER_ENV_PASS_NAME:-$CONTAINER_ENV_PASS_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}"
EOF
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Define extra functions
__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
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__trim() {
local var="$*"
var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters
var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters
printf '%s' "$var" | grep -v '^$' | __remove_extra_spaces
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__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
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__create_docker_script() {
[ -n "$EXECUTE_DOCKER_CMD" ] || return
local replace_with="$HUB_IMAGE_URL:$HUB_IMAGE_TAG $CONTAINER_COMMANDS"
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 | grep -v '^$' | sed 's/ --/\n --/g;s| -d| -d \\|g' | grep -v '^$' | sed '/ --/ s/$/ \\/' | grep '^' | tee "$DOCKERMGR_INSTALL_SCRIPT" >/dev/null
#!/usr/bin/env bash
# Install script for $CONTAINER_NAME
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$EXECUTE_PRE_INSTALL
statusCode=\$?
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if [ \$statusCode -ne 0 ]; then
echo "$create_docker_script_message_pre" >&2
exit 1
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$EXECUTE_DOCKER_CMD
$HUB_IMAGE_URL:$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 -q "$CONTAINER_NAME"; then
echo "$CONTAINER_NAME is not running" >&2
exit 1
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
exit 0
# end script
EOF
unset create_docker_script_message_pre create_docker_script_message_post
[ -f "$DOCKERMGR_INSTALL_SCRIPT" ] || return 1
sed -i 's| '$HUB_IMAGE_URL':'$HUB_IMAGE_TAG' .*\\| \\|g' "$DOCKERMGR_INSTALL_SCRIPT"
chmod -Rf 755 "$DOCKERMGR_INSTALL_SCRIPT"
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__printf_color() { printf_color "$2\n" "$1"; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# import variables from a file
[ -f "$INSTDIR/env.sh" ] && . "$INSTDIR/env.sh"
[ -f "$APPDIR/env.sh" ] && . "$APPDIR/env.sh"
[ -f "$DOCKERMGR_CONFIG_DIR/.env.sh" ] && . "$DOCKERMGR_CONFIG_DIR/.env.sh"
[ -f "$DOCKERMGR_CONFIG_DIR/env/$APPNAME.conf" ] && . "$DOCKERMGR_CONFIG_DIR/env/$APPNAME.conf"
[ -f "$DOCKERMGR_CONFIG_DIR/env/$APPNAME.custom.conf" ] && . "$DOCKERMGR_CONFIG_DIR/env/$APPNAME.custom.conf"
[ -r "$DOCKERMGR_CONFIG_DIR/secure/$APPNAME" ] && . "$DOCKERMGR_CONFIG_DIR/secure/$APPNAME"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Initialize the installer
dockermgr_run_init
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Run pre-install commands
execute "__run_pre_install" "Running pre-installation commands"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ensure_dirs
ensure_perms
mkdir -p "$DOCKERMGR_CONFIG_DIR/env"
mkdir -p "$DOCKERMGR_CONFIG_DIR/secure"
mkdir -p "$DOCKERMGR_CONFIG_DIR/scripts"
mkdir -p "$DOCKERMGR_CONFIG_DIR/installed"
mkdir -p "$DOCKERMGR_CONFIG_DIR/containers"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# fix directory permissions
chmod -f 777 "$APPDIR"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# variable cleanup
HUB_IMAGE_TAG="${HUB_IMAGE_TAG//*:/}"
HUB_IMAGE_URL="${HUB_IMAGE_URL//*:\/\//}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# verify required file exists
if [ -n "$CONTAINER_REQUIRES" ]; then
CONTAINER_REQUIRES="${CONTAINER_REQUIRES//,/}"
for required in $CONTAINER_REQUIRES; do
if [ ! -e "$required" ] || [ -z "$(type "$required" 2>/dev/null)" ]; then
required_missing="$required $required_missing"
fi
done
[ "$required_missing" != " " ] || unset required_missing
if [ -n "$required_missing" ]; then
echo "Missing required: $required_missing"
exit 1
fi
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# rewrite variables from env file
SET_LAN_DEV="${ENV_SET_LAN_DEV:-$SET_LAN_DEV}"
SET_LAN_IP="${ENV_SET_LAN_IP:-$SET_LAN_IP}"
SET_LAN_IP="${ENV_SET_LAN_IP:-$SET_LAN_IP}"
SET_DOCKER_IP="${ENV_SET_DOCKER_IP:-$SET_DOCKER_IP}"
SET_LOCAL_HOSTNAME="${ENV_SET_LOCAL_HOSTNAME:-$SET_LOCAL_HOSTNAME}"
SET_LONG_HOSTNAME="${ENV_SET_LONG_HOSTNAME:-$SET_LONG_HOSTNAME}"
SET_SHORT_HOSTNAME="${ENV_SET_SHORT_HOSTNAME:-$SET_SHORT_HOSTNAME}"
SET_DOMAIN_NAME="${ENV_SET_DOMAIN_NAME:-$SET_DOMAIN_NAME}"
SET_HOST_FULL_NAME="${ENV_SET_HOST_FULL_NAME:-$SET_HOST_FULL_NAME}"
SET_HOST_FULL_DOMAIN="${ENV_SET_HOST_FULL_DOMAIN:-$SET_HOST_FULL_DOMAIN}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
HOST_DATA_DIR="${ENV_HOST_DATA_DIR:-$HOST_DATA_DIR}"
HOST_CONFIG_DIR="${ENV_HOST_CONFIG_DIR:-$HOST_CONFIG_DIR}"
HOST_SSL_DIR="${ENV_HOST_SSL_DIR:-$HOST_SSL_DIR}"
HOST_SSL_CA="${ENV_HOST_SSL_CA:-$HOST_SSL_CA}"
HOST_SSL_CRT="${ENV_HOST_SSL_CRT:-$HOST_SSL_CRT}"
HOST_SSL_KEY="${ENV_HOST_SSL_KEY:-$HOST_SSL_KEY}"
HOST_RESOLVE_ENABLED="${ENV_HOST_RESOLVE_ENABLED:-$HOST_RESOLVE_ENABLED}"
HOST_RESOLVE_FILE="${ENV_HOST_RESOLVE_FILE:-$HOST_RESOLVE_FILE}"
HOST_ETC_HOSTS_ENABLED="${ENV_HOST_ETC_HOSTS_ENABLED:-$HOST_ETC_HOSTS_ENABLED}"
HOST_ETC_HOSTS_MOUNT="${ENV_HOST_ETC_HOSTS_MOUNT:-$HOST_ETC_HOSTS_MOUNT}"
HOST_DOCKER_CONFIG="${ENV_HOST_DOCKER_CONFIG:-$HOST_DOCKER_CONFIG}"
HOST_SOUND_DEVICE="${ENV_HOST_SOUND_DEVICE:-$HOST_SOUND_DEVICE}"
HOST_X11_DISPLAY="${ENV_HOST_X11_DISPLAY:-$HOST_X11_DISPLAY}"
HOST_X11_SOCKET="${ENV_HOST_X11_SOCKET:-$HOST_X11_SOCKET}"
HOST_X11_XAUTH="${ENV_HOST_X11_XAUTH:-$HOST_X11_XAUTH}"
HOST_DOCKER_NETWORK="${ENV_HOST_DOCKER_NETWORK:-$HOST_DOCKER_NETWORK}"
HOST_DOCKER_LINK="${ENV_HOST_DOCKER_LINK:-$HOST_DOCKER_LINK}"
HOST_NETWORK_ADDR="${ENV_HOST_NETWORK_ADDR:-$HOST_NETWORK_ADDR}"
HOST_NGINX_ENABLED="${ENV_HOST_NGINX_ENABLED:-$HOST_NGINX_ENABLED}"
HOST_NGINX_SSL_ENABLED="${ENV_HOST_NGINX_SSL_ENABLED:-$HOST_NGINX_SSL_ENABLED}"
HOST_NGINX_HTTP_PORT="${ENV_HOST_NGINX_HTTP_PORT:-$HOST_NGINX_HTTP_PORT}"
HOST_NGINX_HTTPS_PORT="${ENV_HOST_NGINX_HTTPS_PORT:-$HOST_NGINX_HTTPS_PORT}"
HOST_NGINX_UPDATE_CONF="${ENV_HOST_NGINX_UPDATE_CONF:-$HOST_NGINX_UPDATE_CONF}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CONTAINER_NAME="${ENV_CONTAINER_NAME:-${CONTAINER_NAME:-}}"
CONTAINER_SSL_DIR="${ENV_CONTAINER_SSL_DIR:-$CONTAINER_SSL_DIR}"
CONTAINER_SSL_CA="${ENV_CONTAINER_SSL_CA:-$CONTAINER_SSL_CA}"
CONTAINER_SSL_CRT="${ENV_CONTAINER_SSL_CRT:-$CONTAINER_SSL_CRT}"
CONTAINER_SSL_KEY="${ENV_CONTAINER_SSL_KEY:-$CONTAINER_SSL_KEY}"
CONTAINER_REQUIRES="${ENV_CONTAINER_REQUIRES:-$CONTAINER_REQUIRES}"
CONTAINER_TIMEZONE="${ENV_CONTAINER_TIMEZONE:-$CONTAINER_TIMEZONE}"
CONTAINER_WORK_DIR="${ENV_CONTAINER_WORK_DIR:-$CONTAINER_WORK_DIR}"
CONTAINER_HTML_DIR="${ENV_CONTAINER_HTML_DIR:-$CONTAINER_HTML_DIR}"
CONTAINER_HTML_ENV="${ENV_CONTAINER_HTML_ENV:-$CONTAINER_HTML_ENV}"
CONTAINER_USER_ID="${ENV_CONTAINER_USER_ID:-$CONTAINER_USER_ID}"
CONTAINER_GROUP_ID="${ENV_CONTAINER_GROUP_ID:-$CONTAINER_GROUP_ID}"
CONTAINER_USER_RUN="${ENV_CONTAINER_USER_RUN:-$CONTAINER_USER_RUN}"
CONTAINER_PRIVILEGED_ENABLED="${ENV_CONTAINER_PRIVILEGED_ENABLED:-$CONTAINER_PRIVILEGED_ENABLED}"
CONTAINER_SHM_SIZE="${ENV_CONTAINER_SHM_SIZE:-$CONTAINER_SHM_SIZE}"
CONTAINER_RAM_SIZE="${ENV_CONTAINER_RAM_SIZE:-$CONTAINER_RAM_SIZE}"
CONTAINER_SWAP_SIZE="${ENV_CONTAINER_SWAP_SIZE:-$CONTAINER_SWAP_SIZE}"
CONTAINER_CPU_COUNT="${ENV_CONTAINER_CPU_COUNT:-$CONTAINER_CPU_COUNT}"
CONTAINER_AUTO_RESTART="${ENV_CONTAINER_AUTO_RESTART:-$CONTAINER_AUTO_RESTART}"
CONTAINER_AUTO_DELETE="${ENV_CONTAINER_AUTO_DELETE:-$CONTAINER_AUTO_DELETE}"
CONTAINER_TTY_ENABLED="${ENV_CONTAINER_TTY_ENABLED:-$CONTAINER_TTY_ENABLED}"
CONTAINER_INTERACTIVE_ENABLED="${ENV_CONTAINER_INTERACTIVE_ENABLED:-$CONTAINER_INTERACTIVE_ENABLED}"
CONTAINER_ENV_FILE_ENABLED="${ENV_CONTAINER_ENV_FILE_ENABLED:-$CONTAINER_ENV_FILE_ENABLED}"
CONTAINER_ENV_FILE_MOUNT="${ENV_CONTAINER_ENV_FILE_MOUNT:-$CONTAINER_ENV_FILE_MOUNT}"
CONTAINER_DOCKER_CONFIG_FILE="${ENV_CONTAINER_DOCKER_CONFIG_FILE:-$CONTAINER_DOCKER_CONFIG_FILE}"
CONTAINER_SOUND_DEVICE_FILE="${ENV_CONTAINER_SOUND_DEVICE_FILE:-$CONTAINER_SOUND_DEVICE_FILE}"
CONTAINER_X11_ENABLED="${ENV_CONTAINER_X11_ENABLED:-$CONTAINER_X11_ENABLED}"
CONTAINER_X11_SOCKET="${ENV_CONTAINER_X11_SOCKET:-$CONTAINER_X11_SOCKET}"
CONTAINER_X11_XAUTH="${ENV_CONTAINER_X11_XAUTH:-$CONTAINER_X11_XAUTH}"
CONTAINER_HOSTNAME="${ENV_HOSTNAME:-${ENV_CONTAINER_HOSTNAME:-$CONTAINER_HOSTNAME}}"
CONTAINER_DOMAINNAME="${ENV_DOMAINNAME:-${ENV_CONTAINER_DOMAINNAME:-$CONTAINER_DOMAINNAME}}"
CONTAINER_WEB_SERVER_ENABLED="${ENV_CONTAINER_WEB_SERVER_ENABLED:-$CONTAINER_WEB_SERVER_ENABLED}"
CONTAINER_WEB_SERVER_INT_PORT="${ENV_CONTAINER_WEB_SERVER_INT_PORT:-$CONTAINER_WEB_SERVER_INT_PORT}"
CONTAINER_WEB_SERVER_SSL_ENABLED="${ENV_CONTAINER_WEB_SERVER_SSL_ENABLED:-$CONTAINER_WEB_SERVER_SSL_ENABLED}"
CONTAINER_WEB_SERVER_AUTH_ENABLED="${ENV_CONTAINER_WEB_SERVER_AUTH_ENABLED:-$CONTAINER_WEB_SERVER_AUTH_ENABLED}"
CONTAINER_WEB_SERVER_LISTEN_ON="${ENV_CONTAINER_WEB_SERVER_LISTEN_ON:-$CONTAINER_WEB_SERVER_LISTEN_ON}"
CONTAINER_WEB_SERVER_VHOSTS="${ENV_CONTAINER_WEB_SERVER_VHOSTS:-$CONTAINER_WEB_SERVER_VHOSTS}"
CONTAINER_WEB_SERVER_CONFIG_NAME="${ENV_CONTAINER_WEB_SERVER_CONFIG_NAME:-$CONTAINER_WEB_SERVER_CONFIG_NAME}"
CONTAINER_ADD_CUSTOM_PORT="${ENV_CONTAINER_ADD_CUSTOM_PORT:-$CONTAINER_ADD_CUSTOM_PORT}"
CONTAINER_PROTOCOL="${ENV_CONTAINER_PROTOCOL:-$CONTAINER_PROTOCOL}"
CONTAINER_DNS="${ENV_CONTAINER_DNS:-$CONTAINER_DNS}"
CONTAINER_DATABASE_LISTEN="${ENV_CONTAINER_DATABASE_LISTEN:-$CONTAINER_DATABASE_LISTEN}"
CONTAINER_REDIS_ENABLED="${ENV_CONTAINER_REDIS_ENABLED:-$CONTAINER_REDIS_ENABLED}"
CONTAINER_SQLITE3_ENABLED="${ENV_CONTAINER_SQLITE3_ENABLED:-$CONTAINER_SQLITE3_ENABLED}"
CONTAINER_MARIADB_ENABLED="${ENV_CONTAINER_MARIADB_ENABLED:-$CONTAINER_MARIADB_ENABLED}"
CONTAINER_MONGODB_ENABLED="${ENV_CONTAINER_MONGODB_ENABLED:-$CONTAINER_MONGODB_ENABLED}"
CONTAINER_COUCHDB_ENABLED="${ENV_CONTAINER_COUCHDB_ENABLED:-$CONTAINER_COUCHDB_ENABLED}"
CONTAINER_POSTGRES_ENABLED="${ENV_CONTAINER_POSTGRES_ENABLED:-$CONTAINER_POSTGRES_ENABLED}"
CONTAINER_SUPABASE_ENABLED="${ENV_CONTAINER_SUPABASE_ENABLED:-$CONTAINER_SUPABASE_ENABLED}"
CONTAINER_DATABASE_USER_ROOT="${ENV_CONTAINER_DATABASE_USER_ROOT:-$CONTAINER_DATABASE_USER_ROOT}"
CONTAINER_DATABASE_PASS_ROOT="${ENV_CONTAINER_DATABASE_PASS_ROOT:-$CONTAINER_DATABASE_PASS_ROOT}"
CONTAINER_DATABASE_LENGTH_ROOT="${ENV_CONTAINER_DATABASE_LENGTH_ROOT:-$CONTAINER_DATABASE_LENGTH_ROOT}"
CONTAINER_DATABASE_USER_NORMAL="${ENV_CONTAINER_DATABASE_USER_NORMAL:-$CONTAINER_DATABASE_USER_NORMAL}"
CONTAINER_DATABASE_PASS_NORMAL="${ENV_CONTAINER_DATABASE_PASS_NORMAL:-$CONTAINER_DATABASE_PASS_NORMAL}"
CONTAINER_DATABASE_LENGTH_NORMAL="${ENV_CONTAINER_DATABASE_LENGTH_NORMAL:-$CONTAINER_DATABASE_LENGTH_NORMAL}"
CONTAINER_USER_NAME="${ENV_CONTAINER_USER_NAME:-$CONTAINER_USER_NAME}"
CONTAINER_USER_PASS="${ENV_CONTAINER_USER_PASS:-$CONTAINER_USER_PASS}"
CONTAINER_PASS_LENGTH="${ENV_CONTAINER_PASS_LENGTH:-$CONTAINER_PASS_LENGTH}"
CONTAINER_ENV_USER_NAME="${ENV_CONTAINER_ENV_USER_NAME:-$CONTAINER_ENV_USER_NAME}"
CONTAINER_ENV_PASS_NAME="${ENV_CONTAINER_ENV_PASS_NAME:-$CONTAINER_ENV_PASS_NAME}"
CONTAINER_EMAIL_ENABLED="${ENV_CONTAINER_EMAIL_ENABLED:-$CONTAINER_EMAIL_ENABLED}"
CONTAINER_EMAIL_USER="${ENV_CONTAINER_EMAIL_USER:-$CONTAINER_EMAIL_USER}"
CONTAINER_EMAIL_DOMAIN="${ENV_CONTAINER_EMAIL_DOMAIN:-$CONTAINER_EMAIL_DOMAIN}"
CONTAINER_EMAIL_RELAY="${ENV_CONTAINER_EMAIL_RELAY:-$CONTAINER_EMAIL_RELAY}"
CONTAINER_SERVICES_LIST="${ENV_CONTAINER_SERVICES_LIST:-$CONTAINER_SERVICES_LIST}"
CONTAINER_MOUNT_DATA_ENABLED="${ENV_CONTAINER_MOUNT_DATA_ENABLED:-$CONTAINER_MOUNT_DATA_ENABLED}"
CONTAINER_MOUNT_DATA_MOUNT_DIR="${ENV_CONTAINER_MOUNT_DATA_MOUNT_DIR:-$CONTAINER_MOUNT_DATA_MOUNT_DIR}"
CONTAINER_MOUNT_CONFIG_ENABLED="${ENV_CONTAINER_MOUNT_CONFIG_ENABLED:-$CONTAINER_MOUNT_CONFIG_ENABLED}"
CONTAINER_MOUNT_CONFIG_MOUNT_DIR="${ENV_CONTAINER_MOUNT_CONFIG_MOUNT_DIR:-$CONTAINER_MOUNT_CONFIG_MOUNT_DIR}"
CONTAINER_MOUNTS="${ENV_CONTAINER_MOUNTS:-$CONTAINER_MOUNTS}"
CONTAINER_DEVICES="${ENV_CONTAINER_DEVICES:-$CONTAINER_DEVICES}"
CONTAINER_ENV="${ENV_CONTAINER_ENV:-$CONTAINER_ENV}"
CONTAINER_SYSCTL="${ENV_CONTAINER_SYSCTL:-$CONTAINER_SYSCTL}"
CONTAINER_LABELS="${ENV_CONTAINER_LABELS:-$CONTAINER_LABELS}"
CONTAINER_COMMANDS="${ENV_CONTAINER_COMMANDS:-$CONTAINER_COMMANDS}"
CONTAINER_DEBUG_ENABLED="${ENV_CONTAINER_DEBUG_ENABLED:-$CONTAINER_DEBUG_ENABLED}"
CONTAINER_DEBUG_OPTIONS="${ENV_CONTAINER_DEBUG_OPTIONS:-$CONTAINER_DEBUG_OPTIONS}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
DOCKER_SYS_ADMIN="${ENV_DOCKER_SYS_ADMIN:-$DOCKER_SYS_ADMIN}"
DOCKER_CAP_CHOWN="${ENV_DOCKER_CAP_CHOWN:-$DOCKER_CAP_CHOWN}"
DOCKER_CAP_NET_RAW="${ENV_DOCKER_CAP_NET_RAW:-$DOCKER_CAP_NET_RAW}"
DOCKER_CAP_SYS_NICE="${ENV_DOCKER_CAP_SYS_NICE:-$DOCKER_CAP_SYS_NICE}"
DOCKER_CAP_NET_ADMIN="${ENV_DOCKER_CAP_NET_ADMIN:-$DOCKER_CAP_NET_ADMIN}"
DOCKER_CAP_NET_BIND_SERVICE="${ENV_DOCKER_CAP_NET_BIND_SERVICE:-$DOCKER_CAP_NET_BIND_SERVICE}"
DOCKERMGR_ENABLE_INSTALL_SCRIPT="${SCRIPT_ENABLED:-$DOCKERMGR_ENABLE_INSTALL_SCRIPT}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# SSL Setup container mounts
CONTAINER_SSL_DIR="${CONTAINER_SSL_DIR:-/config/ssl}"
CONTAINER_SSL_CA="${CONTAINER_SSL_CA:-$CONTAINER_SSL_DIR/ca.crt}"
CONTAINER_SSL_CRT="${CONTAINER_SSL_CRT:-$CONTAINER_SSL_DIR/localhost.crt}"
CONTAINER_SSL_KEY="${CONTAINER_SSL_KEY:-$CONTAINER_SSL_DIR/localhost.key}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Setup ssl certs
if [ "$CONTAINER_WEB_SERVER_SSL_ENABLED" = "true" ]; then
if [ -z "$HOST_SSL_CA" ]; then
if [ -f "/etc/ssl/cert.pem" ]; then
HOST_SSL_CA="/etc/ssl/cert.pem"
elif [ -f "/etc/ssl/certs/ca-bundle.crt" ]; then
HOST_SSL_CA="/etc/ssl/certs/ca-bundle.crt"
elif [ -f "/etc/ssl/CA/CasjaysDev/certs/ca.crt" ]; then
HOST_SSL_CA="/etc/ssl/CA/CasjaysDev/certs/ca.crt"
fi
fi
if [ -z "$HOST_SSL_CRT" ]; then
if [ -f "/etc/letsencrypt/live/domain/fullchain.pem" ]; then
HOST_SSL_CRT="/etc/letsencrypt/live/domain/fullchain.pem"
elif [ -f "/etc/ssl/CA/CasjaysDev/certs/localhost.crt" ]; then
HOST_SSL_CRT="/etc/ssl/CA/CasjaysDev/certs/localhost.crt"
fi
fi
if [ -z "$HOST_SSL_KEY" ]; then
if [ -f "/etc/letsencrypt/live/domain/privkey.pem" ]; then
HOST_SSL_KEY="/etc/letsencrypt/live/domain/privkey.pem"
elif [ -f "/etc/ssl/CA/CasjaysDev/private/localhost.key" ]; then
HOST_SSL_KEY="/etc/ssl/CA/CasjaysDev/private/localhost.key"
fi
fi
if [ -n "$HOST_SSL_CA" ]; then
HOST_SSL_CA="$(realpath "$HOST_SSL_CA")"
fi
if [ -n "$HOST_SSL_CRT" ]; then
HOST_SSL_CRT="$(realpath "$HOST_SSL_CRT")"
fi
if [ -n "$HOST_SSL_KEY" ]; then
HOST_SSL_KEY="$(realpath "$HOST_SSL_KEY")"
fi
SSL_ENABLED="yes"
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Setup arrays/empty variables
PRETTY_PORT=""
SET_WEB_PORT_TMP=()
SET_CAPABILITIES=()
DOCKER_SET_OPTIONS=()
CONTAINER_ENV_PORTS=()
DOCKER_SET_TMP_PUBLISH=()
NGINX_REPLACE_INCLUDE=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Ensure that the image has a tag
if [ -z "$HUB_IMAGE_TAG" ]; then
HUB_IMAGE_TAG="latest"
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -z "$HUB_IMAGE_URL" ] || [ "$HUB_IMAGE_URL" = " " ]; then
printf_exit "Please set the url to the containers image"
elif echo "$HUB_IMAGE_URL" | grep -q ':'; then
HUB_IMAGE_URL="$(echo "$HUB_IMAGE_URL" | awk -F':' '{print $1}')"
HUB_IMAGE_TAG="${HUB_IMAGE_TAG:-$(echo "$HUB_IMAGE_URL" | awk -F':' '{print $2}')}"
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set containers name
if [ -z "$CONTAINER_NAME" ]; then
CONTAINER_NAME="$(__container_name || echo "${HUB_IMAGE_URL//\/-/}-$HUB_IMAGE_TAG")"
fi
DOCKER_SET_OPTIONS+=("--name=$CONTAINER_NAME")
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Setup time zone
if [ -z "$CONTAINER_TIMEZONE" ]; then
CONTAINER_TIMEZONE="America/New_York"
fi
DOCKER_SET_OPTIONS+=("--env TZ=$CONTAINER_TIMEZONE")
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# set working dir
if [ -n "$CONTAINER_WORK_DIR" ]; then
DOCKER_SET_OPTIONS+=("--workdir $CONTAINER_WORK_DIR")
DOCKER_SET_OPTIONS+=("--env WORKDIR=$CONTAINER_WORK_DIR")
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set the html directory
if [ -n "$CONTAINER_HTML_DIR" ]; then
if [ -z "$CONTAINER_HTML_ENV" ]; then
CONTAINER_HTML_ENV="WWW_ROOT_DIR"
fi
DOCKER_SET_OPTIONS+=("--env $CONTAINER_HTML_ENV=$CONTAINER_HTML_DIR")
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set user ID
if [ "$USER_ID_ENABLED" = "yes" ]; then
if [ -z "$CONTAINER_USER_ID" ]; then
DOCKER_SET_OPTIONS+=("--env PUID=$(id -u)")
else
DOCKER_SET_OPTIONS+=("--env PUID=$CONTAINER_USER_ID")
fi
if [ -z "$CONTAINER_GROUP_ID" ]; then
DOCKER_SET_OPTIONS+=("--env PGID=$(id -g)")
else
DOCKER_SET_OPTIONS+=("--env PGID=$CONTAINER_GROUP_ID")
fi
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set the process owner
if [ -n "$CONTAINER_USER_RUN" ]; then
DOCKER_SET_OPTIONS+=("--env USER=$CONTAINER_USER_RUN")
DOCKER_SET_OPTIONS+=("--env SERVICE_USER=$CONTAINER_USER_RUN")
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Run the container privileged
if [ "$CONTAINER_PRIVILEGED_ENABLED" = "yes" ]; then
DOCKER_SET_OPTIONS+=("--privileged")
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set ram size
if [ -n "$CONTAINER_RAM_SIZE" ]; then
CONTAINER_RAM_SIZE=$((1024 * 1024 * $CONTAINER_RAM_SIZE))
DOCKER_SET_OPTIONS+=("--memory $CONTAINER_RAM_SIZE")
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set swap size
if [ -n "$CONTAINER_SWAP_SIZE" ]; then
CONTAINER_SWAP_SIZE=$((1024 * 1024 * $CONTAINER_SWAP_SIZE))
DOCKER_SET_OPTIONS+=("--memory-swap $CONTAINER_SWAP_SIZE")
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set CPU count
if [ -z "$CONTAINER_CPU_COUNT" ] && [ -f "/proc/cpuinfo" ]; then
CONTAINER_CPU_COUNT="$(grep -c '^processor' /proc/cpuinfo || echo '1')"
fi
if [ -n "$CONTAINER_CPU_COUNT" ]; then
DOCKER_SET_OPTIONS+=("--cpus $CONTAINER_CPU_COUNT")
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set the containers SHM size
if [ -z "$CONTAINER_SHM_SIZE" ]; then
DOCKER_SET_OPTIONS+=("--shm-size=128M")
else
DOCKER_SET_OPTIONS+=("--shm-size=$CONTAINER_SHM_SIZE")
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Auto restart the container
if [ -z "$CONTAINER_AUTO_RESTART" ]; then
DOCKER_SET_OPTIONS+=("--restart unless-stopped")
else
DOCKER_SET_OPTIONS+=("--restart=$CONTAINER_AUTO_RESTART")
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Only run the container to execute command and then delete
if [ "$CONTAINER_AUTO_DELETE" = "yes" ]; then
DOCKER_SET_OPTIONS+=("--rm")
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Enable the tty
if [ "$CONTAINER_TTY_ENABLED" = "yes" ]; then
DOCKER_SET_OPTIONS+=("--tty")
fi