🗃️ Update codebase 🗃️

rootfs/usr/local/bin/entrypoint.sh

Dockerfile
.env.scripts
rootfs/usr/local/bin/entrypoint.sh
rootfs/usr/local/etc/docker/functions/entrypoint.sh
This commit is contained in:
casjay
2025-10-22 08:41:12 -04:00
parent c589f7f05f
commit 42c6379490
4 changed files with 1117 additions and 1010 deletions

View File

@@ -1,60 +1,79 @@
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
##@Version : 202509161150-git
# - - - - - - - - - - - - - - - - - - - - - - - - -
##@Version : 202510220838-git
# @@Author : CasjaysDev
# @@Contact : CasjaysDev <docker-admin@casjaysdev.pro>
# @@License : MIT
# @@Copyright : Copyright 2025 CasjaysDev
# @@Created : Tue Sep 16 11:50:48 AM EDT 2025
# @@Created : Wed Oct 22 08:38:42 AM EDT 2025
# @@File : .env.scripts
# @@Description : Variables for gen-dockerfile and buildx scripts
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# @@Changelog : newScript
# @@TODO : Refactor code
# @@Other : N/A
# @@Resource : N/A
# @@Terminal App : yes
# @@sudo/root : yes
# @@Template : templates/dockerfiles/dotenv.template
# - - - - - - - - - - - - - - - - - - - - - - - - -
# shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2120,SC2155,SC2199,SC2317,SC2329
# - - - - - - - - - - - - - - - - - - - - - - - - -
# entrypoint Settings
DOCKER_ENTYPOINT_PORTS_WEB="${DOCKER_ENTYPOINT_PORTS_WEB}"
DOCKER_ENTYPOINT_PORTS_SRV="${DOCKER_ENTYPOINT_PORTS_SRV}"
DOCKER_ENTYPOINT_HEALTH_APPS="$DOCKER_ENTYPOINT_HEALTH_APPS"
DOCKER_ENTYPOINT_HEALTH_ENDPOINTS="$DOCKER_ENTYPOINT_HEALTH_ENDPOINTS"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Dockerfile info
ENV_DOCKERFILE="Dockerfile"
ENV_IMAGE_NAME="tor"
ENV_USE_TEMPLATE="alpine"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Maintainer info
ENV_ORG_NAME="casjaysdevdocker"
ENV_VENDOR="CasjaysDev"
ENV_AUTHOR="CasjaysDev"
ENV_MAINTAINER="CasjaysDev <docker-admin@casjaysdev.pro>"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# REPO info
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Repository URLs (Full URLs)
# ENV_GIT_REPO_URL: Complete Git repository URL for source code
ENV_GIT_REPO_URL="https://github.com/casjaysdevdocker/tor"
ENV_REGISTRY_URL="docker.io"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Push image info
# ENV_REGISTRY_URL: Complete registry URL for reference (NOT used for pushing)
ENV_REGISTRY_URL="docker.io/casjaysdevdocker/tor"
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Push Configuration
# ENV_IMAGE_PUSH: Complete push destination (this IS used for pushing)
ENV_IMAGE_PUSH="casjaysdevdocker/tor"
# ENV_IMAGE_TAG: Default tag for the image
ENV_IMAGE_TAG="latest"
# ENV_ADD_TAGS: Additional tags, comma-separated (USE_DATE = auto date tag)
ENV_ADD_TAGS="USE_DATE"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Additional push destinations (if needed)
ENV_ADD_IMAGE_PUSH=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Pull image info
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Pull Configuration
# ENV_PULL_URL: Source image to pull from (base image)
ENV_PULL_URL="casjaysdev/alpine"
# ENV_DISTRO_TAG: Tag for the pull source image
ENV_DISTRO_TAG="${IMAGE_VERSION}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Env
SERVICE_PORT="80"
EXPOSE_PORTS="80 9053 9050 9080"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Versions
PHP_VERSION="84"
NODE_VERSION="system"
NODE_MANAGER="system"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Default directories
WWW_ROOT_DIR="/usr/local/share/httpd/default"
DEFAULT_FILE_DIR="/usr/local/share/template-files"
DEFAULT_DATA_DIR="/usr/local/share/template-files/data"
DEFAULT_CONF_DIR="/usr/local/share/template-files/config"
DEFAULT_TEMPLATE_DIR="/usr/local/share/template-files/defaults"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ENV_PACKAGES="tor torsocks lyrebird privoxy unbound nginx php\$PHP_VERSION"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
ENV_PACKAGES='tor torsocks lyrebird privoxy unbound nginx php$PHP_VERSION'
# - - - - - - - - - - - - - - - - - - - - - - - - -
# ex: ts=2 sw=2 et filetype=sh
# - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@@ -1,7 +1,7 @@
# Docker image for tor using the alpine template
ARG IMAGE_NAME="tor"
ARG PHP_SERVER="tor"
ARG BUILD_DATE="202509161150"
ARG BUILD_DATE="202510220838"
ARG LANGUAGE="en_US.UTF-8"
ARG TIMEZONE="America/New_York"
ARG WWW_ROOT_DIR="/usr/local/share/httpd/default"
@@ -219,8 +219,8 @@ LABEL org.opencontainers.image.authors="${LICENSE}"
LABEL org.opencontainers.image.created="${BUILD_DATE}"
LABEL org.opencontainers.image.version="${BUILD_VERSION}"
LABEL org.opencontainers.image.schema-version="${BUILD_VERSION}"
LABEL org.opencontainers.image.url="docker.io"
LABEL org.opencontainers.image.source="docker.io"
LABEL org.opencontainers.image.url="docker.io/casjaysdevdocker/tor"
LABEL org.opencontainers.image.source="docker.io/casjaysdevdocker/tor"
LABEL org.opencontainers.image.vcs-type="Git"
LABEL org.opencontainers.image.revision="${BUILD_VERSION}"
LABEL org.opencontainers.image.source="https://github.com/casjaysdevdocker/tor"

View File

@@ -21,7 +21,6 @@
# shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2120,SC2155,SC2199,SC2317,SC2329
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# run trap command on exit
trap 'echo "❌ Fatal error, killing container"; kill -TERM 1' ERR
trap 'retVal=$?;[ "$SERVICE_IS_RUNNING" != "yes" ] && [ -f "$SERVICE_PID_FILE" ] && rm -Rf "$SERVICE_PID_FILE";exit $retVal' SIGINT SIGTERM SIGPWR
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# setup debugging - https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash
# shellcheck shell=bash
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
##@Version : 202407241259-git
# @@Author : Jason Hempstead
# @@Contact : git-admin@casjaysdev.pro
@@ -17,15 +17,15 @@
# @@Terminal App : no
# @@sudo/root : no
# @@Template : functions/docker-entrypoint
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
# shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2120,SC2155,SC2199,SC2317,SC2329
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
# setup debugging - https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
[ -f "/config/.debug" ] && [ -z "$DEBUGGER_OPTIONS" ] && export DEBUGGER_OPTIONS="$(<"/config/.debug")" || DEBUGGER_OPTIONS="${DEBUGGER_OPTIONS:-}"
{ [ "$DEBUGGER" = "on" ] || [ -f "/config/.debug" ]; } && echo "Enabling debugging" && set -xo pipefail -x$DEBUGGER_OPTIONS && export DEBUGGER="on" || set -o pipefail
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__remove_extra_spaces() { sed 's/\( \)*/\1/g;s|^ ||g'; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__printf_space() {
local pad=$(printf '%0.1s' " "{1..60})
local padlength=$1
@@ -37,7 +37,7 @@ __printf_space() {
message+="$(printf '%s\n' "$string2") "
printf '%s\n' "$message"
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__rm() { [ -n "$1" ] && [ -e "$1" ] && rm -Rf "${1:?}"; }
__grep_test() { grep -sh "$1" "$2" | grep -qwF "${3:-$1}" || return 1; }
__netstat() { [ -f "$(type -P netstat)" ] && netstat "$@" || return 10; }
@@ -45,23 +45,59 @@ __cd() { { [ -d "$1" ] || mkdir -p "$1"; } && builtin cd "$1" || return 1; }
__is_in_file() { [ -e "$2" ] && grep -Rsq "$1" "$2" && return 0 || return 1; }
__curl() { curl -q -sfI --max-time 3 -k -o /dev/null "$@" &>/dev/null || return 10; }
__find() { find "$1" -mindepth 1 -type ${2:-f,d} 2>/dev/null | grep '.' || return 10; }
__pcheck() { [ -n "$(which pgrep 2>/dev/null)" ] && pgrep -o "$1$" &>/dev/null || return 10; }
__pcheck() { [ -n "$(which pgrep 2>/dev/null)" ] && pgrep -x "$1" &>/dev/null || return 10; }
__file_exists_with_content() { [ -n "$1" ] && [ -f "$1" ] && [ -s "$1" ] && return 0 || return 2; }
__sed() { sed -i 's|'$1'|'$2'|g' "$3" &>/dev/null || sed -i "s|$1|$2|g" "$3" &>/dev/null || return 1; }
__pgrep() { __pcheck "${1:-SERVICE_NAME}" || __ps "${1:-$SERVICE_NAME}" | grep -qv ' grep' || return 10; }
__ps() { [ -f "$(type -P ps)" ] && ps "$@" 2>/dev/null | sed 's|:||g' | grep -Fw " ${1:-$SERVICE_NAME}$" || return 10; }
__is_dir_empty() { if [ -n "$1" ]; then [ "$(ls -A "$1" 2>/dev/null | wc -l)" -eq 0 ] && return 0 || return 1; else return 1; fi; }
__get_ip6() { ip a 2>/dev/null | grep -w 'inet6' | awk '{print $2}' | grep -vE '^::1|^fe' | sed 's|/.*||g' | head -n1 | grep '.' || echo ''; }
__get_ip4() { ip a 2>/dev/null | grep -w 'inet' | awk '{print $2}' | grep -vE '^127.0.0' | sed 's|/.*||g' | head -n1 | grep '.' || echo '127.0.0.1'; }
__find_file_relative() { find "$1"/* -not -path '*env/*' -not -path '.git*' -type f 2>/dev/null | sed 's|'$1'/||g' | sort -u | grep -v '^$' | grep '.' || false; }
__find_directory_relative() { find "$1"/* -not -path '*env/*' -not -path '.git*' -type d 2>/dev/null | sed 's|'$1'/||g' | sort -u | grep -v '^$' | grep '.' || false; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__pid_exists() { ps -ax --no-header | sed 's/^[[:space:]]*//g' | awk -F' ' '{print $1}' | sed 's|:||g' | grep '[0-9]' | sort -uV | grep "^$1$" && return 0 || return 1; }
__is_running() { ps -eo args --no-header | awk '{print $1,$2,$3}' | sed 's|:||g' | sort -u | grep -vE 'grep|COMMAND|awk|tee|ps|sed|sort|tail' | grep "$1" | grep -q "${2:-^}" && return 0 || return 1; }
__get_pid() { ps -ax --no-header | sed 's/^[[:space:]]*//g;s|;||g;s|:||g' | awk '{print $1,$5}' | sed 's|:||g' | grep "$1$" | grep -v 'grep' | awk -F' ' '{print $1}' | grep '[0-9]' | sort -uV | head -n1 | grep '.' && return 0 || return 1; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__format_variables() { printf '%s\n' "${@//,/ }" | tr ' ' '\n' | sort -RVu | grep -v '^$' | tr '\n' ' ' | __clean_variables | grep '.' || return 3; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__pgrep() {
local count=3
local srvc="${1:-SERVICE_NAME}"
while [ $count -ge 0 ]; do
# Use exact process name matching, not full command line search
pgrep -x "$srvc" >/dev/null 2>&1 && return 0
sleep 1
count=$((count - 1))
done
return 10
}
# - - - - - - - - - - - - - - - - - - - - - - - - -
__find_file_relative() {
[ -e "$1" ] || return 0
find "$1"/* -not -path '*env/*' -not -path '.git*' -type f 2>/dev/null | sed 's|'$1'/||g' | sort -u | grep -v '^$' | grep '.' || false
}
# - - - - - - - - - - - - - - - - - - - - - - - - -
__find_directory_relative() {
[ -d "$1" ] || return 0
find "$1"/* -not -path '*env/*' -not -path '.git*' -type d 2>/dev/null | sed 's|'$1'/||g' | sort -u | grep -v '^$' | grep '.' || false
}
# - - - - - - - - - - - - - - - - - - - - - - - - -
__pid_exists() {
local result=""
result="$(ps -ax --no-header 2>/dev/null | sed 's/^[[:space:]]*//g' | awk -F' ' '{print $1}' | sed 's|:||g' | grep '[0-9]' | sort -uV | grep "^$1$" 2>/dev/null || echo '')"
[ -n "$result" ] && return 0 || return 1
}
__is_running() {
local result=""
result="$(ps -eo args --no-header 2>/dev/null | awk '{print $1,$2,$3}' | sed 's|:||g' | sort -u | grep -vE 'grep|COMMAND|awk|tee|ps|sed|sort|tail' | grep "$1" | grep "${2:-^}" 2>/dev/null || echo '')"
[ -n "$result" ] && return 0 || return 1
}
__get_pid() {
local result=""
result="$(ps -ax --no-header 2>/dev/null | sed 's/^[[:space:]]*//g;s|;||g;s|:||g' | awk '{print $1,$5}' | sed 's|:||g' | grep "$1$" | grep -v 'grep' | awk -F' ' '{print $1}' | grep '[0-9]' | sort -uV | head -n1 | grep '.' 2>/dev/null || echo '')"
if [ -n "$result" ]; then
echo "$result"
return 0
else
return 1
fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - -
__format_variables() { printf '%s\n' "${@//,/ }" | tr ' ' '\n' | sort -RVu | grep -v '^$' | tr '\n' ' ' | __clean_variables | grep '.' || return 0; }
# - - - - - - - - - - - - - - - - - - - - - - - - -
__clean_variables() {
local var="$*"
var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters
@@ -69,7 +105,7 @@ __clean_variables() {
var="$(printf '%s\n' "$var" | sed 's/\( \)*/\1/g;s|^ ||g')"
printf '%s' "$var" | grep -v '^$'
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__no_exit() {
local monitor_interval="${SERVICE_MONITOR_INTERVAL:-60}"
local failure_threshold="${SERVICE_FAILURE_THRESHOLD:-3}"
@@ -109,7 +145,7 @@ __no_exit() {
wait
"
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__trim() {
local var="${*//;/ }"
var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters
@@ -117,24 +153,42 @@ __trim() {
var="$(echo "$var" | __remove_extra_spaces | sed "s| |; |g;s|;$| |g" | __remove_extra_spaces)"
printf '%s' "$var" | sed 's|;||g' | grep -v '^$'
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__banner() { printf '# - - - %-60s - - - #\n' "$*"; }
# - - - - - - - - - - - - - - - - - - - - - - - - -
__banner() {
local message="$*"
local total_width=80
local content_width=$((total_width - 14)) # Account for "# - - - " and " - - - #"
printf '# - - - %-*s - - - #\n' "$content_width" "$message"
}
# - - - - - - - - - - - - - - - - - - - - - - - - -
__service_banner() {
local icon="${1:-🔧}"
local message="${2:-Processing}"
local service="${3:-service}"
local full_message="$message $service"
local total_width=80
local content_width=$((total_width - 14)) # Account for "# - - - " and " - - - #"
local icon_width=2 # Most emojis are 2 chars wide
local text_width=$((content_width - icon_width * 2 - 2)) # Account for both icons and spaces
printf '# - - - %s %-*s %s - - - #\n' "$icon" "$text_width" "$full_message" "$icon"
}
# - - - - - - - - - - - - - - - - - - - - - - - - -
__find_php_bin() { find -L '/usr'/*bin -maxdepth 4 -name 'php-fpm*' 2>/dev/null | head -n1 | grep '.' || echo ''; }
__find_php_ini() { find -L '/etc' -maxdepth 4 -name 'php.ini' 2>/dev/null | head -n1 | sed 's|/php.ini||g' | grep '.' || echo ''; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__find_nginx_conf() { find -L '/etc' -maxdepth 4 -name 'nginx.conf' 2>/dev/null | head -n1 | grep '.' || echo ''; }
__find_caddy_conf() { find -L '/etc' -maxdepth 4 -type f -iname 'caddy.conf' 2>/dev/null | head -n1 | grep '.' || echo ''; }
__find_lighttpd_conf() { find -L '/etc' -maxdepth 4 -type f -iname 'lighttpd.conf' 2>/dev/null | head -n1 | grep '.' || echo ''; }
__find_cherokee_conf() { find -L '/etc' -maxdepth 4 -type f -iname 'cherokee.conf' 2>/dev/null | head -n1 | grep '.' || echo ''; }
__find_httpd_conf() { find -L '/etc' -maxdepth 4 -type f -iname 'httpd.conf' -o -iname 'apache2.conf' 2>/dev/null | head -n1 | grep '.' || echo ''; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__find_mysql_conf() { find -L '/etc' -maxdepth 4 -type f -name 'my.cnf' 2>/dev/null | head -n1 | grep '.' || echo ''; }
__find_pgsql_conf() { find -L '/var/lib' '/etc' -maxdepth 8 -type f -name 'postgresql.conf' 2>/dev/null | head -n1 | grep '.' || echo ''; }
__find_couchdb_conf() { return; }
__find_mongodb_conf() { return; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__random_password() { cat "/dev/urandom" | tr -dc '0-9a-zA-Z' | head -c${1:-16} && echo ""; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__init_working_dir() {
local service_name="$SERVICE_NAME" # get service name
local workdir="$(eval echo "${WORK_DIR:-}")" # expand variables
@@ -152,25 +206,25 @@ __init_working_dir() {
[ -n "$workdir" ] && { [ -d "$workdir" ] || mkdir -p "$workdir"; }
[ "$SERVICE_USER" = "root" ] || [ -d "$home" ] && chmod -f 777 "$home"
[ "$SERVICE_USER" = "root" ] || [ -d "$workdir" ] && chmod -f 777 "$workdir"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
# cd to dir
__cd "${workdir:-$home}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
echo "Setting the working directory to: $PWD"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
export WORK_DIR="$workdir" HOME="$home"
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__exec_service() {
local count=6
echo "Starting $1"
eval "$@" 2>>/dev/stderr >>/data/logs/start.log &
while [ $count -ne 0 ]; do
sleep 10
sleep 3
__pgrep $1 && touch "/run/init.d/$1.pid" && break || count=$((count - 1))
done
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__update_ssl_certs() {
[ -f "/config/env/ssl.sh" ] && . "/config/env/ssl.sh"
if [ -f "$SSL_CERT" ] && [ -f "$SSL_KEY" ]; then
@@ -180,7 +234,7 @@ __update_ssl_certs() {
[ -f "$SSL_CERT" ] && cp -Rf "$SSL_CERT" "/etc/ssl/$SSL_CERT"
fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__certbot() {
[ -n "$(type -P 'certbot')" ] || return 1
local options="$1"
@@ -193,7 +247,7 @@ __certbot() {
local certbot_key_opts="--key-path $SSL_KEY --fullchain-path $SSL_CERT"
mkdir -p "/config/letsencrypt"
__symlink "/etc/letsencrypt" "/config/letsencrypt"
is_renewal="$(find /etc/letsencrypt/renewal -type -f 2>/dev/null || false)"
is_renewal="$(find /etc/letsencrypt/renewal -type f 2>/dev/null || false)"
[ -f "/config/env/ssl.sh" ] && . "/config/env/ssl.sh"
[ -f "/config/certbot/env.sh" ] && . "/config/certbot/env.sh"
[ -n "$SSL_KEY" ] && { mkdir -p "$(dirname "$SSL_KEY")" || true; } || { echo "The variable $SSL_KEY is not set" >&2 && return 1; }
@@ -203,7 +257,7 @@ __certbot() {
[ "$CERT_BOT_ENABLED" = "true" ] || { export CERT_BOT_ENABLED="" && return 10; }
[ -n "$CERT_BOT_MAIL" ] || { echo "The variable CERT_BOT_MAIL is not set" >&2 && return 1; }
[ -n "$CERTBOT_DOMAINS" ] || { echo "The variable CERTBOT_DOMAINS is not set" >&2 && return 1; }
for domain in $$CERTBOT_DOMAINS; do
for domain in $CERTBOT_DOMAINS; do
[ -n "$domain" ] && ADD_CERTBOT_DOMAINS+="-d $domain "
done
[ -n "$is_renewal" ] && options="renew" ADD_CERTBOT_DOMAINS="" || options="certonly"
@@ -241,7 +295,7 @@ __certbot() {
[ $statusCode -eq 0 ] && __update_ssl_certs
return $statusCode
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__display_user_info() {
if [ -n "$user_name" ] || [ -n "$user_pass" ] || [ -n "$root_user_name" ] || [ -n "$root_user_pass" ]; then
__banner "User info"
@@ -252,7 +306,7 @@ __display_user_info() {
__banner ""
fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__init_config_etc() {
local copy="no"
local name="$(find "/etc/$SERVICE_NAME" -maxdepth 0 2>/dev/null | head -n1)"
@@ -267,7 +321,7 @@ __init_config_etc() {
__copy_templates "$etc_dir" "$conf_dir"
fi
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
}
__create_ssl_cert() {
local SSL_DIR="${SSL_DIR:-/etc/ssl}"
@@ -299,7 +353,7 @@ __create_ssl_cert() {
return 2
fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__init_apache() {
local etc_dir="" conf_dir="" conf_dir="" www_dir="" apache_bin=""
etc_dir="/etc/${1:-apache2}"
@@ -309,7 +363,7 @@ __init_apache() {
#
return 0
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__init_nginx() {
local etc_dir="/etc/${1:-nginx}"
local conf_dir="/config/${1:-nginx}"
@@ -317,14 +371,14 @@ __init_nginx() {
local nginx_bin="$(type -P 'nginx')"
return 0
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__init_php() {
local etc_dir="/etc/${1:-php}"
local conf_dir="/config/${1:-php}"
local php_bin="${PHP_BIN_DIR:-$(__find_php_bin)}"
return 0
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__init_mysql() {
local db_dir="/data/db/mysql"
local etc_dir="${home:-/etc/${1:-mysql}}"
@@ -337,28 +391,28 @@ __init_mysql() {
local mysqld_bin="$(type -P 'mysqld')"
return 0
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__init_mongodb() {
local home="${MONGODB_CONFIG_FILE:-$(__find_mongodb_conf)}"
local user_name="${INITDB_ROOT_USERNAME:-root}"
local user_pass="${MONGO_INITDB_ROOT_PASSWORD:-$_ROOT_PASSWORD}"
return
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__init_postgres() {
local home="${PGSQL_CONFIG_FILE:-$(__find_pgsql_conf)}"
local user_name="${POSTGRES_USER:-root}"
local user_pass="${POSTGRES_PASSWORD:-$POSTGRES_ROOT_PASSWORD}"
return
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__init_couchdb() {
local home="${COUCHDB_CONFIG_FILE:-$(__find_couchdb_conf)}"
local user_name="${COUCHDB_USER:-root}"
local user_pass="${COUCHDB_PASSWORD:-$SET_RANDOM_PASS}"
return
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Show available init functions
__init_help() {
echo '
@@ -368,7 +422,7 @@ __create_ssl_cert
'
return
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__run_once() {
if [ "$CONFIG_DIR_INITIALIZED" = "false" ] || [ "$DATA_DIR_INITIALIZED" = "false" ] || [ ! -f "/config/.docker_has_run" ]; then
return 0
@@ -376,7 +430,7 @@ __run_once() {
return 1
fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
# run program ever n minutes
__cron() {
trap 'retVal=$?;[ -f "/run/cron/$bin.run" ] && rm -Rf "/run/cron/$bin.run";[ -f "/run/cron/$bin.pid" ] && rm -Rf "/run/cron/$bin.pid";exit ${retVal:-0}' SIGINT ERR EXIT
@@ -395,19 +449,19 @@ __cron() {
[ -f "/run/cron/$bin.run" ] || break
done 2>/dev/stderr >>"/data/logs/cron.log"
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__replace() {
local search="$1" replace="$2" file="${3:-$2}"
[ -e "$file" ] || return 1
__sed "$search" "$replace" "$file" || return 0
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__find_replace() {
local search="$1" replace="$2" file="${3:-$2}"
[ -e "$file" ] || return 1
find "$file" -type f -not -path '.git*' -exec sed -i "s|$search|$replace|g" {} \; 2>/dev/null
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
# /config > /etc
__copy_templates() {
local from="$1" to="$2"
@@ -417,7 +471,7 @@ __copy_templates() {
__file_copy "$from" "$to"
fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
# /config/file > /etc/file
__symlink() {
local from="$1" to="$2"
@@ -426,7 +480,7 @@ __symlink() {
ln -sf "$to" "$from" && echo "Created symlink to $from > $to"
fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__file_copy() {
local from="$1"
local dest="$2"
@@ -456,9 +510,9 @@ __file_copy() {
fi
fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__generate_random_uids() {
local set_random_uid="$(seq 3000 5000 | sort -R | head -n 1)"
local set_random_uid="$(seq 100 999 | sort -R | head -n 1)"
while :; do
if grep -shq "x:.*:$set_random_uid:" "/etc/group" && ! grep -shq "x:$set_random_uid:.*:" "/etc/passwd"; then
set_random_uid=$((set_random_uid + 1))
@@ -468,7 +522,7 @@ __generate_random_uids() {
fi
done
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__setup_directories() {
APPLICATION_DIRS="${APPLICATION_DIRS//,/ }"
APPLICATION_FILES="${APPLICATION_FILES//,/ }"
@@ -501,7 +555,7 @@ __setup_directories() {
fi
done
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
# set user on files/folders
__fix_permissions() {
change_user="${1:-${SERVICE_USER:-root}}"
@@ -526,14 +580,14 @@ __fix_permissions() {
fi
fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__get_gid() { grep "^$1:" /etc/group | awk -F ':' '{print $3}' || false; }
__get_uid() { grep "^$1:" /etc/passwd | awk -F ':' '{print $3}' || false; }
__check_for_uid() { cat "/etc/passwd" 2>/dev/null | awk -F ':' '{print $3}' | sort -u | grep -q "^$1$" || false; }
__check_for_guid() { cat "/etc/group" 2>/dev/null | awk -F ':' '{print $3}' | sort -u | grep -q "^$1$" || false; }
__check_for_user() { cat "/etc/passwd" 2>/dev/null | awk -F ':' '{print $1}' | sort -u | grep -q "^$1$" || false; }
__check_for_group() { cat "/etc/group" 2>/dev/null | awk -F ':' '{print $1}' | sort -u | grep -q "^$1$" || false; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
# check if process is already running
__proc_check() {
cmd_bin="$(type -P "${1:-$EXEC_CMD_BIN}")"
@@ -541,14 +595,13 @@ __proc_check() {
if __pgrep "$cmd_bin" || __pgrep "$cmd_name"; then
SERVICE_IS_RUNNING="yes"
touch "$SERVICE_PID_FILE"
echo "$cmd_name is already running"
return 0
else
return 1
fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__set_user_group_id() {
local exitStatus=0
local set_user="${1:-$SERVICE_USER}"
@@ -557,7 +610,7 @@ __set_user_group_id() {
local random_id="$(__generate_random_uids)"
set_uid="$(__get_uid "$set_user" || echo "$set_uid")"
set_gid="$(__get_gid "$set_user" || echo "$set_gid")"
grep -shq "^$create_user:" "/etc/passwd" "/etc/group" || return 0
grep -shq "^$set_user:" "/etc/passwd" "/etc/group" || return 0
[ -n "$set_user" ] && [ "$set_user" != "root" ] || return
if grep -shq "^$set_user:" "/etc/passwd" "/etc/group"; then
if __check_for_guid "$set_gid"; then
@@ -570,7 +623,7 @@ __set_user_group_id() {
export SERVICE_UID="$set_uid"
export SERVICE_GID="$set_gid"
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__create_service_user() {
local exitStatus=0
local create_user="${1:-$SERVICE_USER}"
@@ -588,8 +641,8 @@ __create_service_user() {
create_uid="${create_uid:-1000}"
create_gid="${create_gid:-1000}"
fi
create_uid="$(__get_uid "$set_user" || echo "$create_uid")"
create_gid="$(__get_gid "$set_user" || echo "$create_gid")"
create_uid="$(__get_uid "$create_user" || echo "$create_uid")"
create_gid="$(__get_gid "$create_user" || echo "$create_gid")"
[ -n "$create_uid" ] && [ "$create_uid" != "0" ] || create_uid="$random_id"
[ -n "$create_gid" ] && [ "$create_gid" != "0" ] || create_gid="$random_id"
while :; do
@@ -608,7 +661,7 @@ __create_service_user() {
echo "creating system user $create_user"
useradd --system -u $create_uid -g $create_group -c "Account for $create_user" -d "$create_home_dir" -s /bin/false $create_user 2>/dev/stderr | tee -p -a "/data/logs/init.txt" >/dev/null
fi
grep -shq "$create_group" "/etc/group" || exitStatus=$((exitCode + 1))
grep -shq "$create_group" "/etc/group" || exitStatus=$((exitStatus + 1))
grep -shq "$create_user" "/etc/passwd" || exitStatus=$((exitCode + 1))
if [ $exitStatus -eq 0 ]; then
export WORK_DIR="${create_home_dir:-}"
@@ -618,7 +671,7 @@ __create_service_user() {
fi
if [ -d "/etc/sudoers.d" ] && [ ! -f "/etc/sudoers.d/$create_user" ]; then
echo "$create_user ALL=(ALL) NOPASSWD: ALL" >"/etc/sudoers.d/$create_user"
elif [ -f "/etc/sudoers" ] && grep -qs "$create_user" "/etc/sudoers"; then
elif [ -f "/etc/sudoers" ] && ! grep -qs "$create_user" "/etc/sudoers"; then
echo "$create_user ALL=(ALL) NOPASSWD: ALL" >"/etc/sudoers"
fi
export SERVICE_UID="$create_uid"
@@ -634,7 +687,7 @@ __create_service_user() {
fi
return $exitStatus
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__create_env_file() {
local dir=""
local envStatus=0
@@ -654,7 +707,7 @@ EOF
rm -f "$sample_file"
return $envStatus
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__exec_command() {
local bin=""
local arg=("$@")
@@ -677,11 +730,9 @@ __exec_command() {
fi
return $exitCode
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Setup the server init scripts
__start_init_scripts() {
set -e
trap 'echo "❌ Fatal error, killing container"; kill -TERM 1' ERR
[ "$1" = " " ] && shift 1
[ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -o pipefail -x$DEBUGGER_OPTIONS || set -o pipefail
local retPID=""
@@ -689,17 +740,11 @@ __start_init_scripts() {
local init_pids=""
local retstatus="0"
local initStatus="0"
local critical_failures="0"
local init_dir="${1:-/usr/local/etc/docker/init.d}"
local init_count="$(ls -A "$init_dir"/* 2>/dev/null | grep -v '\.sample' | wc -l)"
local critical_failures=0
local exit_on_failure="${EXIT_ON_SERVICE_FAILURE:-true}"
if [ -n "$SERVICE_DISABLED" ]; then
unset SERVICE_DISABLED
echo "$SERVICE_DISABLED is disabled"
return 0
fi
# Clean stale PID files from previous runs
if [ ! -f "/run/__start_init_scripts.pid" ]; then
echo "🧹 Cleaning stale PID files from previous container run"
@@ -707,8 +752,6 @@ __start_init_scripts() {
fi
touch /run/__start_init_scripts.pid
mkdir -p "/tmp" "/run" "/run/init.d" "/usr/local/etc/docker/exec"
chmod -R 777 "/tmp" "/run" "/run/init.d" "/usr/local/etc/docker/exec"
if [ "$init_count" -eq 0 ] || [ ! -d "$init_dir" ]; then
mkdir -p "/data/logs/init"
@@ -728,27 +771,73 @@ __start_init_scripts() {
if [ -x "$init" ]; then
name="$(basename "$init")"
service="$(printf '%s' "$name" | sed 's/^[^-]*-//;s|.sh$||g')"
echo "🔧 Executing service script: $init (service: $service)"
__service_banner "🔧" "Executing service script:" "$(basename "$init")"
# Execute the init script and capture the exit code
if eval "$init"; then
sleep 5
retPID=$(__get_pid "$service")
if [ -n "$retPID" ]; then
if source "$init"; then
# Check if service was disabled first
if [ -n "$SERVICE_DISABLED" ]; then
initStatus="0"
echo "Service $service started successfully - PID: ${retPID}"
__service_banner "🚫" "Service $service is disabled -" "skipping"
unset SERVICE_DISABLED
else
initStatus="1"
critical_failures=$((critical_failures + 1))
echo "⚠️ Service $service appears to have started but no process found"
sleep 2
# Check for service success indicators
local expected_pid_file="/run/init.d/$service.pid"
if [ "$SERVICE_USES_PID" = "no" ]; then
# Service doesn't use PID files - check if expected PID file exists or assume success
if [ -f "$expected_pid_file" ]; then
retPID="$(cat "$expected_pid_file" 2>/dev/null || echo "0")"
initStatus="0"
__service_banner "✅" "Service $service started successfully -" "PID file"
else
initStatus="0"
__service_banner "✅" "Service $service started successfully -" "no PID tracking"
fi
else
initStatus="1"
critical_failures=$((critical_failures + 1))
echo "❌ Service $service failed to start - check logs: docker logs $CONTAINER_NAME"
fi
# Service uses PID tracking - verify actual running processes
set +e # Temporarily disable exit on error
retPID=""
# First, try to find actual running process with various name patterns
for name_variant in "$service" "${service}84" "${service}d" "$(echo "$service" | sed 's/-//g')" "$(echo "$service" | tr -d '-')"; do
if [ -z "$retPID" ]; then
retPID=$(__get_pid "$name_variant" 2>/dev/null || echo "")
[ -n "$retPID" ] && found_process="$name_variant" && break
fi
done
set -e # Re-enable exit on error
if [ -n "$retPID" ] && [ "$retPID" != "0" ]; then
# Found actual running process
initStatus="0"
__service_banner "✅" "Service $service started successfully -" "PID: ${retPID} ($found_process)"
elif [ -f "$expected_pid_file" ]; then
# No running process but PID file exists - verify PID is valid
file_pid="$(cat "$expected_pid_file" 2>/dev/null || echo "")"
if [ -n "$file_pid" ] && kill -0 "$file_pid" 2>/dev/null; then
initStatus="0"
__service_banner "✅" "Service $service started successfully -" "PID: $file_pid (from file)"
elif [ -n "$file_pid" ]; then
initStatus="1"
critical_failures=$((critical_failures + 1))
__service_banner "⚠️" "Service $service has stale PID file -" "process $file_pid not running"
else
initStatus="0"
__service_banner "✅" "Service $service completed initialization -" "no process tracking"
fi
else
# No process and no PID file - this is likely a configuration-only service
initStatus="0"
__service_banner "✅" "Service $service completed successfully -" "configuration service"
fi
fi
fi
else
initStatus="1"
critical_failures=$((critical_failures + 1))
__service_banner "❌" "Service $service failed to start -" "check logs"
fi
echo ""
fi
retstatus=$((retstatus + initStatus))
@@ -770,7 +859,7 @@ __start_init_scripts() {
printf '%s\n' "$SERVICE_NAME started on $(date)" >"/data/logs/start.log"
return $retstatus
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__setup_mta() {
[ -d "/etc/ssmtp" ] || [ -d "/etc/postfix" ] || return
if [ ! -d "/config/ssmtp" ] || [ ! -d "/config/postfix" ]; then
@@ -877,7 +966,7 @@ EOF
[ -f "/root/dead.letter" ] && __rm "/root/dead.letter"
return $exitCode
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__initialize_web_health() {
local www_dir="${1:-${WWW_ROOT_DIR:-/usr/local/share/httpd/default}}"
if [ -d "$www_dir" ]; then
@@ -886,7 +975,7 @@ __initialize_web_health() {
__find_replace "REPLACE_LAST_UPDATED_ON_MESSAGE" "${LAST_UPDATED_ON_MESSAGE:-$(date +'Last updated on: %Y-%m-%d at %H:%M:%S')}" "/usr/local/share/httpd"
fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
# file_dir
__initialize_replace_variables() {
local set_dir="" get_dir="$*"
@@ -929,7 +1018,7 @@ __initialize_replace_variables() {
mkdir -p "${TMP_DIR:-/tmp/$SERVICE_NAME}" "${RUN_DIR:-/run/$SERVICE_NAME}" "${LOG_DIR:-/data/logs/$SERVICE_NAME}"
chmod -f 777 "${TMP_DIR:-/tmp/$SERVICE_NAME}" "${RUN_DIR:-/run/$SERVICE_NAME}" "${LOG_DIR:-/data/logs/$SERVICE_NAME}"
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__initialize_database() {
[ "$IS_DATABASE_SERVICE" = "yes" ] || [ "$USES_DATABASE_SERVICE" = "yes" ] || return 0
local dir="${1:-$ETC_DIR}"
@@ -960,7 +1049,7 @@ __initialize_database() {
__find_replace "REPLACE_DATABASE_DIR" "$DATABASE_DIR" "/etc"
fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__initialize_db_users() {
[ "$IS_DATABASE_SERVICE" = "yes" ] || [ "$USES_DATABASE_SERVICE" = "yes" ] || return 0
db_normal_user="${DATABASE_USER_NORMAL:-$user_name}"
@@ -973,7 +1062,7 @@ __initialize_db_users() {
export DATABASE_PASS_ROOT="$db_admin_pass"
export db_normal_user db_normal_pass db_admin_user db_admin_pass
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__initialize_system_etc() {
local conf_dir="$1"
local dir=""
@@ -1000,7 +1089,7 @@ __initialize_system_etc() {
done
fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__initialize_custom_bin_dir() {
local SET_USR_BIN=""
[ -d "/data/bin" ] && SET_USR_BIN+="$(__find /data/bin f) "
@@ -1018,7 +1107,7 @@ __initialize_custom_bin_dir() {
unset create_bin_template create_bin_name SET_USR_BIN
fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__initialize_default_templates() {
if [ -n "$DEFAULT_TEMPLATE_DIR" ]; then
if [ "$CONFIG_DIR_INITIALIZED" = "false" ] && [ -d "/config" ]; then
@@ -1038,7 +1127,7 @@ __initialize_default_templates() {
fi
fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__initialize_config_dir() {
if [ -n "$DEFAULT_CONF_DIR" ]; then
if [ "$CONFIG_DIR_INITIALIZED" = "false" ] && [ -d "/config" ]; then
@@ -1058,7 +1147,7 @@ __initialize_config_dir() {
fi
fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__initialize_data_dir() {
if [ -d "/data" ]; then
if [ "$DATA_DIR_INITIALIZED" = "false" ] && [ -n "$DEFAULT_DATA_DIR" ]; then
@@ -1078,7 +1167,7 @@ __initialize_data_dir() {
fi
fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__initialize_www_root() {
local WWW_INIT=""
local WWW_TEMPLATE=""
@@ -1091,7 +1180,7 @@ __initialize_www_root() {
fi
__initialize_web_health "$WWW_ROOT_DIR"
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__is_htdocs_mounted() {
WWW_ROOT_DIR="${WWW_ROOT_DIR:-/data/htdocs}"
[ -n "$ENV_WWW_ROOT_DIR" ] && WWW_ROOT_DIR="$ENV_WWW_ROOT_DIR"
@@ -1118,7 +1207,7 @@ __is_htdocs_mounted() {
[ -d "$WWW_ROOT_DIR" ] || mkdir -p "$WWW_ROOT_DIR"
export WWW_ROOT_DIR="${WWW_ROOT_DIR:-/usr/local/share/httpd/default}"
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__initialize_ssl_certs() {
[ "$SSL_ENABLED" = "yes" ] && __certbot
if [ -d "/config/letsencrypt" ]; then
@@ -1145,7 +1234,7 @@ __initialize_ssl_certs() {
fi
type update-ca-certificates &>/dev/null && update-ca-certificates &>/dev/null
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__start_php_dev_server() {
if [ "$2" = "yes" ]; then
if [ -d "/usr/local/share/httpd" ]; then
@@ -1158,7 +1247,7 @@ __start_php_dev_server() {
fi
fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__check_service() {
if [ "$1" = "check" ]; then
shift $#
@@ -1166,7 +1255,7 @@ __check_service() {
exit $?
fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
__switch_to_user() {
if [ "$RUNAS_USER" = "root" ]; then
su_exec=""
@@ -1189,7 +1278,7 @@ __switch_to_user() {
fi
export su_exec
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
# usage backup "days" "hours"
__backup() {
local dirs="" backup_dir backup_name backup_exclude runTime cronTime maxDays
@@ -1227,7 +1316,7 @@ __backup() {
[ -n "$cronTime" ] && runTime=$((cronTime * 3600)) || return $exitStatus
sleep $runTime && __backup "$maxDays" "$cronTime"
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
# set variables from function calls
export INIT_DATE="${INIT_DATE:-$(date)}"
export START_SERVICES="${START_SERVICES:-yes}"
@@ -1235,13 +1324,13 @@ export ENTRYPOINT_MESSAGE="${ENTRYPOINT_MESSAGE:-yes}"
export ENTRYPOINT_FIRST_RUN="${ENTRYPOINT_FIRST_RUN:-yes}"
export DATA_DIR_INITIALIZED="${DATA_DIR_INITIALIZED:-false}"
export CONFIG_DIR_INITIALIZED="${CONFIG_DIR_INITIALIZED:-false}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
# System
export LANG="${LANG:-C.UTF-8}"
export LC_ALL="${LANG:-C.UTF-8}"
export TZ="${TZ:-${TIMEZONE:-America/New_York}}"
export HOSTNAME="${FULL_DOMAIN_NAME:-${SERVER_HOSTNAME:-$HOSTNAME}}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Default directories
export SSL_DIR="${SSL_DIR:-/config/ssl}"
export SSL_CA="${SSL_CERT:-/config/ssl/ca.crt}"
@@ -1251,15 +1340,15 @@ export LOCAL_BIN_DIR="${LOCAL_BIN_DIR:-/usr/local/bin}"
export DEFAULT_DATA_DIR="${DEFAULT_DATA_DIR:-/usr/local/share/template-files/data}"
export DEFAULT_CONF_DIR="${DEFAULT_CONF_DIR:-/usr/local/share/template-files/config}"
export DEFAULT_TEMPLATE_DIR="${DEFAULT_TEMPLATE_DIR:-/usr/local/share/template-files/defaults}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Backup settings
export BACKUP_MAX_DAYS="${BACKUP_MAX_DAYS:-}"
export BACKUP_RUN_CRON="${BACKUP_RUN_CRON:-}"
export BACKUP_DIR="${BACKUP_DIR:-/data/backups}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
CONTAINER_IP4_ADDRESS="${CONTAINER_IP4_ADDRESS:-$(__get_ip4)}"
CONTAINER_IP6_ADDRESS="${CONTAINER_IP6_ADDRESS:-$(__get_ip6)}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Additional
export WORK_DIR="${ENV_WORK_DIR:-$WORK_DIR}"
export SET_RANDOM_PASS="${SET_RANDOM_PASS:-$(__random_password 16)}"
@@ -1277,15 +1366,15 @@ export ENTRYPOINT_PID_FILE="${ENTRYPOINT_PID_FILE:-/run/init.d/entrypoint.pid}"
export ENTRYPOINT_INIT_FILE="${ENTRYPOINT_INIT_FILE:-/config/.entrypoint.done}"
export ENTRYPOINT_DATA_INIT_FILE="${ENTRYPOINT_DATA_INIT_FILE:-/data/.docker_has_run}"
export ENTRYPOINT_CONFIG_INIT_FILE="${ENTRYPOINT_CONFIG_INIT_FILE:-/config/.docker_has_run}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
# is already Initialized
[ -z "$DATA_DIR_INITIALIZED" ] && { [ -f "$ENTRYPOINT_DATA_INIT_FILE" ] && DATA_DIR_INITIALIZED="true" || DATA_DIR_INITIALIZED="false"; }
[ -z "$CONFIG_DIR_INITIALIZED" ] && { [ -f "$ENTRYPOINT_CONFIG_INIT_FILE" ] && CONFIG_DIR_INITIALIZED="true" || CONFIG_DIR_INITIALIZED="false"; }
[ -z "$ENTRYPOINT_FIRST_RUN" ] && { { [ -f "$ENTRYPOINT_PID_FILE" ] || [ -f "$ENTRYPOINT_INIT_FILE" ]; } && ENTRYPOINT_FIRST_RUN="no" || ENTRYPOINT_FIRST_RUN="true"; }
export ENTRYPOINT_DATA_INIT_FILE DATA_DIR_INITIALIZED ENTRYPOINT_CONFIG_INIT_FILE CONFIG_DIR_INITIALIZED
export ENTRYPOINT_PID_FILE ENTRYPOINT_INIT_FILE ENTRYPOINT_FIRST_RUN
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
# export the functions
export -f __get_pid __start_init_scripts __is_running __certbot __update_ssl_certs __create_ssl_cert
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
# end of functions