From 429a32110448bb9db45419f08bc24ab59adca600 Mon Sep 17 00:00:00 2001 From: casjay Date: Fri, 6 Sep 2024 16:00:47 -0400 Subject: [PATCH] =?UTF-8?q?=20=F0=9F=A6=88=F0=9F=8F=A0=F0=9F=90=9C?= =?UTF-8?q?=E2=9D=97=20Initial=20Commit=20=E2=9D=97=F0=9F=90=9C?= =?UTF-8?q?=F0=9F=A6=88=F0=9F=8F=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitattributes | 98 ++ .gitignore | 98 ++ LICENSE.md | 13 + README.md | 78 ++ install.sh | 2630 ++++++++++++++++++++++++++++++++++++++++ nginx/.gitkeep | 0 nginx/proxy.conf | 89 ++ rootfs/config/.gitkeep | 0 rootfs/data/.gitkeep | 0 9 files changed, 3006 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 LICENSE.md create mode 100644 README.md create mode 100755 install.sh create mode 100644 nginx/.gitkeep create mode 100644 nginx/proxy.conf create mode 100644 rootfs/config/.gitkeep create mode 100644 rootfs/data/.gitkeep diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8aec01c --- /dev/null +++ b/.gitattributes @@ -0,0 +1,98 @@ +# Template generated on Fri Sep 6 08:05:19 AM EDT 2024 from https://github.com/alexkaratarakis/gitattributes" +# Common settings that generally should always be used with your language specific settings +# Auto detect text files and perform LF normalization +* text=auto +# The above will handle all files NOT found below +# Documents +*.bibtex text diff=bibtex +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain +*.md text diff=markdown +*.mdx text diff=markdown +*.tex text diff=tex +*.adoc text +*.textile text +*.mustache text +*.csv text eol=crlf +*.tab text +*.tsv text +*.txt text +*.sql text +*.epub diff=astextplain +# Graphics +*.png binary +*.jpg binary +*.jpeg binary +*.gif binary +*.tif binary +*.tiff binary +*.ico binary +# SVG treated as text by default. +*.svg text +# If you want to treat it as binary, +# use the following line instead. +# *.svg binary +*.eps binary +# Scripts +*.bash text eol=lf +*.fish text eol=lf +*.ksh text eol=lf +*.sh text eol=lf +*.zsh text eol=lf +# These are explicitly windows files and should use crlf +*.bat text eol=crlf +*.cmd text eol=crlf +*.ps1 text eol=crlf +# Serialisation +*.json text +*.toml text +*.xml text +*.yaml text +*.yml text +# Archives +*.7z binary +*.bz binary +*.bz2 binary +*.bzip2 binary +*.gz binary +*.lz binary +*.lzma binary +*.rar binary +*.tar binary +*.taz binary +*.tbz binary +*.tbz2 binary +*.tgz binary +*.tlz binary +*.txz binary +*.xz binary +*.Z binary +*.zip binary +*.zst binary +# Text files where line endings should be preserved +*.patch -text +# Exclude files from exporting +.gitattributes export-ignore +.gitignore export-ignore +.gitkeep export-ignore + +# Template generated on Fri Sep 6 08:05:19 AM EDT 2024 +# Files for git large file system +*.7z filter=lfs diff=lfs merge=lfs -text +*.gz filter=lfs diff=lfs merge=lfs -text +*.xz filter=lfs diff=lfs merge=lfs -text +*.tar filter=lfs diff=lfs merge=lfs -text +*.bz2 filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.rpm filter=lfs diff=lfs merge=lfs -text +*.7zip filter=lfs diff=lfs merge=lfs -text +*.bzip2 filter=lfs diff=lfs merge=lfs -text + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..40bad41 --- /dev/null +++ b/.gitignore @@ -0,0 +1,98 @@ +# gitignore created on 09/06/24 at 15:53 +# Disable reminder in prompt +ignoredirmessage + +# OS generated files +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### macOS ### +# General +.DS_Store? +.AppleDouble +.LSOverride + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### macOS Patch ### +# iCloud generated files +*.icloud + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# misc +!*/README* +!inc/main.bash + +# Windows shortcuts +*.lnk + +# ignore commit message +**/.gitcommit + +# ignore .build_failed files +**/.build_failed* + + +# ignore .bak files +**/*.bak + +# ignore .no_push files +**/.no_push + +# ignore .no_git files +**/.no_git + +# ignore .installed files +**/.installed + diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..c76e83f --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,13 @@ + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2024 casjay + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 1. You just DO WHAT THE FUCK YOU WANT TO. diff --git a/README.md b/README.md new file mode 100644 index 0000000..debd548 --- /dev/null +++ b/README.md @@ -0,0 +1,78 @@ +## 👋 Welcome to remotely 🚀 + +remotely README + + +## Install my system scripts + +```shell + sudo bash -c "$(curl -q -LSsf "https://github.com/systemmgr/installer/raw/main/install.sh")" + sudo systemmgr --config && sudo systemmgr install scripts +``` + +## Automatic install/update + +```shell +dockermgr update remotely +``` + +## Install and run container + +```shell +mkdir -p "$HOME/.local/share/srv/docker/remotely/rootfs" +git clone "https://github.com/dockermgr/remotely" "$HOME/.local/share/CasjaysDev/dockermgr/remotely" +cp -Rfva "$HOME/.local/share/CasjaysDev/dockermgr/remotely/rootfs/." "$HOME/.local/share/srv/docker/remotely/rootfs/" +docker run -d \ +--restart always \ +--privileged \ +--name casjaysdevdocker-remotely \ +--hostname remotely \ +-e TZ=${TIMEZONE:-America/New_York} \ +-v "$HOME/.local/share/srv/docker/casjaysdevdocker-remotely/rootfs/data:/data:z" \ +-v "$HOME/.local/share/srv/docker/casjaysdevdocker-remotely/rootfs/config:/config:z" \ +-p 80:80 \ +casjaysdevdocker/remotely:latest +``` + +## via docker-compose + +```yaml +version: "2" +services: + ProjectName: + image: casjaysdevdocker/remotely + container_name: casjaysdevdocker-remotely + environment: + - TZ=America/New_York + - HOSTNAME=remotely + volumes: + - "$HOME/.local/share/srv/docker/casjaysdevdocker-remotely/rootfs/data:/data:z" + - "$HOME/.local/share/srv/docker/casjaysdevdocker-remotely/rootfs/config:/config:z" + ports: + - 80:80 + restart: always +``` + +## Get source files + +```shell +dockermgr download src casjaysdevdocker/remotely +``` + +OR + +```shell +git clone "https://github.com/casjaysdevdocker/remotely" "$HOME/Projects/github/casjaysdevdocker/remotely" +``` + +## Build container + +```shell +cd "$HOME/Projects/github/casjaysdevdocker/remotely" +buildx +``` + +## Authors + +🤖 casjay: [Github](https://github.com/casjay) 🤖 +⛵ casjaysdevdocker: [Github](https://github.com/casjaysdevdocker) [Docker](https://hub.docker.com/u/casjaysdevdocker) ⛵ diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..f3714a1 --- /dev/null +++ b/install.sh @@ -0,0 +1,2630 @@ +#!/usr/bin/env bash +# shellcheck shell=bash +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +##@Version : 202409061553-git +# @@Author : Jason Hempstead +# @@Contact : jason@casjaysdev.pro +# @@License : LICENSE.md +# @@ReadME : install.sh --help +# @@Copyright : Copyright: (c) 2024 Jason Hempstead, Casjays Developments +# @@Created : Friday, Sep 06, 2024 15:53 EDT +# @@File : install.sh +# @@Description : Container installer script for remotely +# @@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=SC2016 +# shellcheck disable=SC2031 +# shellcheck disable=SC2120 +# shellcheck disable=SC2155 +# shellcheck disable=SC2199 +# shellcheck disable=SC2317 +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +APPNAME="remotely" +VERSION="202409061553-git" +REPO_BRANCH="${GIT_REPO_BRANCH:-main}" +USER="${SUDO_USER:-$USER}" +RUN_USER="${RUN_USER:-$USER}" +USER_HOME="${USER_HOME:-$HOME}" +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 -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 +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Repository variables +REPO="${DOCKERMGRREPO:-https://github.com/$SCRIPTS_PREFIX}/remotely" +APPVERSION="$(__appversion "$REPO/raw/$REPO_BRANCH/version.txt")" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Defaults variables +APPNAME="remotely" +export INSTDIR="$HOME/.local/share/CasjaysDev/$SCRIPTS_PREFIX/remotely" +export DOCKERMGR_CONFIG_DIR="${DOCKERMGR_CONFIG_DIR:-$HOME/.config/myscripts/$SCRIPTS_PREFIX}" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Set the mountpoint directory +export APPDIR="$HOME/.local/share/srv/docker/remotely" +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; } +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# printf_space spacing color message value +__printf_space() { + test -n "$1" && test -z "${1//[0-9]/}" && local padl="$1" && shift 1 || local padl="40" + test -n "$1" && test -z "${1//[0-9]/}" && local color="$1" && shift 1 || local color="7" + local string1="$1" + local string2="$2" + local pads=$(printf '%0.1s' " "{1..60}) + local message="$(printf "%b" "$(tput setaf "$color" 2>/dev/null)")" + message+="$(printf '%s' "$string1") " + message+="$(printf '%*.*s' 0 $((padl - ${#string1} - ${#string2})) "$pads") " + message+="$(printf '%s' "$string2") " + message+="$(printf '%b\n' "$(tput sgr0 2>/dev/null)")" + printf '%s\n' "$message" +} +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +__printf_spacing_file() { __printf_space "$1" "7" "$2" "$3"; } +__printf_spacing_color() { __printf_space "$1" "$2" "$3" "$4"; } +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +__cmd_exists() { type -P $1 &>/dev/null || return 1; } +__remove_extra_spaces() { sed 's/\( \)*/\1/g;s|^ ||g'; } +__port() { echo "$((50000 + $RANDOM % 1000))" | grep '^' || 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; } +__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)); } +__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 -i "$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"; } +__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; } +__domain_name() { hostname -d 2>/dev/null | grep -F '.' | grep '^' || hostname -f 2>/dev/null | grep -w '.' | awk -F '.' '{print $(NF-1)"."$NF}' | __grep_char || return 1; } +__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/$APPNAME.${1:-custom}.conf" ] && cat "$DOCKERMGR_CONFIG_DIR/env/$APPNAME.${1:-custom}.conf" | grep -Ev '^$|^#' | grep '=' | grep '^' || __custom_docker_env | grep -Ev '^$|^#' | grep '=' | 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; } +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Ensure docker is installed and running +__docker_check || __docker_init +__docker_is_running || printf_exit "Docker is not running" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# hash the password +__hash_password() { + echo -n "$1" #| argon2 "$(openssl rand -base64 32)" -e -id -k 65540 -t 3 -p 4 +} +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Define any pre-install scripts +__run_pre_install() { + + 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="true" && shift 1 ;; + -s | --server) 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 +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Init only - This should be false +INIT_SCRIPT_ONLY="false" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +[ -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 -sc ^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="${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 || 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="" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# registry org +HUB_ORG="casjaysdevdocker" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# URL to container image - docker pull - [URL] +HUB_IMAGE_URL="$HUB_ORG/remotely" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# 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" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# 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] [/var/run/docker.sock] [yes/no] +DOCKER_SOCKET_ENABLED="no" +DOCKER_SOCKER_READONLY="yes" +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" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# /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 hostname and domain - Default: [remotely.$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/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] +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="" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# 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="5000" +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="/" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Specify custom nginx vhosts - autoconfigure: [all.name/name.all/name.mydomain/name.myhost] - [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 [.all:exter:inter/[tcp,udp] [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" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# 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" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# 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="" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# 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" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# If container has an admin password then set it here - [pass/random] +CONTAINER_USER_ADMIN_PASS_HASH="" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# 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="ASPNETCORE_ENVIRONMENT=Production,Remotely_ApplicationOptions__DbProvider=SQLite,Remotely_ConnectionStrings__SQLite='Data Source=//data/db/sqlite/remotely.db'" +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="no" +DOCKER_CAP_SYS_NICE="no" +DOCKER_CAP_NET_ADMIN="no" +DOCKER_CAP_SYS_MODULE="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,/data/logs/$APPNAME,/config/$APPNAME " +CONTAINER_CREATE_DIRECTORY+="" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# enable cron jobs +HOST_CRON_ENABLED="" +HOST_CRON_USER="root" +HOST_CRON_SCHEDULE="" +HOST_CRON_COMMAND="" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# 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" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Set custom container enviroment variables - [MYVAR="VAR"] +__custom_docker_env() { + cat </dev/null + +EOF +} +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +__dockermgr_variables() { + [ -d "$DOCKERMGR_CONFIG_DIR/env" ] || mkdir -p "$DOCKERMGR_CONFIG_DIR/env" + cat <"$DOCKERMGR_CONFIG_DIR/uninstall/$APPNAME" +NGINX_FILES="$(__trim "$NGINX_CONF_FILE $NGINX_INC_CONFIG $NGINX_VHOST_CONFIG $NGINX_INTERNAL_IS_SET")" +EOF +} +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Define extra functions +__custom_docker_clean_env() { grep -Ev '^$|^#' | sed 's|^|--env |g' | grep '\--' | grep -v '\--env \\' | tr '\n' ' ' | __remove_extra_spaces; } +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +__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 exec_docker_cmd create_docker_script_message_pre create_docker_script_message_post + replace_with="$HUB_IMAGE_URL:$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 </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 + $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 -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| '$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.env.conf" ] && . "$DOCKERMGR_CONFIG_DIR/env/$APPNAME.env.conf" +[ -f "$DOCKERMGR_CONFIG_DIR/env/$APPNAME.script.sh" ] && . "$DOCKERMGR_CONFIG_DIR/env/$APPNAME.script.sh" +[ -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 [ -n "$(type "$required" 2>/dev/null)" ] || [ -n "$(type -P "$required" 2>/dev/null)" ] || [ -e "$required" ]; then + required="" + else + __printf_color "6" "Installing required: $required" && pkmgr silent install $required &>/dev/null && required="" || 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 +INIT_SCRIPT_ONLY="${ENV_INIT_SCRIPT_ONLY:-$INIT_SCRIPT_ONLY}" +SET_LAN_DEV="${ENV_SET_LAN_DEV:-$SET_LAN_DEV}" +SET_LAN_IP="${ENV_SET_LAN_IP:-$SET_LAN_IP}" +SET_LOCAL_IP="$(__my_default_lan_address)" +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}" +HOST_NGINX_INTERNAL_HOST="${HOST_NGINX_INTERNAL_HOST:-${CONTAINER_HOSTNAME:-$APPNAME}}" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +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_SQLITE_ENABLED="${ENV_CONTAINER_SQLITE_ENABLED:-$CONTAINER_SQLITE_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}" +CONTAINER_USER_ADMIN_PASS_LENGTH="${ENV_CONTAINER_USER_ADMIN_PASS_LENGTH:-$CONTAINER_USER_ADMIN_PASS_LENGTH}" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +[ -n "$CONTAINER_OPT_HOSTNAME" ] && ENV_HOSTNAME="$CONTAINER_OPT_HOSTNAME" +[ -n "$CONTAINER_OPT_DOMAINNAME" ] && CONTAINER_DOMAINNAME="$CONTAINER_OPT_DOMAINNAME" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# 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}" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +CONTAINER_DOMAINNAME="${HOST_NGINX_EXTERNAL_DOMAIN:-$CONTAINER_DOMAINNAME}" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# 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") +DOCKER_SET_OPTIONS+=("--env ENV_CONTAINER_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 ENV_WORK_DIR=$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 +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +if [ -n "$DOCKER_MAX_LOG_FILE" ]; then + DOCKER_SET_OPTIONS+=("--log-opt max-size=$DOCKER_MAX_LOG_FILE") +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" ]; then + CONTAINER_CPU_COUNT="${SET_HOST_CORES:-$([ -f "/proc/cpuinfo" ] && grep -c '^processor' /proc/cpuinfo || echo '1')}" +fi +if [ -n "$CONTAINER_CPU_COUNT" ] && [ "$SET_HOST_CORES" -le "$CONTAINER_CPU_COUNT" ]; then + CONTAINER_CPU_COUNT="$SET_HOST_CORES" +fi +if [ -n "$CONTAINER_CPU_COUNT" ]; then + DOCKER_SET_OPTIONS+=("--cpus $CONTAINER_CPU_COUNT") +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# +if [ "$CONTAINER_PROXY_SIGNAL" = "no" ] || [ "$CONTAINER_PROXY_SIGNAL" = "false" ]; then + DOCKER_SET_OPTIONS+=("--sig-proxy=false") +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 +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Run in interactive mode +if [ "$CONTAINER_INTERACTIVE_ENABLED" = "yes" ]; then + DOCKER_SET_OPTIONS+=("--interactive") +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Mount cgroups in the container +if [ -e "$CGROUPS_MOUNTS" ] || [ -e "/sys/fs/cgroup" ]; then + if [ "$CGROUPS_ENABLED" = "yes" ]; then + if [ -z "$CGROUPS_MOUNTS" ]; then + DOCKER_SET_OPTIONS+=("--volume /sys/fs/cgroup:/sys/fs/cgroup:rw") + else + DOCKER_SET_OPTIONS+=("--volume $CGROUPS_MOUNTS") + fi + fi +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Mount the docker socket +if [ "$DOCKER_SOCKET_ENABLED" = "yes" ]; then + if [ -z "$DOCKER_SOCKET_MOUNT" ]; then + if [ -e "/var/run/docker.sock" ]; then + DOCKER_SOCKET_TMP_MOUNT="/var/run/docker.sock:/var/run/docker.sock" + elif [ -e "$DOCKER_SOCKET_MOUNT" ]; then + DOCKER_SOCKET_TMP_MOUNT="$DOCKER_SOCKET_MOUNT:/var/run/docker.sock" + fi + fi + if [ "$DOCKER_SOCKER_READONLY" = "yes" ]; then + DOCKER_SOCKET_TMP_MOUNT="$DOCKER_SOCKET_TMP_MOUNT:ro" + fi + DOCKER_SET_OPTIONS+=("--volume $DOCKER_SOCKET_TMP_MOUNT") + unset DOCKER_SOCKET_TMP_MOUNT +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Mount docker config in the container +if [ -r "$CONTAINER_DOCKER_CONFIG_FILE" ] || [ -r "$HOME/.docker/config.json" ]; then + if [ "$DOCKER_CONFIG_ENABLED" = "yes" ]; then + if [ -z "$CONTAINER_DOCKER_CONFIG_FILE" ]; then + CONTAINER_DOCKER_CONFIG_FILE="/root/.docker/config.json" + fi + if [ -n "$HOST_DOCKER_CONFIG" ]; then + DOCKER_SET_OPTIONS+=("--volume $HOST_DOCKER_CONFIG:$CONTAINER_DOCKER_CONFIG_FILE:ro") + elif [ -f "$HOME/.docker/config.json" ]; then + DOCKER_SET_OPTIONS+=("--volume $HOME/.docker/config.json:$CONTAINER_DOCKER_CONFIG_FILE:ro") + fi + fi +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Mount sound card in container +if [ -e "$HOST_SOUND_DEVICE_FILE" ] || [ -e "/dev/snd" ]; then + if [ "$DOCKER_SOUND_ENABLED" = "yes" ]; then + if [ -z "$HOST_SOUND_DEVICE_FILE" ]; then + HOST_SOUND_DEVICE_FILE="/dev/snd" + fi + if [ -z "$CONTAINER_SOUND_DEVICE_FILE" ]; then + CONTAINER_SOUND_DEVICE_FILE="/dev/snd" + fi + if [ -n "$HOST_SOUND_DEVICE_FILE" ] && [ -n "$CONTAINER_SOUND_DEVICE_FILE" ]; then + DOCKER_SET_OPTIONS+=("--device $HOST_SOUND_DEVICE_FILE:$CONTAINER_SOUND_DEVICE_FILE") + fi + fi +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# /lib/modules /proc /sys /dev mounts +if [ "$HOST_DEV_MOUNT_ENABLED" = "yes" ]; then + DOCKER_SET_OPTIONS+=("--volume /dev:/dev:z") +fi +if [ "$HOST_PROC_MOUNT_ENABLED" = "yes" ]; then + DOCKER_SET_OPTIONS+=("--volume /proc:/proc:z") +fi +if [ "$HOST_SYS_MOUNT_ENABLED" = "yes" ]; then + DOCKER_SET_OPTIONS+=("--volume /sys:/sys:z") +fi +if [ "$HOST_MODULES_MOUNT_ENABLED" = "yes" ]; then + DOCKER_SET_OPTIONS+=("--volume /lib/modules:/lib/modules:z") +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# set password length +if [ -n "$CONTAINER_USER_ADMIN_PASS_HASH" ]; then + if [ "$CONTAINER_USER_ADMIN_PASS_HASH" = "random" ]; then + CONTAINER_USER_ADMIN_PASS_RAW="$(__password 32)" + CONTAINER_USER_ADMIN_PASS_HASH="$(__hash_password $CONTAINER_USER_ADMIN_PASS_RAW)" + fi + CONTAINER_USER_ADMIN_PASS_RAW="${CONTAINER_USER_ADMIN_PASS_RAW:-$CONTAINER_USER_ADMIN_PASS_HASH}" + CONTAINER_USER_ADMIN_PASS_HASH="${CONTAINER_USER_ADMIN_PASS_HASH:-$(__hash_password $CONTAINER_USER_ADMIN_PASS_RAW)}" +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Setup display if enabled +if [ "$CONTAINER_X11_ENABLED" = "yes" ]; then + if [ -z "$HOST_X11_DISPLAY" ] && [ -n "$DISPLAY" ]; then + HOST_X11_DISPLAY="${DISPLAY//*:/}" + fi + if [ -z "$HOST_X11_SOCKET" ]; then + HOST_X11_SOCKET="/tmp/.X11-unix" + fi + if [ -z "$HOST_X11_XAUTH" ]; then + HOST_X11_XAUTH="$HOME/.Xauthority" + fi + [ -f "/tmp/.X11-unix" ] || unset HOST_X11_SOCKET + [ -f "$HOME/.Xauthority" ] || unset HOST_X11_XAUTH + if [ -n "$HOST_X11_DISPLAY" ] && [ -n "$HOST_X11_SOCKET" ] && [ -n "$HOST_X11_XAUTH" ]; then + DOCKER_SET_OPTIONS+=("--env DISPLAY=:$HOST_X11_DISPLAY") + DOCKER_SET_OPTIONS+=("--volume $HOST_X11_SOCKET:${CONTAINER_X11_SOCKET:-/tmp/.X11-unix}") + DOCKER_SET_OPTIONS+=("--volume $HOST_X11_XAUTH:${CONTAINER_X11_XAUTH:-/home/x11user/.Xauthority}") + fi +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Setup containers hostname +if __is_server && [ -z "$CONTAINER_HOSTNAME" ]; then + CONTAINER_DOMAINNAME="$SET_HOST_FULL_DOMAIN" +else + CONTAINER_DOMAINNAME="${CONTAINER_DOMAINNAME:-$SET_HOST_FULL_DOMAIN}" +fi +CONTAINER_HOSTNAME="${CONTAINER_HOSTNAME:-${APPNAME:-remotely}}" +echo "$CONTAINER_HOSTNAME" | grep -q "$CONTAINER_DOMAINNAME" || CONTAINER_HOSTNAME="$CONTAINER_HOSTNAME.$CONTAINER_DOMAINNAME" +if [ -n "$CONTAINER_HOSTNAME" ]; then + DOCKER_SET_OPTIONS+=("--hostname $CONTAINER_HOSTNAME") + DOCKER_SET_OPTIONS+=("--env HOSTNAME=$CONTAINER_HOSTNAME") +else + DOCKER_SET_OPTIONS+=("--hostname $CONTAINER_NAME") + DOCKER_SET_OPTIONS+=("--env HOSTNAME=$CONTAINER_NAME") +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Set the domain name +if [ -n "$CONTAINER_DOMAINNAME" ]; then + DOCKER_SET_OPTIONS+=("--domainname $CONTAINER_DOMAINNAME") + DOCKER_SET_OPTIONS+=("--env DOMAINNAME=$CONTAINER_DOMAINNAME") +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Set the docker network +if [ "$HOST_DOCKER_NETWORK" = "host" ]; then + DOCKER_SET_OPTIONS+=("--net-host") +else + if [ -z "$HOST_DOCKER_NETWORK" ]; then + HOST_DOCKER_NETWORK="bridge" + fi + DOCKER_SET_OPTIONS+=("--network $HOST_DOCKER_NETWORK") +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Create network if needed +DOCKER_CREATE_NET="$(__docker_net_create)" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Set nginx directory +if [ -z "$NGINX_DIR" ]; then + NGINX_DIR="$HOME/.config/nginx" +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Container listen address [address:extPort:intPort] +HOST_DEFAULT_IP="${SET_LOCAL_IP:-$SET_LAN_IP}" +HOST_LISTEN_ADDR="${HOST_LISTEN_ADDR:-$SET_LAN_IP}" +if [ "$HOST_NETWORK_ADDR" = "yes" ] || [ "$HOST_NETWORK_ADDR" = "lan" ]; then + HOST_DEFINE_LISTEN="$SET_LAN_IP" + HOST_LISTEN_ADDR="$SET_LAN_IP" +elif [ "$HOST_NETWORK_ADDR" = "public" ] || [ "$HOST_NETWORK_ADDR" = "all" ]; then + if connect_test && __test_public_reachable; then + HOST_DEFINE_LISTEN="0.0.0.0" + HOST_LISTEN_ADDR=$(__public_ip -4) + else + HOST_DEFINE_LISTEN="$HOST_DEFAULT_IP" + HOST_LISTEN_ADDR="$HOST_DEFAULT_IP" + fi +elif [ "$HOST_NETWORK_ADDR" = "docker" ]; then + HOST_DEFINE_LISTEN="$SET_DOCKER_IP" + HOST_LISTEN_ADDR="$SET_DOCKER_IP" +elif [ "$HOST_NETWORK_ADDR" = "local" ]; then + HOST_DEFINE_LISTEN="127.0.0.1" + HOST_LISTEN_ADDR="127.0.0.1" + CONTAINER_PRIVATE="yes" +else + HOST_DEFINE_LISTEN="0.0.0.0" + HOST_LISTEN_ADDR="$HOST_DEFAULT_IP" +fi +HOST_DEFINE_LISTEN="${HOST_DEFINE_LISTEN:-0.0.0.0}" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Setup the listen address +if [ -n "$HOST_DEFINE_LISTEN" ]; then + HOST_LISTEN_ADDR="${HOST_DEFINE_LISTEN//:*/}" +fi +HOST_LISTEN_ADDR="${HOST_LISTEN_ADDR:-$HOST_DEFINE_LISTEN}" +HOST_LISTEN_ADDR="${HOST_LISTEN_ADDR//0.0.0.0/$SET_LAN_IP}" +HOST_LISTEN_ADDR="${HOST_LISTEN_ADDR//:*/}" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# # nginx +NGINX_VHOSTS_CONF_FILE_TMP="/tmp/$$.$APPNAME.conf" +NGINX_VHOSTS_INC_FILE_TMP="/tmp/$$.$APPNAME.inc.conf" +NGINX_VHOSTS_PROXY_FILE_TMP="/tmp/$$.$APPNAME.custom.conf" +NINGX_WRITABLE="$(sudo -n true && sudo bash -c '[ -w "/etc/nginx" ] && echo "true" || false' || echo 'false')" +if [ "$HOST_NGINX_ENABLED" = "yes" ]; then + if [ -f "/etc/nginx/nginx.conf" ] && [ "$NINGX_WRITABLE" = "true" ]; then + NGINX_DIR="/etc/nginx" + else + NGINX_DIR="$HOME/.config/nginx" + fi + if [ -n "$HOST_NGINX_HTTPS_PORT" ]; then + NGINX_LISTEN_OPTS="ssl http2" + NGINX_PORT="${HOST_NGINX_HTTPS_PORT:-443}" + else + NGINX_PORT="${HOST_NGINX_HTTP_PORT:-80}" + fi + if [ "$CONTAINER_WEB_SERVER_AUTH_ENABLED" = "yes" ]; then + NGINX_AUTH_DIR="$NGINX_DIR/auth" + CONTAINER_USER_NAME="${CONTAINER_USER_NAME:-root}" + CONTAINER_USER_PASS="${CONTAINER_USER_PASS:-$RANDOM_PASS}" + if [ ! -d "$NGINX_AUTH_DIR" ]; then + mkdir -p "$NGINX_AUTH_DIR" + fi + if [ -n "$(builtin type -P htpasswd)" ]; then + if ! grep -q "$CONTAINER_USER_NAME"; then + __printf_color "3" "Creating auth $NGINX_AUTH_DIR/$APPNAME" + if [ -f "$NGINX_AUTH_DIR/$APPNAME" ]; then + htpasswd -b "$NGINX_AUTH_DIR/$APPNAME" "$CONTAINER_USER_NAME" "$CONTAINER_USER_PASS" &>/dev/null + else + htpasswd -b -c "$NGINX_AUTH_DIR/$APPNAME" "$CONTAINER_USER_NAME" "$CONTAINER_USER_PASS" &>/dev/null + fi + fi + fi + fi + if [ "$HOST_NGINX_UPDATE_CONF" = "yes" ]; then + mkdir -p "$NGINX_DIR/vhosts.d" + fi + if [ ! -f "$NGINX_MAIN_CONFIG" ]; then + HOST_NGINX_UPDATE_CONF="yes" + fi +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Setup containers web server +if [ "$CONTAINER_WEB_SERVER_ENABLED" = "yes" ]; then + if [ "$NGINX_PROXY_ADDRESS" = "0.0.0.0" ]; then + NGINX_PROXY_ADDRESS="127.0.0.1" + else + NGINX_PROXY_ADDRESS="${CONTAINER_WEB_SERVER_LISTEN_ON:-$HOST_LISTEN_ADDR}" + fi + if [ "$CONTAINER_WEB_SERVER_SSL_ENABLED" = "yes" ] || [ "$SSL_ENABLED" = "yes" ]; then + DOCKER_SET_OPTIONS+=("--env SSL_ENABLED=true") + fi + if [ -n "$CONTAINER_WEB_SERVER_INT_PORT" ]; then + CONTAINER_WEB_SERVER_INT_PORT="${CONTAINER_WEB_SERVER_INT_PORT//,/ }" + DOCKER_SET_OPTIONS+=("--env WEB_PORT=\"$CONTAINER_WEB_SERVER_INT_PORT\"") + fi + if [ "$CONTAINER_WEB_SERVER_SSL_ENABLED" = "yes" ]; then + CONTAINER_PROTOCOL="https" + else + CONTAINER_PROTOCOL="http" + fi + if [ -z "$CONTAINER_WEB_SERVER_LISTEN_ON" ]; then + CONTAINER_WEB_SERVER_LISTEN_ON="$HOST_LISTEN_ADDR" + fi +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# +if [ "$CONTAINER_HTTPS_PORT" != "" ]; then + CONTAINER_PROTOCOL="https" +fi +DOCKER_SET_OPTIONS+=("--env CONTAINER_PROTOCOL=$CONTAINER_PROTOCOL") +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Setup easy port settings +if [ "$CONTAINER_SERVICE_PUBLIC" = "yes" ] || [ "$CONTAINER_SERVICE_PUBLIC" = "0.0.0.0" ]; then + CONTAINER_SERVICE_PUBLIC="0.0.0.0" +elif echo "$CONTAINER_SERVICE_PUBLIC" | grep -q '[0-9].*\.[0-9].*\.[0-9].*\.[0-9]'; then + true +else + CONTAINER_SERVICE_PUBLIC="127.0.0.1" +fi +if [ "$CONTAINER_IS_DNS_SERVER" = "yes" ]; then + service_port="$(__netstat "53" | grep -v 'docker' && __port || echo "53")" + DOCKER_SET_TMP_PUBLISH+=("--publish $CONTAINER_SERVICE_PUBLIC:$service_port:53/udp") + DOCKER_SET_TMP_PUBLISH+=("--publish $CONTAINER_SERVICE_PUBLIC:$service_port:53/tcp") + unset service_port +fi +if [ "$CONTAINER_IS_DHCP_SERVER" = "yes" ]; then + service_port="$(__netstat "67" | grep -v 'docker' && __port || echo "67")" + DOCKER_SET_TMP_PUBLISH+=("--publish $CONTAINER_SERVICE_PUBLIC:$service_port:67/udp") + service_port="$(__netstat "68" | grep -v 'docker' && __port || echo "68")" + DOCKER_SET_TMP_PUBLISH+=("--publish $CONTAINER_SERVICE_PUBLIC:$service_port:68/udp") + unset service_port +fi +if [ "$CONTAINER_IS_TFTP_SERVER" = "yes" ]; then + service_port="$(__netstat "69" | grep -v 'docker' && __port || echo "69")" + DOCKER_SET_TMP_PUBLISH+=("--publish $CONTAINER_SERVICE_PUBLIC:$service_port:69/udp") + unset service_port +fi +if [ "$CONTAINER_IS_SMTP_SERVER" = "yes" ]; then + service_port="$(__netstat "25" | grep -v 'docker' && __port || echo "25")" + DOCKER_SET_TMP_PUBLISH+=("--publish $CONTAINER_SERVICE_PUBLIC:$service_port:25/tcp") + service_port="$(__netstat "465" | grep -v 'docker' && __port || echo "465")" + DOCKER_SET_TMP_PUBLISH+=("--publish $CONTAINER_SERVICE_PUBLIC:$service_port:465/tcp") + service_port="$(__netstat "587" | grep -v 'docker' && __port || echo "587")" + DOCKER_SET_TMP_PUBLISH+=("--publish $CONTAINER_SERVICE_PUBLIC:$service_port:587/tcp") + unset service_port +fi +if [ "$CONTAINER_IS_POP3_SERVER" = "yes" ]; then + service_port="$(__netstat "110" | grep -v 'docker' && __port || echo "110")" + DOCKER_SET_TMP_PUBLISH+=("--publish $CONTAINER_SERVICE_PUBLIC:$service_port:110/tcp") + service_port="$(__netstat "995" | grep -v 'docker' && __port || echo "995")" + DOCKER_SET_TMP_PUBLISH+=("--publish $CONTAINER_SERVICE_PUBLIC:$service_port:995/tcp") + unset service_port +fi +if [ "$CONTAINER_IS_IMAP_SERVER" = "yes" ]; then + service_port="$(__netstat "143" | grep -v 'docker' && __port || echo "143")" + DOCKER_SET_TMP_PUBLISH+=("--publish $CONTAINER_SERVICE_PUBLIC:$service_port:143/tcp") + service_port="$(__netstat "993" | grep -v 'docker' && __port || echo "993")" + DOCKER_SET_TMP_PUBLISH+=("--publish $CONTAINER_SERVICE_PUBLIC:$service_port:993/tcp") + unset service_port +fi +if [ "$CONTAINER_IS_TIME_SERVER" = "yes" ]; then + service_port="$(__netstat "123" | grep -v 'docker' && __port || echo "123")" + DOCKER_SET_TMP_PUBLISH+=("--publish $CONTAINER_SERVICE_PUBLIC:$service_port:123/udp") + DOCKER_SET_TMP_PUBLISH+=("--publish $CONTAINER_SERVICE_PUBLIC:$service_port:123/tcp") + unset service_port +fi +if [ "$CONTAINER_IS_TIME_SERVER" = "yes" ]; then + service_port="$(__netstat "119" | grep -v 'docker' && __port || echo "119")" + DOCKER_SET_TMP_PUBLISH+=("--publish $CONTAINER_SERVICE_PUBLIC:$service_port:119/tcp") + service_port="$(__netstat "433" | grep -v 'docker' && __port || echo "433")" + DOCKER_SET_TMP_PUBLISH+=("--publish $CONTAINER_SERVICE_PUBLIC:$service_port:433/tcp") + unset service_port +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Database setup +if [ -n "$CONTAINER_DEFAULT_DATABASE_TYPE" ]; then + DOCKER_SET_OPTIONS+=("--env CONTAINER_DEFAULT_DATABASE_TYPE=$CONTAINER_DEFAULT_DATABASE_TYPE") +fi +if [ -z "$CONTAINER_DATABASE_LISTEN" ]; then + CONTAINER_DATABASE_LISTEN="0.0.0.0" +fi +if [ -z "$DATABASE_BASE_DIR" ]; then + DATABASE_BASE_DIR="/data/db" + DOCKER_SET_OPTIONS+=("--env DATABASE_BASE_DIR=$DATABASE_BASE_DIR") +fi +if [ "$CONTAINER_CUSTOM_DATABASE_ENABLED" = "yes" ] && [ -n "$CONTAINER_CUSTOM_DATABASE_NAME" ]; then + SHOW_DATABASE_INFO="true" + CONTAINER_DATABASE_ENABLED="yes" + DATABASE_DIR_CUSTOM="${CONTAINER_CUSTOM_DATABASE_DIR:-$DATABASE_BASE_DIR/$CONTAINER_CUSTOM_DATABASE_NAME}" + DOCKER_SET_OPTIONS+=("--volume $LOCAL_DATA_DIR/db/$DATABASE_DIR_CUSTOM:$DATABASE_DIR_CUSTOM:z") + DOCKER_SET_OPTIONS+=("--env DATABASE_DIR_CUSTOM=$DATABASE_DIR_CUSTOM") + CONTAINER_CUSTOM_DATABASE_PROTOCOL="${CONTAINER_CUSTOM_DATABASE_PROTOCOL:-file}" + if echo "$CONTAINER_CUSTOM_DATABASE_PORT" | grep -q "^[0-9][0-9]"; then + DOCKER_SET_TMP_PUBLISH+=("--publish $CONTAINER_DATABASE_LISTEN:$CONTAINER_CUSTOM_DATABASE_PORT:$CONTAINER_CUSTOM_DATABASE_PORT") + CONTAINER_DATABASE_PROTO="$CONTAINER_CUSTOM_DATABASE_PROTOCOL://$HOST_LISTEN_ADDR:$CONTAINER_CUSTOM_DATABASE_PORT" + else + CONTAINER_DATABASE_PROTO="file:///$DATABASE_DIR_CUSTOM/" + fi + MESSAGE_CONTAINER_DATABASE="true" +fi +if [ "$CONTAINER_REDIS_ENABLED" = "yes" ]; then + SHOW_DATABASE_INFO="true" + CONTAINER_DATABASE_ENABLED="yes" + CONTAINER_DATABASE_PROTO="redis://$HOST_LISTEN_ADDR:6379" + DOCKER_SET_TMP_PUBLISH+=("--publish $CONTAINER_DATABASE_LISTEN:6379:6379") + DATABASE_DIR_REDIS="${DATABASE_DIR_REDIS:-$DATABASE_BASE_DIR/redis}" + DOCKER_SET_OPTIONS+=("--volume $LOCAL_DATA_DIR/db/redis:$DATABASE_DIR_REDIS:z") + DOCKER_SET_OPTIONS+=("--env DATABASE_DIR_REDIS=$DATABASE_DIR_REDIS") + MESSAGE_REDIS="true" +fi +if [ "$CONTAINER_SQLITE_ENABLED" = "yes" ]; then + SHOW_DATABASE_INFO="true" + CONTAINER_DATABASE_ENABLED="yes" + DATABASE_DIR_SQLITE="${DATABASE_DIR_SQLITE:-$DATABASE_BASE_DIR/sqlite}" + DOCKER_SET_OPTIONS+=("--volume $LOCAL_DATA_DIR/db/sqlite:$DATABASE_DIR_SQLITE:z") + DOCKER_SET_OPTIONS+=("--env DATABASE_DIR_SQLITE=$DATABASE_DIR_SQLITE") + CONTAINER_DATABASE_PROTO="sqlite://$DATABASE_DIR_SQLITE" + [ -d "$DATADIR/$DATABASE_DIR_SQLITE" ] || CONTAINER_CREATE_DIRECTORY+=",$DATABASE_DIR_SQLITE" + MESSAGE_SQLITE="true" +fi +if [ "$CONTAINER_POSTGRES_ENABLED" = "yes" ]; then + SHOW_DATABASE_INFO="true" + CONTAINER_DATABASE_ENABLED="yes" + DOCKER_SET_TMP_PUBLISH+=("--publish $CONTAINER_DATABASE_LISTEN:5432:5432") + DATABASE_DIR_POSTGRES="${DATABASE_DIR_POSTGRES:-$DATABASE_BASE_DIR/postgres}" + DOCKER_SET_OPTIONS+=("--volume $LOCAL_DATA_DIR/db/postgres:$DATABASE_DIR_POSTGRES:z") + DOCKER_SET_OPTIONS+=("--env DATABASE_DIR_POSTGRES=$DATABASE_DIR_POSTGRES") + CONTAINER_DATABASE_PROTO="postgresql://$HOST_LISTEN_ADDR:5432" + MESSAGE_PGSQL="true" +fi +if [ "$CONTAINER_MARIADB_ENABLED" = "yes" ]; then + SHOW_DATABASE_INFO="true" + CONTAINER_DATABASE_ENABLED="yes" + DOCKER_SET_TMP_PUBLISH+=("--publish $CONTAINER_DATABASE_LISTEN:3306:3306") + DATABASE_DIR_MARIADB="${DATABASE_DIR_MARIADB:-$DATABASE_BASE_DIR/mysql}" + DOCKER_SET_OPTIONS+=("--volume $LOCAL_DATA_DIR/db/mysql:$DATABASE_DIR_MARIADB:z") + DOCKER_SET_OPTIONS+=("--env DATABASE_DIR_MARIADB=$DATABASE_DIR_MARIADB") + CONTAINER_DATABASE_PROTO="mysql://$HOST_LISTEN_ADDR:3306" + MESSAGE_MARIADB="true" +fi +if [ "$CONTAINER_COUCHDB_ENABLED" = "yes" ]; then + SHOW_DATABASE_INFO="true" + CONTAINER_DATABASE_ENABLED="yes" + DOCKER_SET_TMP_PUBLISH+=("--publish $CONTAINER_DATABASE_LISTEN:5984:5984") + DATABASE_DIR_COUCHDB="${DATABASE_DIR_COUCHDB:-$DATABASE_BASE_DIR/couchdb}" + DOCKER_SET_OPTIONS+=("--volume $LOCAL_DATA_DIR/db/couchdb:$DATABASE_DIR_COUCHDB:z") + DOCKER_SET_OPTIONS+=("--env DATABASE_DIR_COUCHDB=$DATABASE_DIR_COUCHDB") + CONTAINER_DATABASE_PROTO="http://$HOST_LISTEN_ADDR:5984" + MESSAGE_COUCHDB="true" +fi +if [ "$CONTAINER_MONGODB_ENABLED" = "yes" ]; then + SHOW_DATABASE_INFO="true" + CONTAINER_DATABASE_ENABLED="yes" + DOCKER_SET_TMP_PUBLISH+=("--publish $CONTAINER_DATABASE_LISTEN:27017:27017") + DATABASE_DIR_MONGODB="${DATABASE_DIR_MONGODB:-$DATABASE_BASE_DIR/mongodb}" + DOCKER_SET_OPTIONS+=("--volume $LOCAL_DATA_DIR/db/mongodb:$DATABASE_DIR_MONGODB:z") + DOCKER_SET_OPTIONS+=("--env DATABASE_DIR_MONGODB=$DATABASE_DIR_MONGODB") + CONTAINER_DATABASE_PROTO="mongodb://$HOST_LISTEN_ADDR:27017" + MESSAGE_MONGODB="true" +fi +if [ "$CONTAINER_SUPABASE_ENABLED" = "yes" ]; then + SHOW_DATABASE_INFO="true" + CONTAINER_DATABASE_ENABLED="yes" + CONTAINER_DATABASE_PROTO="http://$HOST_LISTEN_ADDR:8000" + DOCKER_SET_TMP_PUBLISH+=("--publish $CONTAINER_DATABASE_LISTEN:5432:5432") + DATABASE_DIR_SUPABASE="${DATABASE_DIR_SUPABASE:-$DATABASE_BASE_DIR/supabase}" + DOCKER_SET_OPTIONS+=("--volume $LOCAL_DATA_DIR/db/supabase:$DATABASE_DIR_SUPABASE:z") + DOCKER_SET_OPTIONS+=("--env DATABASE_DIR_SUPABASE=$DATABASE_DIR_SUPABASE") + MESSAGE_SUPABASE="true" +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# +if [ "$CONTAINER_DATABASE_ENABLED" = "yes" ]; then + if [ -n "$CONTAINER_DATABASE_USER_ROOT" ]; then + DOCKER_SET_OPTIONS+=("--env DATABASE_USER_ROOT=${CONTAINER_DATABASE_USER_ROOT:-root}") + fi + if [ -n "$CONTAINER_DATABASE_PASS_ROOT" ]; then + if [ "$CONTAINER_DATABASE_PASS_ROOT" = "random" ]; then + CONTAINER_DATABASE_PASS_ROOT="$(__password "${CONTAINER_DATABASE_LENGTH_ROOT:-12}")" + fi + DOCKER_SET_OPTIONS+=("--env DATABASE_PASS_ROOT=$CONTAINER_DATABASE_PASS_ROOT") + fi + if [ -n "$CONTAINER_DATABASE_USER_NORMAL" ]; then + DOCKER_SET_OPTIONS+=("--env DATABASE_USER_NORMAL=${CONTAINER_DATABASE_USER_NORMAL:-$USER}") + fi + if [ -n "$CONTAINER_DATABASE_PASS_NORMAL" ]; then + if [ "$CONTAINER_DATABASE_PASS_NORMAL" = "random" ]; then + CONTAINER_DATABASE_PASS_NORMAL="$(__password "${CONTAINER_DATABASE_LENGTH_NORMAL:-12}")" + fi + DOCKER_SET_OPTIONS+=("--env DATABASE_PASS_NORMAL=$CONTAINER_DATABASE_PASS_NORMAL") + fi +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# containers username and password configuration +if [ -n "$REMOTELY_USERNAME" ]; then + CONTAINER_USER_NAME="$REMOTELY_USERNAME" +fi +if [ -n "$CONTAINER_USER_NAME" ]; then + CONTAINER_USER_NAME="${REMOTELY_USERNAME:-${CONTAINER_USER_NAME:-$DEFAULT_USERNAME}}" +fi +if [ -n "$CONTAINER_USER_NAME" ]; then + if [ -n "$CONTAINER_ENV_USER_NAME" ]; then + DOCKER_SET_OPTIONS+=("--env ${CONTAINER_ENV_USER_NAME:-username}=\"$CONTAINER_USER_NAME\"") + fi +fi +if [ -n "$REMOTELY_PASSWORD" ]; then + CONTAINER_USER_PASS="$REMOTELY_PASSWORD" +fi +if [ -n "$CONTAINER_USER_PASS" ]; then + if [ "$CONTAINER_USER_PASS" = "random" ]; then + CONTAINER_USER_PASS="$(__password "${CONTAINER_PASS_LENGTH:-16}")" + fi + CONTAINER_USER_PASS="${REMOTELY_PASSWORD:-${CONTAINER_USER_PASS:-$DEFAULT_PASSWORD}}" +fi +if [ -n "$CONTAINER_USER_PASS" ]; then + if [ -n "$CONTAINER_ENV_PASS_NAME" ]; then + DOCKER_SET_OPTIONS+=("--env ${CONTAINER_ENV_PASS_NAME:-PASSWORD}=\"$CONTAINER_USER_PASS\"") + fi +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Setup email variables +if [ "$CONTAINER_EMAIL_ENABLED" = "yes" ]; then + if [ -n "$CONTAINER_EMAIL_DOMAIN" ]; then + DOCKER_SET_OPTIONS+=("--env EMAIL_DOMAIN=$CONTAINER_EMAIL_DOMAIN") + fi + if [ -n "$CONTAINER_EMAIL_RELAY" ]; then + DOCKER_SET_OPTIONS+=("--env EMAIL_RELAY=$CONTAINER_EMAIL_RELAY") + fi + if [ -n "$CONTAINER_EMAIL_USER" ]; then + DOCKER_SET_OPTIONS+=("--env EMAIL_ADMIN=$CONTAINER_EMAIL_USER@") + fi + if [ -z "$CONTAINER_EMAIL_PORTS" ]; then + CONTAINER_EMAIL_PORTS="25,465,587" + fi + CONTAINER_EMAIL_PORTS="$(echo "${CONTAINER_EMAIL_PORTS//,/ }" | tr ' ' '\n')" + DOCKER_SET_OPTIONS+=("--env EMAIL_ENABLED=$CONTAINER_EMAIL_ENABLED") + for port in $CONTAINER_EMAIL_PORTS; do + DOCKER_SET_TMP_PUBLISH+=("--publish $HOST_LISTEN_ADDR:$port:$port") + done +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# process list +if [ -n "$CONTAINER_SERVICES_LIST" ]; then + DOCKER_SET_OPTIONS+=("--env PROCS_LIST=${CONTAINER_SERVICES_LIST// /,}") +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Setup data mount point +if [ "$CONTAINER_MOUNT_DATA_ENABLED" = "yes" ]; then + if [ -z "$CONTAINER_MOUNT_DATA_MOUNT_DIR" ]; then + CONTAINER_MOUNT_DATA_MOUNT_DIR="/data" + fi + CONTAINER_MOUNT_DATA_MOUNT_DIR="${CONTAINER_MOUNT_DATA_MOUNT_DIR//:*/}" + DOCKER_SET_OPTIONS+=("--volume $LOCAL_DATA_DIR:$CONTAINER_MOUNT_DATA_MOUNT_DIR:z") +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Set config mount point +if [ "$CONTAINER_MOUNT_CONFIG_ENABLED" = "yes" ]; then + if [ -z "$CONTAINER_MOUNT_CONFIG_MOUNT_DIR" ]; then + CONTAINER_MOUNT_CONFIG_MOUNT_DIR="/config" + fi + CONTAINER_MOUNT_CONFIG_MOUNT_DIR="${CONTAINER_MOUNT_CONFIG_MOUNT_DIR//:*/}" + DOCKER_SET_OPTIONS+=("--volume $LOCAL_CONFIG_DIR:$CONTAINER_MOUNT_CONFIG_MOUNT_DIR:z") +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# additional docker arguments +if [ -n "$DOCKER_CUSTOM_ARGUMENTS" ]; then + DOCKER_CUSTOM_ARGUMENTS="${DOCKER_CUSTOM_ARGUMENTS//,/ }" + DOCKER_SET_OPTIONS+=("$DOCKER_CUSTOM_ARGUMENTS") +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# debugging +if [ "$CONTAINER_DEBUG_ENABLED" = "yes" ]; then + DOCKER_SET_OPTIONS+=("--env DEBUGGER=on") + if [ -n "$CONTAINER_DEBUG_OPTIONS" ]; then + DOCKER_SET_OPTIONS+=("--env DEBUGGER_OPTIONS=$CONTAINER_DEBUG_OPTIONS") + fi +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Send command to container +if [ -n "$CONTAINER_COMMANDS" ]; then + CONTAINER_COMMANDS="${CONTAINER_COMMANDS//,/ } " +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Setup links +if [ -n "$HOST_DOCKER_LINK" ]; then + for link in $HOST_DOCKER_LINK; do + [ -n "$link" ] && DOCKER_SET_LINK="--link $link " + done + unset link +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Setup dns +if [ -n "$CONTAINER_DNS" ]; then + DOCKER_SET_DNS="" + DOCKER_SET_OPTIONS+=("--env CUSTOM_DNS=true") + CONTAINER_DNS="${CONTAINER_DNS//,/ }" + for dns in $CONTAINER_DNS; do + if [ "$dns" != "" ] && [ "$dns" != " " ]; then + DOCKER_SET_DNS+="--dns $dns " + fi + done + unset dns +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Setup mounts +if [ -n "$CONTAINER_MOUNTS" ]; then + DOCKER_SET_MNT="" + CONTAINER_MOUNTS="${CONTAINER_MOUNTS//,/ }" + for mnt in $CONTAINER_MOUNTS; do + if [ "$mnt" != "" ] && [ "$mnt" != " " ]; then + echo "$mnt" | grep -q ':' || mnt="$mnt:$mnt" + DOCKER_SET_MNT+="--volume $mnt " + fi + done + unset mnt +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +if [ -n "$CONTAINER_OPT_MOUNT_VAR" ]; then + DOCKER_SET_MNT="" + CONTAINER_OPT_MOUNT_VAR="${CONTAINER_OPT_MOUNT_VAR//,/ }" + for mnt in $CONTAINER_OPT_MOUNT_VAR; do + if [ "$mnt" != "" ] && [ "$mnt" != " " ]; then + echo "$mnt" | grep -q ':' || mnt="$mnt:$mnt" + DOCKER_SET_MNT+="--volume $mnt " + fi + done + unset mnt +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Setup devices +if [ -n "$CONTAINER_DEVICES" ]; then + DOCKER_SET_DEV="" + CONTAINER_DEVICES="${CONTAINER_DEVICES//,/ }" + for dev in $CONTAINER_DEVICES; do + if [ "$dev" != "" ] && [ "$dev" != " " ]; then + echo "$dev" | grep -q ':' || dev="$dev:$dev" + DOCKER_SET_DEV+="--device $dev " + fi + done + unset dev +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Setup enviroment variables +if [ -n "$CONTAINER_ENV" ]; then + DOCKER_SET_ENV="" + CONTAINER_ENV="${CONTAINER_ENV//,/ }" + for env in $CONTAINER_ENV; do + if [ "$env" != "" ] && [ "$env" != " " ]; then + DOCKER_SET_ENV+="--env $env " + fi + done + unset env +fi +if [ -n "$CONTAINER_OPT_ENV_VAR" ]; then + CONTAINER_OPT_ENV_VAR="${CONTAINER_OPT_ENV_VAR//,/ }" + for env in $CONTAINER_OPT_ENV_VAR; do + if [ "$env" != "" ] && [ "$env" != " " ]; then + DOCKER_SET_ENV+="--env $env " + fi + done + unset env +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# setup capabilites +[ "$DOCKER_CAP_CHOWN" = "yes" ] && SET_CAPABILITIES+=("CHOWN") +[ "$DOCKER_CAP_NET_RAW" = "yes" ] && SET_CAPABILITIES+=("NET_RAW") +[ "$DOCKER_CAP_NET_ADMIN" = "yes" ] && SET_CAPABILITIES+=("NET_ADMIN") +[ "$DOCKER_CAP_SYS_NICE" = "yes" ] && SET_CAPABILITIES+=("SYS_NICE") +[ "$DOCKER_CAP_SYS_TIME" = "yes" ] && SET_CAPABILITIES+=("SYS_TIME") +[ "$DOCKER_CAP_SYS_ADMIN" = "yes" ] && SET_CAPABILITIES+=("SYS_ADMIN") +[ "$DOCKER_CAP_SYS_MODULE" = "yes" ] && SET_CAPABILITIES+=("SYS_MODULE") +[ "$DOCKER_CAP_NET_BIND_SERVICE" = "yes" ] && SET_CAPABILITIES+=("NET_BIND_SERVICE") +[ -n "${SET_CAPABILITIES[*]}" ] && CONTAINER_CAPABILITIES="${SET_CAPABILITIES[*]}" +if [ -n "$CONTAINER_CAPABILITIES" ]; then + DOCKER_SET_CAP="" + CONTAINER_CAPABILITIES="${CONTAINER_CAPABILITIES//,/ } ${DOCKER_CUSTOM_CAP//,/ }" + for cap in $CONTAINER_CAPABILITIES; do + if [ "$cap" != "" ] && [ "$cap" != " " ]; then + DOCKER_SET_CAP+="--cap-add $cap " + fi + done + unset cap +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Setup sysctl +if [ -n "$CONTAINER_SYSCTL" ]; then + DOCKER_SET_SYSCTL="" + CONTAINER_SYSCTL="${CONTAINER_SYSCTL//,/ }" + for sysctl in $CONTAINER_SYSCTL; do + if [ "$sysctl" != "" ] && [ "$sysctl" != " " ]; then + DOCKER_SET_SYSCTL+="--sysctl \"$sysctl\" " + fi + done + unset sysctl +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Setup container labels +if [ -n "$CONTAINER_LABELS" ]; then + DOCKER_SET_LABELS="" + CONTAINER_LABELS="${CONTAINER_LABELS//,/ }" + for label in $CONTAINER_LABELS; do + if [ "$label" != "" ] && [ "$label" != " " ]; then + DOCKER_SET_LABELS+="--label $label " + fi + done + unset label +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Setup custom port mappings +SET_TEMP_LISTEN="${HOST_DEFINE_LISTEN//:*/}" +SET_TEMP_ADDR="${HOST_LISTEN_ADDR:-127.0.0.1}" +if [ -n "$CONTAINER_OPT_PORT_VAR" ] || [ -n "$CONTAINER_ADD_CUSTOM_PORT" ]; then + SET_TEMP_PUBLISH="" + CONTAINER_LISTEN_ON="${SET_TEMP_LISTEN:-$SET_TEMP_ADDR}" + CONTAINER_OPT_PORT_VAR="${CONTAINER_OPT_PORT_VAR//,/ }" + CONTAINER_ADD_CUSTOM_PORT="${CONTAINER_ADD_CUSTOM_PORT//,/ }" + for set_port in $CONTAINER_ADD_CUSTOM_PORT $CONTAINER_OPT_PORT_VAR; do + if [ "$set_port" != " " ] && [ -n "$set_port" ]; then + new_port="${set_port//\/*/}" + TYPE="$(echo "$set_port" | grep '/' | awk -F '/' '{print $NF}' | head -n1 | grep '^' || echo '')" + if echo "$new_port" | grep -q 'random:'; then + random_port="$(__rport)" + new_port="${new_port//random:/}" + port="$random_port:${new_port//*:/}" + elif echo "$new_port" | grep -q '\.all:[0-9]'; then + set_listen_on_all="yes" + new_port="${new_port//.all:/}" + if echo "$new_port" | grep -q '^.*[0-9]:[0-9]'; then + port="$new_port" + else + port="$new_port:$new_port" + fi + set_listen_addr="false" + set_listen_port="$port $set_listen_port" + elif echo "$new_port" | grep -q ':.*[0-9]:[0-9]'; then + new_port="${new_port//.all:/}" + port=$new_port + set_listen_addr="false" + elif echo "$new_port" | grep -q '^.*[0-9]:[0-9]'; then + new_port="${new_port//.all:/}" + port=$new_port + elif echo "$new_port" | grep -q ':.*[0-9]:[0-9]'; then + port="$new_port" + set_listen_addr="false" + elif echo "$new_port" | grep -q ':'; then + port="$new_port" + set_listen_addr="true" + else + port="$new_port:$new_port" + set_listen_addr="false" + fi + if [ "$CONTAINER_PRIVATE" = "yes" ]; then + port="$SET_ADDR:$port" + elif [ "$set_listen_addr" = "true" ]; then + port="$CONTAINER_LISTEN_ON:$port" + fi + [ -z "$TYPE" ] && SET_TEMP_PUBLISH="$port" || SET_TEMP_PUBLISH="$port/$TYPE" + DOCKER_SET_TMP_PUBLISH+=("--publish $SET_TEMP_PUBLISH") + fi + done + unset set_port SET_TEMP_LISTEN SET_TEMP_ADDR SET_TEMP_PUBLISH +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# container web server configuration proxy|/location|port +if [ "$CONTAINER_WEB_SERVER_ENABLED" = "yes" ] && { [ -n "$CONTAINER_ADD_RANDOM_PORTS" ] || [ -n "$CONTAINER_WEB_SERVER_INT_PORT" ]; }; then + internal_path="/${CONTAINER_WEB_SERVER_INT_PATH//\/\//\/}" + external_path="/${CONTAINER_WEB_SERVER_EXT_PATH//\/\//\/}" + CONTAINER_WEB_SERVER_LISTEN_ON="${CONTAINER_WEB_SERVER_LISTEN_ON:-}" + CONTAINER_ADD_RANDOM_PORTS="${CONTAINER_ADD_RANDOM_PORTS//,/ }" + CONTAINER_WEB_SERVER_INT_PORT="${CONTAINER_WEB_SERVER_INT_PORT//,/ }" + for set_port in $CONTAINER_WEB_SERVER_INT_PORT $CONTAINER_ADD_RANDOM_PORTS; do + if [ "$set_port" != " " ] && [ -n "$set_port" ]; then + proxy_url="" + proxy_location="" + proxy_info="$set_port" + get_port="${set_port//*|*|/}" + port=${get_port//\/*/} + port="${port//*:/}" + random_port="$(__rport)" + set_hostname="${proxy_info//|*/}" + SET_WEB_PORT_TMP+=("$CONTAINER_WEB_SERVER_LISTEN_ON:$random_port") + DOCKER_SET_TMP_PUBLISH+=("--publish $CONTAINER_WEB_SERVER_LISTEN_ON:$random_port:$port") + if echo "$proxy_info" | grep -q '[a-zA-Z0-9]|/.*|[0-9]'; then + NGINX_REPLACE_INCLUDE="yes" + set_hostname="$(echo "$set_hostname" | grep -v 'proxy$' | grep '^' || false)" + proxy_location="$(echo "$proxy_info" | awk -F '|' '{print $2}' | grep '^' || false)" + proxy_url="$CONTAINER_WEB_SERVER_LISTEN_ON:$random_port" + proxy_url="${proxy_url//\/\//\/}" + echo "$CONTAINER_PROTOCOL" | grep -q "^http" && nginx_proto="${CONTAINER_PROTOCOL:-http}" || nginx_proto="http" + if [ -n "$proxy_url" ] && [ -n "$proxy_location" ]; then + if [ -n "$set_hostname" ]; then + NGINX_CUSTOM_CONFIG="true" + echo "$set_hostname" | grep -qF '.' || set_hostname="$set_hostname.$CONTAINER_HOSTNAME" + cat </dev/null +server { + listen 443 ssl http2; + listen [::]:443 ssl http2; + server_name $set_hostname; + access_log /var/log/nginx/access.$set_hostname.log; + error_log /var/log/nginx/error.$set_hostname.log info; + keepalive_timeout 75 75; + client_max_body_size 0; + chunked_transfer_encoding on; + add_header Strict-Transport-Security "max-age=7200"; + ssl_protocols TLSv1.1 TLSv1.2; + ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH'; + ssl_prefer_server_ciphers on; + ssl_session_cache shared:SSL:10m; + ssl_session_timeout 1d; + ssl_certificate /etc/letsencrypt/live/domain/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/domain/privkey.pem; + + include /etc/nginx/global.d/nginx-defaults.conf; + + location ${external_path:-$proxy_location/} { + send_timeout 3600; + proxy_ssl_verify off; + proxy_http_version 1.1; + proxy_connect_timeout 3600; + proxy_send_timeout 3600; + proxy_read_timeout 3600; + proxy_request_buffering off; + proxy_buffering off; + proxy_set_header Host \$http_host; + proxy_set_header X-Real-IP \$remote_addr; + proxy_set_header X-Forwarded-For \$remote_addr; + proxy_set_header X-Forwarded-Proto \$scheme; + proxy_set_header Upgrade \$http_upgrade; + proxy_set_header Connection \$connection_upgrade; + proxy_redirect http:// https://; + proxy_pass $nginx_proto://$proxy_url$internal_path; + } + +} + +EOF + else + cat </dev/null + location ${external_path:-$proxy_location} { + send_timeout 3600; + proxy_ssl_verify off; + proxy_http_version 1.1; + proxy_connect_timeout 3600; + proxy_send_timeout 3600; + proxy_read_timeout 3600; + proxy_request_buffering off; + proxy_buffering off; + proxy_set_header Host \$http_host; + proxy_set_header X-Real-IP \$remote_addr; + proxy_set_header X-Forwarded-For \$remote_addr; + proxy_set_header X-Forwarded-Proto \$scheme; + proxy_set_header Upgrade \$http_upgrade; + proxy_set_header Connection \$connection_upgrade; + proxy_redirect http:// https://; + proxy_pass $nginx_proto://$proxy_url/$internal_path; + } + +EOF + fi + fi + unset proxy_info proxy_location proxy_url set_hostname + fi + fi + done + [ -n "$CONTAINER_PUBLISHED_PORT" ] && DOCKER_SET_TMP_PUBLISH=("${CONTAINER_PUBLISHED_PORT//--publish,/}") + CONTAINER_PUBLISHED_PORT="${DOCKER_SET_TMP_PUBLISH[*]}" + CONTAINER_PUBLISHED_PORT="${CONTAINER_PUBLISHED_PORT// /,}" + CONTAINER_PUBLISHED_PORT="${CONTAINER_PUBLISHED_PORT//--publish,/}" + unset set_port CONTAINER_ADD_RANDOM_PORTS +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# reuse existing ports +if [ -n "$CONTAINER_PUBLISHED_PORT" ]; then + publish_temp=() + CONTAINER_PUBLISHED_PORT="${CONTAINER_PUBLISHED_PORT//,/ }" + for publish_port in $CONTAINER_PUBLISHED_PORT; do + publish_temp+=("--publish $publish_port ") + done + DOCKER_SET_TMP_PUBLISH=("${publish_temp[*]}") + unset CONTAINER_ADD_RANDOM_PORTS CONTAINER_WEB_SERVER_INT_PORT publish_port publish_temp +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Fix/create port +SET_WEB_PORT="$(__trim "${SET_WEB_PORT_TMP[*]}")" +SET_NGINX_PROXY_PORT="$(echo "$SET_WEB_PORT" | tr ' ' '\n' | grep -v '^$' | head -n1 | grep '^' || echo '')" +if [ -n "$SET_NGINX_PROXY_PORT" ]; then + CLEANUP_PORT="${SET_NGINX_PROXY_PORT//\/*/}" + NGINX_PROXY_PORT="${CLEANUP_PORT//$NGINX_PROXY_ADDRESS:/}" +fi +unset SET_PRETTY_PORT SET_NGINX_PROXY_PORT SET_WEB_PORT_TMP CLEANUP_PORT +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# SSL setup +NGINX_PROXY_URL="" +PROXY_HTTP_PROTO="$CONTAINER_PROTOCOL" +if [ "$NGINX_SSL" = "yes" ]; then + if [ "$SSL_ENABLED" = "yes" ]; then + PROXY_HTTP_PROTO="https" + fi + if [ "$PROXY_HTTP_PROTO" = "https" ]; then + NGINX_PROXY_URL="$PROXY_HTTP_PROTO://$NGINX_PROXY_ADDRESS:$NGINX_PROXY_PORT" + fi +else + CONTAINER_PROTOCOL="${CONTAINER_PROTOCOL:-http}" +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +NGINX_PROXY_URL="${NGINX_PROXY_URL:-$PROXY_HTTP_PROTO://$NGINX_PROXY_ADDRESS:$NGINX_PROXY_PORT}" +NGINX_PROXY_URL="${NGINX_PROXY_URL// /}$CONTAINER_WEB_SERVER_EXT_PATH" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Set temp env for PORTS ENV variable +CONTAINER_ENV_PORTS=("${DOCKER_SET_TMP_PUBLISH[@]//--publish/}") +SET_PORTS_ENV_TMP="$(__trim "${CONTAINER_ENV_PORTS[*]}")" +DOCKER_SET_PORTS_ENV_TMP="$(echo "${SET_PORTS_ENV_TMP//,/ }" | tr ' ' '\n' | grep ':' | awk -F ':' '{print $NF}' | grep '^')" +DOCKER_SET_PORTS_ENV_TMP="$(echo "$DOCKER_SET_PORTS_ENV_TMP" | grep '[0-9]' | sed 's|/.*||g' | sort -uV | grep -v '^$' | tr '\n' ' ' | grep '^' || echo '')" +ENV_PORTS="${DOCKER_SET_PORTS_ENV_TMP[*]}" +ENV_PORTS="$(__trim "${ENV_PORTS[*]}")" +if [ -n "$ENV_PORTS" ]; then + DOCKER_SET_OPTIONS+=("--env ENV_PORTS=\"${ENV_PORTS[*]}\"") +fi +unset DOCKER_SET_PORTS_ENV_TMP ENV_PORTS SET_PORTS_ENV_TMP +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +DOCKER_CUSTOM_ARRAY="$(__retrieve_custom_env | __custom_docker_clean_env)" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Clean up variables +DOCKER_SET_PUBLISH="$(printf '%s\n' "${DOCKER_SET_TMP_PUBLISH[@]}" | sort -Vu | tr '\n' ' ')" # ensure only one +HUB_IMAGE_URL="$(__trim "${HUB_IMAGE_URL[*]:-}")" # image url +HUB_IMAGE_TAG="$(__trim "${HUB_IMAGE_TAG[*]:-}")" # image tag +DOCKER_GET_CAP="$(__trim "${DOCKER_SET_CAP[*]:-}")" # --capabilites +DOCKER_GET_ENV="$(__trim "${DOCKER_SET_ENV[*]:-}")" # --env +DOCKER_GET_DEV="$(__trim "${DOCKER_SET_DEV[*]:-}")" # --device +DOCKER_GET_DNS="$(__trim "${DOCKER_SET_DNS[*]:-}")" # --dns +DOCKER_GET_MNT="$(__trim "${DOCKER_SET_MNT[*]:-}")" # --volume +DOCKER_GET_LINK="$(__trim "${DOCKER_SET_LINK[*]:-}")" # --link +DOCKER_GET_LABELS="$(__trim "${DOCKER_SET_LABELS[*]:-}")" # --labels +DOCKER_GET_SYSCTL="$(__trim "${DOCKER_SET_SYSCTL[*]:-}")" # --sysctl +DOCKER_GET_OPTIONS="$(__trim "${DOCKER_SET_OPTIONS[*]:-}")" # --env +DOCKER_GET_CUSTOM="$(__trim "${DOCKER_CUSTOM_ARRAY[*]:-}")" # --tty --rm --interactive +DOCKER_GET_PUBLISH="$(__trim "${DOCKER_SET_PUBLISH[*]:-}")" # --publish ports +CONTAINER_COMMANDS="$(__trim "${CONTAINER_COMMANDS[*]:-}")" # pass command to container +[ -n "$CONTAINER_COMMANDS" ] || CONTAINER_COMMANDS=" " +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# set docker commands - script creation - execute command # +SET_EXECUTE_PRE_INSTALL="$(echo "docker stop $CONTAINER_NAME &>/dev/null;docker rm -f $CONTAINER_NAME &>/dev/null;docker pull -q $HUB_IMAGE_URL:$HUB_IMAGE_TAG")" +SET_EXECUTE_DOCKER_CMD="$(echo "docker run -d $DOCKER_GET_OPTIONS $DOCKER_GET_CUSTOM $DOCKER_GET_LINK $DOCKER_GET_LABELS $DOCKER_GET_CAP $DOCKER_GET_SYSCTL $DOCKER_GET_DEV $DOCKER_SET_DNS $DOCKER_GET_MNT $DOCKER_GET_ENV $DOCKER_GET_PUBLISH $HUB_IMAGE_URL:$HUB_IMAGE_TAG")" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Run functions +__container_import_variables "$CONTAINER_ENV_FILE_MOUNT" +__dockermgr_variables >"$DOCKERMGR_CONFIG_DIR/env/$APPNAME.env.conf" +__custom_docker_script >"$DOCKERMGR_CONFIG_DIR/env/$APPNAME.script.sh" +__dockermgr_password_variables >"$DOCKERMGR_CONFIG_DIR/secure/$APPNAME" +chmod -f 600 "$DOCKERMGR_CONFIG_DIR/secure/$APPNAME" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # +if [ ! -f "$DOCKERMGR_CONFIG_DIR/env/$APPNAME.custom.conf" ]; then + __custom_docker_env | sed 's|^--.* ||g' >"$DOCKERMGR_CONFIG_DIR/env/$APPNAME.custom.conf" + echo "" >>"$DOCKERMGR_CONFIG_DIR/env/$APPNAME.custom.conf" +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Main progam +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +[ -d "$APPDIR/files" ] && { [ ! -d "$DATADIR" ] && mv -f "$APPDIR/files" "$DATADIR"; } +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Clone/update the repo +if __am_i_online; then + urlverify "$REPO" || printf_exit "$REPO was not found" + if [ -d "$INSTDIR/.git" ]; then + message="Updating $APPNAME configurations" + execute "git_update $INSTDIR" "$message" + else + message="Installing $APPNAME configurations" + execute "git_clone $REPO $INSTDIR" "$message" + fi + # exit on fail + failexitcode $? "$message has failed" +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Write the container name to file +echo "$CONTAINER_NAME" >"$DOCKERMGR_CONFIG_DIR/installed/$APPNAME" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +if [ ! -d "$DATADIR" ]; then + mkdir -p "$DATADIR" + chmod -f 777 "$DATADIR" +fi +if [ ! -d "$LOCAL_DATA_DIR" ]; then + mkdir -p "$LOCAL_DATA_DIR" + chmod -f 777 "$LOCAL_DATA_DIR" +fi +if [ ! -d "$LOCAL_CONFIG_DIR" ]; then + mkdir -p "$LOCAL_CONFIG_DIR" + chmod -f 777 "$LOCAL_CONFIG_DIR" +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +CONTAINER_CREATE_DIRECTORY="${CONTAINER_CREATE_DIRECTORY//,/ }" +CONTAINER_CREATE_DIRECTORY="$(__trim "$CONTAINER_CREATE_DIRECTORY")" +if [ -n "$CONTAINER_CREATE_DIRECTORY" ]; then + CONTAINER_CREATE_DIRECTORY="${CONTAINER_CREATE_DIRECTORY//, /}" + for dir in $CONTAINER_CREATE_DIRECTORY; do + if [ -n "$dir" ] && [ ! -d "$DATADIR/$dir" ]; then + mkdir -p "$DATADIR/$dir" + chmod -f 777 "$DATADIR/$dir" + fi + done +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Copy over data files - keep the same stucture as -v DATADIR/mnt:/mnt +if [ -d "$INSTDIR/rootfs" ] && [ ! -f "$DATADIR/.installed" ]; then + __printf_color "3" "Copying files to $DATADIR" + __sudo_exec cp -Rf "$INSTDIR/rootfs/." "$DATADIR/" &>/dev/null + find "$DATADIR" -name ".gitkeep" -type f -exec rm -rf {} \; &>/dev/null +fi +if [ -f "$DATADIR/.installed" ]; then + __sudo_exec date +'Updated on %Y-%m-%d at %H:%M' | tee -p "$DATADIR/.installed" &>/dev/null +else + __sudo_exec chown -Rf "$USER":"$USER" "$DOCKERMGR_CONFIG_DIR" &>/dev/null + __sudo_exec chown -f "$USER":"$USER" "$DATADIR" "$INSTDIR" "$INSTDIR" &>/dev/null + __sudo_exec date +'installed on %Y-%m-%d at %H:%M' | tee -p "$DATADIR/.installed" &>/dev/null +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Mount /etc/resolv.conf file in the container +if [ "$HOST_RESOLVE_ENABLED" = "yes" ]; then + mkdir -p "$INSTDIR/rootfs/etc" + [ -n "$HOST_ETC_RESOLVE_INIT_FILE" ] || HOST_ETC_RESOLVE_INIT_FILE="/etc/resolv.conf" + if [ ! -f "$INSTDIR/rootfs/etc/resolv.conf" ]; then + cp -Rf "$HOST_ETC_RESOLVE_INIT_FILE" "$INSTDIR/rootfs/etc/resolv.conf" + fi + touch "$INSTDIR/rootfs/etc/resolv.conf" + if [ "$HOST_ETC_RESOLVE_INIT_FILE" = "/usr/local/etc/resolv.conf" ]; then + DOCKER_SET_OPTIONS+=("--volume $INSTDIR/rootfs/etc/resolv.conf:/usr/local/etc/resolv.conf") + else + DOCKER_SET_OPTIONS+=("--volume $INSTDIR/rootfs/etc/resolv.conf:/etc/resolv.conf") + fi +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Mount /etc/hosts file in the container +if [ "$HOST_ETC_HOSTS_ENABLED" = "yes" ]; then + mkdir -p "$INSTDIR/rootfs/etc" + [ -n "$HOST_ETC_HOSTS_INIT_FILE" ] || HOST_ETC_HOSTS_INIT_FILE="/etc/hosts" + if [ ! -f "$INSTDIR/rootfs/etc/hosts" ]; then + cp -Rf "$HOST_ETC_HOSTS_INIT_FILE" "$INSTDIR/rootfs/etc/hosts" + fi + touch "$INSTDIR/rootfs/etc/hosts" + if [ "$HOST_ETC_HOSTS_INIT_FILE" = "/usr/local/etc/hosts" ]; then + DOCKER_SET_OPTIONS+=("--volume $INSTDIR/rootfs/etc/hosts:/usr/local/etc/hosts") + else + DOCKER_SET_OPTIONS+=("--volume $INSTDIR/rootfs/etc/hosts:/etc/hosts") + fi +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +DOCKERMGR_INSTALL_SCRIPT="$DOCKERMGR_CONFIG_DIR/scripts/$CONTAINER_NAME.sh" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# setup the container +unset EXECUTE_DOCKER_SCRIPT +EXECUTE_DOCKER_CMD="$(__trim "${SET_EXECUTE_DOCKER_CMD[*]}")" +EXECUTE_PRE_INSTALL="$(__trim "${SET_EXECUTE_PRE_INSTALL[*]}")" +DOCKER_COMPOSE_CMD="$(docker compose 2>&1 | grep -q 'is not a docker command.' || echo "true")" +if [ -f "$INSTDIR/docker-compose.yml" ] && [ "$DOCKER_COMPOSE_CMD" = "true" ]; then + __printf_color "3" "Installing containers using docker-compose" + sed -i 's|REPLACE_DATADIR|'$DATADIR'' "$INSTDIR/docker-compose.yml" &>/dev/null + if cd "$INSTDIR"; then + docker compose pull &>/dev/null + docker compose up -d &>/dev/null + CONTAINER_INSTALLED="true" + create_docker_script_message_pre="Failed to cd into $INSTDIR" + create_docker_script_message_post="Failed to bring up containers" + EXECUTE_PRE_INSTALL="$(echo 'cd "'$INSTDIR'"')" + EXECUTE_DOCKER_CMD="$(echo 'docker compose pull && docker compose up -d')" + fi +elif [ -f "$INSTDIR/docker-compose.yml" ] && [ -n "$(type -P docker-compose)" ]; then + __printf_color "3" "Installing containers using docker-compose" + sed -i 's|REPLACE_DATADIR|'$DATADIR'' "$INSTDIR/docker-compose.yml" &>/dev/null + if cd "$INSTDIR"; then + docker-compose pull &>/dev/null + docker-compose up -d &>/dev/null + CONTAINER_INSTALLED="true" + create_docker_script_message_pre="Failed to cd into $INSTDIR" + create_docker_script_message_post="Failed to bring up containers" + EXECUTE_PRE_INSTALL="$(echo 'cd "'$INSTDIR'"')" + EXECUTE_DOCKER_CMD="$(echo 'docker-compose pull && docker-compose up -d')" + fi +fi +__create_docker_script +EXECUTE_DOCKER_SCRIPT="$EXECUTE_DOCKER_CMD" +if [ "$INIT_SCRIPT_ONLY" = "false" ] && [ -n "$EXECUTE_DOCKER_SCRIPT" ]; then + EXECUTE_PRE_INSTALL="$(__trim "${EXECUTE_PRE_INSTALL//||*/}")" + EXECUTE_DOCKER_SCRIPT="$(__trim "${EXECUTE_DOCKER_SCRIPT//||*/}")" + __printf_color "6" "Updating the image from $HUB_IMAGE_URL with tag $HUB_IMAGE_TAG" + if [ -n "$EXECUTE_PRE_INSTALL" ]; then + __printf_color "6" "Executing pre-install command" + eval "$EXECUTE_PRE_INSTALL" 2>"${TMP:-/tmp}/$APPNAME.err.log" >/dev/null + fi + __printf_color "6" "Creating container $CONTAINER_NAME" + if eval $EXECUTE_DOCKER_SCRIPT $CONTAINER_COMMANDS 2>"${TMP:-/tmp}/$APPNAME.err.log" >/dev/null; then + sleep 10 + if { __container_is_running || __docker_ps_all -q || __sudo_exec docker start $CONTAINER_NAME &>/dev/null; }; then + rm -Rf "${TMP:-/tmp}/$APPNAME.err.log" + echo "$CONTAINER_NAME" >"$DOCKERMGR_CONFIG_DIR/containers/$APPNAME" + __docker_ps_all -q && CONTAINER_INSTALLED="true" + else + ERROR_LOG="true" + fi + fi +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Install nginx proxy +if [ "$USER" = "root" ]; then + [ -d "$NGINX_DIR" ] && NINGX_VHOSTS_WRITABLE="true" +else + NINGX_VHOSTS_WRITABLE="$(sudo -n true && NGINX_DIR="$NGINX_DIR" sudo -E bash -c '[ -w "$NGINX_DIR" ] && echo true')" +fi +if [ "$NINGX_VHOSTS_WRITABLE" = "true" ]; then + NGINX_VHOST_TMP_NAMES=() + NGINX_VHOST_ENABLED="true" + NGINX_VHOST_SET_NAMES="${CONTAINER_WEB_SERVER_VHOSTS//,/ }" + NGINX_CONFIG_NAME="${CONTAINER_WEB_SERVER_CONFIG_NAME:-$CONTAINER_HOSTNAME}" + NGINX_MAIN_CONFIG="$NGINX_DIR/vhosts.d/$NGINX_CONFIG_NAME.conf" + NGINX_VHOST_CONFIG="$NGINX_DIR/vhosts.d/$NGINX_CONFIG_NAME.custom.conf" + NGINX_INC_CONFIG="$NGINX_DIR/conf.d/vhosts/$NGINX_CONFIG_NAME.conf" + if [ "$NGINX_DIR" = "/etc/nginx/vhosts.d" ]; then + [ -d "$NGINX_DIR/vhosts.d" ] || __sudo_root mkdir -p "$NGINX_DIR/vhosts.d" + [ -d "$NGINX_DIR/conf.d/vhosts.d" ] || __sudo_root mkdir -p "$NGINX_DIR/conf.d/vhosts.d" + chmod 777 "$NGINX_DIR/vhosts.d" "$NGINX_DIR/conf.d/vhosts.d" + else + [ -d "$NGINX_DIR/vhosts.d" ] || mkdir -p "$NGINX_DIR/vhosts.d" + [ -d "$NGINX_DIR/conf.d/vhosts.d" ] || mkdir -p "$NGINX_DIR/conf.d/vhosts.d" + fi + if [ "$HOST_NGINX_UPDATE_CONF" = "yes" ] && [ -f "$INSTDIR/nginx/proxy.conf" ]; then + for vhost in $NGINX_VHOST_SET_NAMES; do + if [ -n "$vhost" ]; then + set_vhost="${vhost// /}" + if echo "$set_vhost" | grep -q "[.]all$"; then # map to vhost.* + vhost="$(__set_vhost_alias "$set_vhost" ".all" ".*")" + NGINX_VHOST_TMP_NAMES+=("$vhost") + set_vhost="" + elif echo "$set_vhost" | grep -q "^all[.]"; then # map to *.vhost + vhost="$(__set_vhost_alias "$set_vhost" "all." "*.")" + NGINX_VHOST_TMP_NAMES+=("$vhost") + set_vhost="" + elif echo "$set_vhost" | grep -q '[.]myhost$'; then # map to vhost.hostname + vhost="$(__set_vhost_alias "$set_vhost" ".myhost" "")" + NGINX_VHOST_TMP_NAMES+=("$vhost.$CONTAINER_HOSTNAME") + set_vhost="" + elif echo "$set_vhost" | grep -q '[.]mydomain$'; then # map to vhost.domain or map to vhost.hostname + vhost="$(__set_vhost_alias "$set_vhost" ".mydomain" "")" + NGINX_VHOST_TMP_NAMES+=("$vhost.${CONTAINER_DOMAINNAME:-$CONTAINER_HOSTNAME}") + set_vhost="" + elif echo "$set_vhost" | grep -q '.*[a-zA-Z0-9]\.\*$'; then # map to vhost.* + NGINX_VHOST_TMP_NAMES+=("$set_vhost") + set_vhost="" + else + NGINX_VHOST_TMP_NAMES+=("${set_vhost:-$vhost}") + fi + fi + done + if [ -n "${NGINX_VHOST_TMP_NAMES[*]}" ]; then + NGINX_VHOST_NAMES="$(__trim "${NGINX_VHOST_TMP_NAMES[*]}")" + CONTAINER_WEB_SERVER_VHOSTS="${NGINX_VHOST_NAMES//\'/}" + unset NGINX_VHOST_TMP_NAMES + else + NGINX_VHOST_NAMES="${NGINX_VHOST_NAMES:-}" + fi + cp -f "$INSTDIR/nginx/proxy.conf" "$NGINX_VHOSTS_CONF_FILE_TMP" + sed -i "s|REPLACE_APPNAME|$APPNAME|g" "$NGINX_VHOSTS_CONF_FILE_TMP" &>/dev/null + sed -i "s|REPLACE_NGINX_PORT|$NGINX_PORT|g" "$NGINX_VHOSTS_CONF_FILE_TMP" &>/dev/null + sed -i "s|REPLACE_HOST_PROXY|$NGINX_PROXY_URL|g" "$NGINX_VHOSTS_CONF_FILE_TMP" &>/dev/null + sed -i "s|REPLACE_NGINX_HOST|$CONTAINER_HOSTNAME|g" "$NGINX_VHOSTS_CONF_FILE_TMP" &>/dev/null + sed -i "s|REPLACE_NGINX_VHOSTS|$NGINX_VHOST_NAMES|g" "$NGINX_VHOSTS_CONF_FILE_TMP" &>/dev/null + sed -i "s|REPLACE_SERVER_LISTEN_OPTS|$NGINX_LISTEN_OPTS|g" "$NGINX_VHOSTS_CONF_FILE_TMP" &>/dev/null + if [ -d "$NGINX_DIR/vhosts.d" ]; then + if [ -f "$NGINX_VHOSTS_INC_FILE_TMP" ]; then + sed -i "s|REPLACE_NGINX_INCLUDE|$NGINX_INC_CONFIG|g" "$NGINX_VHOSTS_CONF_FILE_TMP" + __sudo_root mv -f "$NGINX_VHOSTS_INC_FILE_TMP" "$NGINX_INC_CONFIG" + elif [ -f "$INSTDIR/nginx/conf.d/vhosts/include.conf" ]; then + cat "$INSTDIR/nginx/conf.d/vhosts/include.conf" | tee -p "$NGINX_VHOSTS_INC_FILE_TMP" &>/dev/null + sed -i "s|REPLACE_NGINX_INCLUDE|$NGINX_INC_CONFIG|g" "$NGINX_VHOSTS_CONF_FILE_TMP" + __sudo_root mv -f "$NGINX_VHOSTS_INC_FILE_TMP" "$NGINX_INC_CONFIG" + fi + if [ -f "$NGINX_VHOSTS_PROXY_FILE_TMP" ] && [ "$NGINX_CUSTOM_CONFIG" = "true" ]; then + __sudo_root mv -f "$NGINX_VHOSTS_PROXY_FILE_TMP" "$NGINX_VHOST_CONFIG" + fi + if [ ! -f "$NGINX_INC_CONFIG" ]; then + sed -i "s|include.*REPLACE_NGINX_INCLUDE;||g" "$NGINX_VHOSTS_CONF_FILE_TMP" + fi + __sudo_root mv -f "$NGINX_VHOSTS_CONF_FILE_TMP" "$NGINX_MAIN_CONFIG" + if [ -f "$NGINX_MAIN_CONFIG" ]; then + NGINX_IS_INSTALLED="yes" + NGINX_CONF_FILE="$NGINX_MAIN_CONFIG" + fi + if [ -f "/etc/nginx/nginx.conf" ]; then + systemctl status nginx 2>/dev/null | grep -q enabled &>/dev/null && __sudo_root systemctl reload nginx &>/dev/null + fi + else + mv -f "$NGINX_VHOSTS_CONF_FILE_TMP" "$INSTDIR/nginx/$NGINX_CONFIG_NAME.conf" &>/dev/null + fi + else + NGINX_PROXY_URL="" + fi + [ -n "$NGINX_PROXY_URL" ] && NGNIX_REVERSE_ADDRESS="$NGINX_PROXY_URL" + [ -f "$NGINX_MAIN_CONFIG" ] && NGINX_PROXY_URL="$CONTAINER_PROTOCOL://$CONTAINER_HOSTNAME" +fi +NGNIX_REVERSE_ADDRESS="${CONTAINER_NGINX_PROXY_URL:-$NGINX_PROXY_URL}" +{ [ "$NGINX_VHOST_NAMES" = "" ] || [ "$NGINX_VHOST_NAMES" = " " ]; } && unset NGINX_VHOST_NAMES +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Setup an internal host +NGINX_VHOSTS_PROXY_INT_TMP="/tmp/$$.$HOST_NGINX_INTERNAL_HOST.$HOST_NGINX_INTERNAL_DOMAIN" +if [ -n "$NGNIX_REVERSE_ADDRESS" ] && [ -n "$HOST_NGINX_INTERNAL_DOMAIN" ]; then + HOST_NGINX_INTERNAL_DOMAIN="$HOST_NGINX_INTERNAL_HOST.$HOST_NGINX_INTERNAL_DOMAIN" + cat </dev/null +server { + listen $HOST_NGINX_HTTP_PORT; + listen [::]:$HOST_NGINX_HTTP_PORT; + server_name $HOST_NGINX_INTERNAL_DOMAIN; + access_log /var/log/nginx/access.$HOST_NGINX_INTERNAL_DOMAIN.log; + error_log /var/log/nginx/error.$HOST_NGINX_INTERNAL_DOMAIN.log info; + keepalive_timeout 75 75; + client_max_body_size 0; + chunked_transfer_encoding on; + add_header Strict-Transport-Security "max-age=7200"; + + include /etc/nginx/global.d/nginx-defaults.conf; + + location / { + send_timeout 3600; + proxy_http_version 1.1; + proxy_connect_timeout 3600; + proxy_send_timeout 3600; + proxy_read_timeout 3600; + proxy_buffering off; + proxy_request_buffering off; + proxy_set_header Host \$http_host; + proxy_set_header X-Real-IP \$remote_addr; + proxy_set_header X-Forwarded-For \$remote_addr; + proxy_set_header X-Forwarded-Proto \$scheme; + proxy_pass $NGNIX_REVERSE_ADDRESS; + } +} + +EOF + if [ -f "$NGINX_VHOSTS_PROXY_INT_TMP" ]; then + if [ -f "/etc/nginx/nginx.conf" ]; then + [ -d "$NGINX_DIR/vhosts.d" ] || __sudo_root mkdir -p "$NGINX_DIR/vhosts.d" + __sudo_root mv -f "$NGINX_VHOSTS_PROXY_INT_TMP" "$NGINX_DIR/vhosts.d/$HOST_NGINX_INTERNAL_DOMAIN.conf" + systemctl status nginx 2>/dev/null | grep -q enabled &>/dev/null && __sudo_root systemctl reload nginx &>/dev/null + else + [ -d "$NGINX_DIR" ] || mkdir -p "$NGINX_DIR/vhosts.d" 2>/dev/null + [ -w "$NGINX_DIR" ] && mv -f "$NGINX_VHOSTS_PROXY_INT_TMP" "$NGINX_DIR/vhosts.d/$HOST_NGINX_INTERNAL_DOMAIN.conf" &>/dev/null + fi + fi + NGINX_VHOST_NAMES="$NGINX_VHOST_NAMES $HOST_NGINX_INTERNAL_DOMAIN" + [ -f "$NGINX_DIR/vhosts.d/$HOST_NGINX_INTERNAL_DOMAIN.conf" ] && NGINX_INTERNAL_IS_SET="$NGINX_DIR/vhosts.d/$HOST_NGINX_INTERNAL_DOMAIN.conf" +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# finalize +if [ "$CONTAINER_INSTALLED" = "true" ] || __docker_ps_all -q; then + DOCKER_PORTS="$(__trim "${DOCKER_GET_PUBLISH//--publish/}")" + SET_PORT="$(echo "$DOCKER_PORTS" | tr ' ' '\n' | grep -vE '^$|--' | sort -V | awk -F ':' '{print $1":"$3":"$2}' | grep '^')" + HOSTS_WRITABLE="$(sudo -n true && sudo bash -c '[ -w "/etc/hosts" ] && echo "true" || false' || echo 'false')" + printf '# - - - - - - - - - - - - - - - - - - - - - - - - - -\n' + if [ "$HOSTS_WRITABLE" = "true" ]; then + if [ -n "$NGINX_VHOST_NAMES" ]; then + NGINX_VHOST_NAMES="${NGINX_VHOST_NAMES//,/ }" + for vhost in $NGINX_VHOST_NAMES; do + if ! grep -sq " $vhost$" "/etc/hosts"; then + if echo "$vhost" | grep -qFv '*'; then + __printf_spacing_color "44" "40" "Adding to /etc/hosts:" "$vhost $CONTAINER_WEB_SERVER_LISTEN_ON" + __printf_spacing_file "40" "$CONTAINER_WEB_SERVER_LISTEN_ON" "$vhost" | sudo tee -p -a "/etc/hosts" &>/dev/null + fi + fi + done + show_hosts_message_banner="true" + fi + if [ -n "$HOST_NGINX_INTERNAL_DOMAIN" ]; then + if ! grep -sq " $HOST_NGINX_INTERNAL_DOMAIN$" "/etc/hosts"; then + __printf_spacing_color "44" "40" "Adding to /etc/hosts:" "$HOST_NGINX_INTERNAL_DOMAIN $HOST_LISTEN_ADDR" + __printf_spacing_file "40" "$HOST_LISTEN_ADDR" "$HOST_NGINX_INTERNAL_DOMAIN" | sudo tee -p -a "/etc/hosts" &>/dev/null + fi + fi + if ! grep -sq " $CONTAINER_HOSTNAME$" "/etc/hosts"; then + __printf_spacing_color "44" "40" "Adding to /etc/hosts:" "$CONTAINER_HOSTNAME $HOST_LISTEN_ADDR" + __printf_spacing_file "40" "$HOST_LISTEN_ADDR" "$CONTAINER_HOSTNAME" | sudo tee -p -a "/etc/hosts" &>/dev/null + fi + show_hosts_message_banner="true" + [ "$show_hosts_message_banner" = "true" ] && printf '# - - - - - - - - - - - - - - - - - - - - - - - - - -\n' + unset show_hosts_message_banner + fi + __printf_spacing_color "3" "40" "The container name is:" "$CONTAINER_NAME" + __printf_spacing_color "3" "40" "Containers data is saved in:" "$DATADIR" + __printf_spacing_color "3" "40" "The container is listening on:" "$HOST_LISTEN_ADDR" + __printf_spacing_color "3" "40" "The domain name is set to:" "$CONTAINER_DOMAINNAME" + __printf_spacing_color "3" "40" "The hostname name is set to:" "$CONTAINER_HOSTNAME" + if [ -n "$HOST_NGINX_INTERNAL_DOMAIN" ]; then + __printf_spacing_color "3" "40" "The internal name is set to:" "$HOST_NGINX_INTERNAL_DOMAIN" + fi + printf '# - - - - - - - - - - - - - - - - - - - - - - - - - -\n' + if [ "$HOST_CRON_ENABLED" = "yes" ] && [ -n "$HOST_CRON_COMMAND" ]; then + [ -n "$HOST_CRON_USER" ] || HOST_CRON_USER="root" + [ -n "$HOST_CRON_SCHEDULE" ] || HOST_CRON_SCHEDULE="30 0 * * *" + __printf_spacing_color "6" "40" "Setting cron user to:" "$HOST_CRON_USER" + __printf_spacing_color "6" "40" "Setting schedule to:" "$HOST_CRON_SCHEDULE" + __printf_spacing_color "3" "40" "Saving cron job to: /etc/cron.d/$CONTAINER_NAME" + echo "$HOST_CRON_SCHEDULE $HOST_CRON_USER $HOST_CRON_COMMAND" | sudo tee -p "/etc/cron.d/$CONTAINER_NAME" &>/dev/null + printf '# - - - - - - - - - - - - - - - - - - - - - - - - - -\n' + fi + if __ssl_certs; then + mkdir -p "$CONTAINER_SSL_DIR" + __sudo_exec chmod -f 777 "$CONTAINER_SSL_DIR" + if __sudo_exec cp -Rf "$HOST_SSL_CA" "$CONTAINER_SSL_CA"; then + __sudo_exec chmod -Rf 666 "$CONTAINER_SSL_CA" + __printf_spacing_color "3" "40" "Copied CA Cert to:" "$CONTAINER_SSL_CA" + fi + if __sudo_exec cp -Rf "$HOST_SSL_CRT" "$CONTAINER_SSL_CRT"; then + __sudo_exec chmod -Rf 666 "$CONTAINER_SSL_DIR" + __printf_spacing_color "3" "40" "Copied certificate to:" "$CONTAINER_SSL_CRT" + fi + if __sudo_exec cp -Rf "$HOST_SSL_KEY" "$CONTAINER_SSL_KEY"; then + __sudo_exec chmod -Rf 666 "$CONTAINER_SSL_DIR" + __printf_spacing_color "3" "40" "Copied private key to:" "$CONTAINER_SSL_KEY" + fi + __sudo_exec chown -Rf "$USER":"$USER" "$CONTAINER_SSL_DIR" &>/dev/null + printf '# - - - - - - - - - - - - - - - - - - - - - - - - - -\n' + fi + if [ "$DOCKER_CREATE_NET" ]; then + __printf_spacing_color "5" "40" "Created docker network:" "$HOST_DOCKER_NETWORK" + printf '# - - - - - - - - - - - - - - - - - - - - - - - - - -\n' + fi + if [ "$NGINX_IS_INSTALLED" = "yes" ]; then + __printf_spacing_color "6" "40" "nginx vhost name:" "$CONTAINER_HOSTNAME" + __printf_spacing_color "6" "40" "nginx website:" "$NGINX_PROXY_URL" + if [ -f "$NGINX_CONF_FILE" ]; then + __printf_spacing_color "6" "40" "nginx config file installed to:" "$NGINX_CONF_FILE" + fi + if [ -f "$NGINX_INC_CONFIG" ]; then + __printf_spacing_color "6" "40" "nginx vhost file installed to:" "$NGINX_INC_CONFIG" + fi + if [ -f "$NGINX_VHOST_CONFIG" ]; then + __printf_spacing_color "6" "40" "nginx custom vhost file installed to:" "$NGINX_VHOST_CONFIG" + fi + if [ -n "$NGINX_INTERNAL_IS_SET" ]; then + __printf_spacing_color "6" "40" "nginx internal vhost file installed to:" "$NGINX_INTERNAL_IS_SET" + fi + printf '# - - - - - - - - - - - - - - - - - - - - - - - - - -\n' + fi + if [ -n "$SET_PORT" ] && [ -n "$NGINX_PROXY_URL" ]; then + MESSAGE="true" + __printf_spacing_color "33" "40" "Server address:" "$NGINX_PROXY_URL" + if [ -n "$NGINX_VHOST_NAMES" ]; then + NGINX_VHOST_NAMES="${NGINX_VHOST_NAMES//,/ }" + for vhost in $NGINX_VHOST_NAMES; do + __printf_spacing_color "33" "40" "vhost name:" "$vhost" + done + fi + printf '# - - - - - - - - - - - - - - - - - - - - - - - - - -\n' + fi + if [ -n "$CONTAINER_USER_ADMIN_PASS_HASH" ]; then + show_user_footer="true" + __printf_spacing_color "6" "40" "raw password is:" "$CONTAINER_USER_ADMIN_PASS_RAW" + if [ "$CONTAINER_USER_ADMIN_PASS_RAW" != "$CONTAINER_USER_ADMIN_PASS_HASH" ]; then + __printf_spacing_color "6" "40" "hashed password is:" "$CONTAINER_USER_ADMIN_PASS_HASH" + fi + fi + if [ -n "$CONTAINER_USER_NAME" ]; then + show_user_footer="true" + __printf_spacing_color "6" "40" "Username is:" "$CONTAINER_USER_NAME" + fi + if [ -n "$CONTAINER_USER_PASS" ]; then + show_user_footer="true" + __printf_spacing_color "33" "40" "Password is:" "$CONTAINER_USER_PASS" + fi + if [ "$CONTAINER_DATABASE_USER_ROOT" ]; then + show_user_footer="true" + __printf_spacing_color "33" "40" "Database root user:" "$CONTAINER_DATABASE_USER_ROOT" + fi + if [ "$CONTAINER_DATABASE_PASS_ROOT" ]; then + show_user_footer="true" + __printf_spacing_color "33" "40" "Database root password:" "$CONTAINER_DATABASE_PASS_ROOT" + fi + if [ "$CONTAINER_DATABASE_USER_NORMAL" ]; then + show_user_footer="true" + __printf_spacing_color "33" "40" "Database user:" "$CONTAINER_DATABASE_USER_NORMAL" + fi + if [ "$CONTAINER_DATABASE_PASS_NORMAL" ]; then + show_user_footer="true" + __printf_spacing_color "33" "40" "Database password:" "$CONTAINER_DATABASE_PASS_NORMAL" + fi + [ "$show_user_footer" = "true" ] && printf '# - - - - - - - - - - - - - - - - - - - - - - - - - -\n' + if [ "$SHOW_DATABASE_INFO" = "true" ]; then + __printf_spacing_color "3" "40" "Database is running on:" "$CONTAINER_DATABASE_PROTO" + if [ -n "$MESSAGE_CONTAINER_DATABASE" ]; then + __printf_spacing_color "6" "40" "$MESSAGE_CONTAINER_DATABASE" + fi + if [ -n "$MESSAGE_COUCHDB" ]; then + __printf_spacing_color "6" "40" "Database files are saved to:" "$DATABASE_DIR_COUCHDB" + fi + if [ -n "$MESSAGE_SQLITE" ]; then + __printf_spacing_color "6" "40" "Database files are saved to:" "$DATABASE_DIR_SQLITE" + fi + if [ -n "$MESSAGE_MARIADB" ]; then + __printf_spacing_color "6" "40" "Database files are saved to:" "$DATABASE_DIR_MARIADB" + fi + if [ -n "$MESSAGE_MONGODB" ]; then + __printf_spacing_color "6" "40" "Database files are saved to:" "$DATABASE_DIR_MONGODB" + fi + if [ -n "$MESSAGE_PGSQL" ]; then + __printf_spacing_color "6" "40" "Database files are saved to:" "$DATABASE_DIR_POSTGRES" + fi + if [ -n "$MESSAGE_REDIS" ]; then + __printf_spacing_color "6" "40" "Database files are saved to:" "$DATABASE_DIR_REDIS" + fi + if [ -n "$MESSAGE_SUPABASE" ]; then + __printf_spacing_color "6" "40" "Database files are saved to:" "$DATABASE_DIR_SUPABASE" + fi + printf '# - - - - - - - - - - - - - - - - - - - - - - - - - -\n' + fi + if [ -f "$DATADIR/config/auth/htpasswd" ]; then + MESSAGE="true" + __printf_spacing_color "5" "40" "Username:" "root" + __printf_spacing_color "5" "40" "Password:" "${SET_USER_PASS:-toor}" + __printf_spacing_color "5" "40" "htpasswd File:" "/config/auth/htpasswd" + printf '# - - - - - - - - - - - - - - - - - - - - - - - - - -\n' + fi + if [ -z "$SET_PORT" ]; then + __printf_spacing_color "3" "40" "This container does not have services configured" + printf '# - - - - - - - - - - - - - - - - - - - - - - - - - -\n' + else + for create_service in $SET_PORT; do + if [ "$create_service" != "--publish" ] && [ "$create_service" != " " ]; then + unset type + if [ "$set_listen_on_all" = "yes" ]; then + for custom_port in $set_listen_port; do + set_custom_port="$(echo "$custom_port" | awk -F ':' '{print $2}' | grep '^' || echo "${custom_port//*:/}")" + set_custom_service="$(echo "$custom_port" | awk -F ':' '{print $1}' | grep '^' || echo "$set_custom_port")" + __printf_spacing_color "6" "40" "Port $set_custom_service is mapped to:" "$set_custom_port" + done + create_service="${create_service//$custom_port/} " + unset set_custom_service set_custom_port + fi + service="$create_service" + if [ -n "$service" ]; then + if echo "$service" | grep -q ":.*.:"; then + set_host="$(echo "$service" | awk -F ':' '{print $1}')" + set_port="$(echo "$service" | awk -F ':' '{print $3}')" + set_service="$(echo "$service" | awk -F ':' '{print $2}')" + elif [ -n "$service" ] && [ "$service" != " " ]; then + set_host="$SET_LISTEN" + set_port="$(echo "$service" | awk -F ':' '{print $1}')" + set_service="$(echo "$service" | awk -F ':' '{print $2}')" + fi + get_servive="$set_service" + set_service="${set_service//\/*/}" + listen="${set_host//0.0.0.0/$HOST_LISTEN_ADDR}:$set_port" + echo "$get_servive" | grep -qE '[0-9]/tcp|[0-9]/udp' && type="${get_servive//*\//}" || unset type + [ -n "$type" ] && get_listen="$listen/$type" || get_listen="$listen" + set_listen=$(printf '%s' "$get_listen") + if [ -n "$listen" ]; then + __printf_spacing_color "6" "40" "Port $set_service is mapped to:" "$set_listen" + fi + fi + fi + unset get_listen type + done + printf '# - - - - - - - - - - - - - - - - - - - - - - - - - -\n' + fi + if [ -f "$DOCKERMGR_INSTALL_SCRIPT" ]; then + __printf_spacing_color "3" "40" "Script saved to:" "$DOCKERMGR_INSTALL_SCRIPT" + printf '# - - - - - - - - - - - - - - - - - - - - - - - - - -\n' + fi + if [ -f "$DOCKERMGR_CONFIG_DIR/env/$APPNAME.env.conf" ] || [ -f "$DOCKERMGR_CONFIG_DIR/env/$APPNAME.custom.conf" ]; then + if [ -f "$DOCKERMGR_CONFIG_DIR/env/$APPNAME.env.conf" ]; then + __printf_spacing_color "2" "40" "variables saved to:" "$DOCKERMGR_CONFIG_DIR/env/$APPNAME.env.conf" + fi + if [ -f "$DOCKERMGR_CONFIG_DIR/env/$APPNAME.custom.conf" ]; then + __printf_spacing_color "2" "40" "Container variables saved to:" "$DOCKERMGR_CONFIG_DIR/env/$APPNAME.custom.conf" + fi + printf '# - - - - - - - - - - - - - - - - - - - - - - - - - -\n' + fi + if [ -n "$CONTAINER_DEFAULT_USERNAME" ] || [ -n "$CONTAINER_DEFAULT_PASSWORD" ]; then + [ -n "$CONTAINER_DEFAULT_USERNAME" ] && __printf_spacing_color "6" "40" "Containers default username is:" "$CONTAINER_DEFAULT_USERNAME" + [ -n "$CONTAINER_DEFAULT_PASSWORD" ] && __printf_spacing_color "6" "40" "Containers default password is:" "$CONTAINER_DEFAULT_PASSWORD" + printf '# - - - - - - - - - - - - - - - - - - - - - - - - - -\n' + fi + if [ -n "$POST_SHOW_FINISHED_MESSAGE" ]; then + __printf_color "2" "$POST_SHOW_FINISHED_MESSAGE" + printf '# - - - - - - - - - - - - - - - - - - - - - - - - - -\n' + fi + __printf_spacing_color "6" "40" "$APPNAME has been installed to:" "$APPDIR" + printf '# - - - - - - - - - - - - - - - - - - - - - - - - - -\n\n' + __show_post_message +else + __printf_color "6" "The container $CONTAINER_NAME seems to have failed" + if [ "$ERROR_LOG" = "true" ]; then + __printf_spacing_color "3" "40" "Errors logged to:" "${TMP:-/tmp}/$APPNAME.err.log" + else + printf_red "Something seems to have gone wrong with the install" + fi + if [ -f "$DOCKERMGR_INSTALL_SCRIPT" ]; then + __printf_spacing_color "3" "40" "Script:" "$DOCKERMGR_INSTALL_SCRIPT" + fi + exit 10 +fi +if [ "$USER" != "root" ] && [ -n "$USER" ]; then + __sudo_exec chown -f "$USER":"$USER" "$DATADIR" "$INSTDIR" &>/dev/null +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +__create_uninstall +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# run post install scripts +run_postinst() { + dockermgr_run_post + run_post_install &>/dev/null +} +# +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# run post install scripts +execute "run_postinst" "Running post install scripts" 1>/dev/null +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Output post install message +run_post_custom +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# create version file +dockermgr_install_version &>/dev/null +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# exit +run_exit >/dev/null +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# End application +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# lets exit with code +exit ${EXIT:-${exitCode:-0}} +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# ex: ts=2 sw=2 et filetype=sh diff --git a/nginx/.gitkeep b/nginx/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/nginx/proxy.conf b/nginx/proxy.conf new file mode 100644 index 0000000..aa3281d --- /dev/null +++ b/nginx/proxy.conf @@ -0,0 +1,89 @@ +# Reverse Proxy for remotely + +server { + server_name REPLACE_NGINX_HOST *.REPLACE_NGINX_HOST REPLACE_NGINX_VHOSTS; + listen REPLACE_NGINX_PORT REPLACE_SERVER_LISTEN_OPTS; + listen [::]:REPLACE_NGINX_PORT REPLACE_SERVER_LISTEN_OPTS; + access_log /var/log/nginx/access.REPLACE_NGINX_HOST.log; + error_log /var/log/nginx/error.REPLACE_NGINX_HOST.log info; + client_max_body_size 0; + ssl_prefer_server_ciphers off; + keepalive_timeout 75 75; + ssl_protocols TLSv1.2 TLSv1.3; + ssl_certificate_key /etc/letsencrypt/live/domain/privkey.pem; + ssl_certificate /etc/letsencrypt/live/domain/fullchain.pem; + ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384; + add_header Strict-Transport-Security "max-age=7200"; + + include REPLACE_NGINX_INCLUDE; + include /etc/nginx/global.d/nginx-defaults.conf; + + location / { + send_timeout 3600; + client_max_body_size 1024M; + proxy_http_version 1.1; + proxy_intercept_errors off; + proxy_send_timeout 3600; + proxy_read_timeout 3600; + proxy_connect_timeout 3600; + proxy_buffering off; + proxy_request_buffering off; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Scheme $scheme; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Forwarded-Port $server_port; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; + proxy_set_header Accept-Encoding ""; + proxy_redirect http:// https://; + proxy_pass REPLACE_HOST_PROXY; + } + location /_blazor { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Host $host; + proxy_pass REPLACE_HOST_PROXY; + } + location /AgentHub { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Host $host; + proxy_pass REPLACE_HOST_PROXY; + } + location /ViewerHub { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Host $host; + proxy_pass REPLACE_HOST_PROXY; + } + location /CasterHub { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Host $host; + proxy_pass REPLACE_HOST_PROXY; + } +} + +} diff --git a/rootfs/config/.gitkeep b/rootfs/config/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/data/.gitkeep b/rootfs/data/.gitkeep new file mode 100644 index 0000000..e69de29