🗃️ Update codebase 🗃️

rootfs/usr/local/bin/entrypoint.sh
rootfs/usr/local/bin/get_dns_record
This commit is contained in:
casjay
2025-11-30 15:16:44 -05:00
parent 0eba6accc6
commit 52cfd14af6
2 changed files with 279 additions and 278 deletions

View File

@@ -1,13 +1,13 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck shell=bash # shellcheck shell=bash
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
##@Version : 202511291229-git ##@Version : 202511301511-git
# @@Author : Jason Hempstead # @@Author : Jason Hempstead
# @@Contact : jason@casjaysdev.pro # @@Contact : jason@casjaysdev.pro
# @@License : WTFPL # @@License : WTFPL
# @@ReadME : entrypoint.sh --help # @@ReadME : entrypoint.sh --help
# @@Copyright : Copyright: (c) 2025 Jason Hempstead, Casjays Developments # @@Copyright : Copyright: (c) 2025 Jason Hempstead, Casjays Developments
# @@Created : Saturday, Nov 29, 2025 12:29 EST # @@Created : Sunday, Nov 30, 2025 15:11 EST
# @@File : entrypoint.sh # @@File : entrypoint.sh
# @@Description : Entrypoint file for bind # @@Description : Entrypoint file for bind
# @@Changelog : New script # @@Changelog : New script
@@ -43,24 +43,24 @@ while :; do [ "$1" = " " ] && shift 1 || break; done
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# import the functions file # import the functions file
if [ -f "/usr/local/etc/docker/functions/entrypoint.sh" ]; then if [ -f "/usr/local/etc/docker/functions/entrypoint.sh" ]; then
. "/usr/local/etc/docker/functions/entrypoint.sh" . "/usr/local/etc/docker/functions/entrypoint.sh"
else else
echo "Can not load functions from /usr/local/etc/docker/functions/entrypoint.sh" echo "Can not load functions from /usr/local/etc/docker/functions/entrypoint.sh"
exit 1 exit 1
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
case "$1" in case "$1" in
# Help message # Help message
-h | --help) -h | --help)
shift 1 shift 1
echo 'Docker container for '$CONTAINER_NAME'' echo 'Docker container for '$CONTAINER_NAME''
echo "Usage: $CONTAINER_NAME [help tail cron exec start init shell certbot ssl procs ports healthcheck backup command]" echo "Usage: $CONTAINER_NAME [help tail cron exec start init shell certbot ssl procs ports healthcheck backup command]"
echo "" echo ""
exit 0 exit 0
;; ;;
-*) -*)
shift shift
;; ;;
esac esac
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Create the default env files # Create the default env files
@@ -68,7 +68,7 @@ __create_env_file "/config/env/default.sh" "/root/env.sh" &>/dev/null
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# import variables from files # import variables from files
for set_env in "/root/env.sh" "/usr/local/etc/docker/env"/*.sh "/config/env"/*.sh; do for set_env in "/root/env.sh" "/usr/local/etc/docker/env"/*.sh "/config/env"/*.sh; do
[ -f "$set_env" ] && . "$set_env" [ -f "$set_env" ] && . "$set_env"
done done
unset set_env unset set_env
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -94,9 +94,9 @@ SERVER_PORTS="" # specifiy other ports
WEB_SERVER_PORT="" # port : 80,443 WEB_SERVER_PORT="" # port : 80,443
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Healthcheck variables # Healthcheck variables
HEALTH_ENABLED="yes" # enable healthcheck [yes/no] HEALTH_ENABLED="yes" # enable healthcheck [yes/no]
SERVICES_LIST="tini" # comma separated list of processes for the healthcheck SERVICES_LIST="tini,tor,named,php-fpm,nginx" # comma separated list of processes for the healthcheck
HEALTH_ENDPOINTS="" # url endpoints: [http://localhost/health,http://localhost/test] HEALTH_ENDPOINTS="" # url endpoints: [http://localhost/health,http://localhost/test]
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Update path var # Update path var
export PATH RUNAS_USER SERVICE_USER SERVICE_GROUP SERVICE_UID SERVICE_GID WWW_ROOT_DIR DATABASE_DIR export PATH RUNAS_USER SERVICE_USER SERVICE_GROUP SERVICE_UID SERVICE_GID WWW_ROOT_DIR DATABASE_DIR
@@ -107,7 +107,7 @@ export PATH RUNAS_USER SERVICE_USER SERVICE_GROUP SERVICE_UID SERVICE_GID WWW_RO
# show message # show message
__run_message() { __run_message() {
return return
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
################## END OF CONFIGURATION ##################### ################## END OF CONFIGURATION #####################
@@ -162,13 +162,13 @@ export ENTRYPOINT_DATA_INIT_FILE="${ENTRYPOINT_DATA_INIT_FILE:-/data/.docker_has
export ENTRYPOINT_CONFIG_INIT_FILE="${ENTRYPOINT_CONFIG_INIT_FILE:-/config/.docker_has_run}" export ENTRYPOINT_CONFIG_INIT_FILE="${ENTRYPOINT_CONFIG_INIT_FILE:-/config/.docker_has_run}"
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -n "$CONTAINER_WEB_SERVER_WWW_REPO" ]; then if [ -n "$CONTAINER_WEB_SERVER_WWW_REPO" ]; then
www_temp_dir="/tmp/git/$(basename -- "$CONTAINER_WEB_SERVER_WWW_REPO")" www_temp_dir="/tmp/git/$(basename -- "$CONTAINER_WEB_SERVER_WWW_REPO")"
rm -Rf "${WWW_ROOT_DIR:?}"/* "${www_temp_dir:?}"/* rm -Rf "${WWW_ROOT_DIR:?}"/* "${www_temp_dir:?}"/*
mkdir -p "$WWW_ROOT_DIR" "$www_temp_dir" mkdir -p "$WWW_ROOT_DIR" "$www_temp_dir"
git clone -q "$CONTAINER_WEB_SERVER_WWW_REPO" "$www_temp_dir" 2>/dev/null git clone -q "$CONTAINER_WEB_SERVER_WWW_REPO" "$www_temp_dir" 2>/dev/null
rm -Rf "$www_temp_dir/.git" "$www_temp_dir"/.git* rm -Rf "$www_temp_dir/.git" "$www_temp_dir"/.git*
rsync -ra "$www_temp_dir/" "$WWW_ROOT_DIR" --delete >/dev/null 2>&1 rsync -ra "$www_temp_dir/" "$WWW_ROOT_DIR" --delete >/dev/null 2>&1
rm -Rf "$www_temp_dir" rm -Rf "$www_temp_dir"
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# variables based on env/files # variables based on env/files
@@ -252,63 +252,63 @@ EOF
[ -n "$BACKUP_DIR" ] && { [ -d "$BACKUP_DIR" ] || mkdir -p "$BACKUP_DIR"; } [ -n "$BACKUP_DIR" ] && { [ -d "$BACKUP_DIR" ] || mkdir -p "$BACKUP_DIR"; }
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -f "$ENTRYPOINT_INIT_FILE" ]; then if [ -f "$ENTRYPOINT_INIT_FILE" ]; then
ENTRYPOINT_MESSAGE="no" ENTRYPOINT_FIRST_RUN="no" ENTRYPOINT_MESSAGE="no" ENTRYPOINT_FIRST_RUN="no"
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
if [ "$ENTRYPOINT_FIRST_RUN" != "no" ]; then if [ "$ENTRYPOINT_FIRST_RUN" != "no" ]; then
# Show start message # Show start message
if [ "$CONFIG_DIR_INITIALIZED" = "no" ] || [ "$DATA_DIR_INITIALIZED" = "no" ]; then if [ "$CONFIG_DIR_INITIALIZED" = "no" ] || [ "$DATA_DIR_INITIALIZED" = "no" ]; then
[ "$ENTRYPOINT_MESSAGE" = "yes" ] && echo "Executing entrypoint script for bind" [ "$ENTRYPOINT_MESSAGE" = "yes" ] && echo "Executing entrypoint script for bind"
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Set reusable variables # Set reusable variables
{ { [ -w "/etc" ] && [ ! -f "/etc/hosts" ]; } || [ -w "/etc/hosts" ]; } && UPDATE_FILE_HOSTS="yes" && touch "/etc/hosts" { { [ -w "/etc" ] && [ ! -f "/etc/hosts" ]; } || [ -w "/etc/hosts" ]; } && UPDATE_FILE_HOSTS="yes" && touch "/etc/hosts"
{ { [ -w "/etc" ] && [ ! -f "/etc/timezone" ]; } || [ -w "/etc/timezone" ]; } && UPDATE_FILE_TZ="yes" && touch "/etc/timezone" { { [ -w "/etc" ] && [ ! -f "/etc/timezone" ]; } || [ -w "/etc/timezone" ]; } && UPDATE_FILE_TZ="yes" && touch "/etc/timezone"
{ { [ -w "/etc" ] && [ ! -f "/etc/resolv.conf" ]; } || [ -w "/etc/resolv.conf" ]; } && UPDATE_FILE_RESOLV="yes" && touch "/etc/resolv.conf" { { [ -w "/etc" ] && [ ! -f "/etc/resolv.conf" ]; } || [ -w "/etc/resolv.conf" ]; } && UPDATE_FILE_RESOLV="yes" && touch "/etc/resolv.conf"
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Set timezone # Set timezone
[ -n "$TZ" ] && [ "$UPDATE_FILE_TZ" = "yes" ] && echo "$TZ" >"/etc/timezone" [ -n "$TZ" ] && [ "$UPDATE_FILE_TZ" = "yes" ] && echo "$TZ" >"/etc/timezone"
[ -f "/usr/share/zoneinfo/$TZ" ] && [ "$UPDATE_FILE_TZ" = "yes" ] && ln -sf "/usr/share/zoneinfo/$TZ" "/etc/localtime" [ -f "/usr/share/zoneinfo/$TZ" ] && [ "$UPDATE_FILE_TZ" = "yes" ] && ln -sf "/usr/share/zoneinfo/$TZ" "/etc/localtime"
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# if ipv6 add it to /etc/hosts # if ipv6 add it to /etc/hosts
if [ "$UPDATE_FILE_HOSTS" = "yes" ]; then if [ "$UPDATE_FILE_HOSTS" = "yes" ]; then
echo "# known hostname mappings" >"/etc/hosts" echo "# known hostname mappings" >"/etc/hosts"
if [ -n "$(ip a 2>/dev/null | grep 'inet6.*::' || ifconfig 2>/dev/null | grep 'inet6.*::')" ]; then if [ -n "$(ip a 2>/dev/null | grep 'inet6.*::' || ifconfig 2>/dev/null | grep 'inet6.*::')" ]; then
__printf_space "40" "::1" "localhost" >>"/etc/hosts" __printf_space "40" "::1" "localhost" >>"/etc/hosts"
__printf_space "40" "127.0.0.1" "localhost" >>"/etc/hosts" __printf_space "40" "127.0.0.1" "localhost" >>"/etc/hosts"
else else
__printf_space "40" "127.0.0.1" "localhost" >>"/etc/hosts" __printf_space "40" "127.0.0.1" "localhost" >>"/etc/hosts"
fi fi
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# add .internal domain # add .internal domain
if [ "$UPDATE_FILE_HOSTS" = "yes" ] && [ -n "$HOSTNAME" ]; then if [ "$UPDATE_FILE_HOSTS" = "yes" ] && [ -n "$HOSTNAME" ]; then
__grep_test " $HOSTNAME" "/etc/hosts" || __printf_space "40" "${CONTAINER_IP4_ADDRESS:-127.0.0.1}" "$HOSTNAME" >>"/etc/hosts" __grep_test " $HOSTNAME" "/etc/hosts" || __printf_space "40" "${CONTAINER_IP4_ADDRESS:-127.0.0.1}" "$HOSTNAME" >>"/etc/hosts"
__grep_test " ${HOSTNAME%%.*}.internal" "/etc/hosts" || __printf_space "40" "${CONTAINER_IP4_ADDRESS:-127.0.0.1}" "${HOSTNAME%%.*}.internal" >>"/etc/hosts" __grep_test " ${HOSTNAME%%.*}.internal" "/etc/hosts" || __printf_space "40" "${CONTAINER_IP4_ADDRESS:-127.0.0.1}" "${HOSTNAME%%.*}.internal" >>"/etc/hosts"
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# add domainname # add domainname
if [ "$UPDATE_FILE_HOSTS" = "yes" ] && [ "$DOMAINNAME" != "internal" ] && [ -n "$DOMAINNAME" ] && [ "$HOSTNAME.$DOMAINNAME" != "$DOMAINNAME" ]; then if [ "$UPDATE_FILE_HOSTS" = "yes" ] && [ "$DOMAINNAME" != "internal" ] && [ -n "$DOMAINNAME" ] && [ "$HOSTNAME.$DOMAINNAME" != "$DOMAINNAME" ]; then
__grep_test " ${HOSTNAME%%.*}.$DOMAINNAME" "/etc/hosts" || __printf_space "40" "${CONTAINER_IP4_ADDRESS:-127.0.0.1}" "${HOSTNAME%%.*}.$DOMAINNAME" >>"/etc/hosts" __grep_test " ${HOSTNAME%%.*}.$DOMAINNAME" "/etc/hosts" || __printf_space "40" "${CONTAINER_IP4_ADDRESS:-127.0.0.1}" "${HOSTNAME%%.*}.$DOMAINNAME" >>"/etc/hosts"
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Set containers hostname # Set containers hostname
[ -n "$HOSTNAME" ] && [ "$UPDATE_FILE_HOSTS" = "yes" ] && echo "$HOSTNAME" >"/etc/hostname" [ -n "$HOSTNAME" ] && [ "$UPDATE_FILE_HOSTS" = "yes" ] && echo "$HOSTNAME" >"/etc/hostname"
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -f "/etc/hostname" ]; then if [ -f "/etc/hostname" ]; then
[ -n "$(type -P hostname)" ] && hostname -F "/etc/hostname" &>/dev/null || HOSTNAME="$(<"/etc/hostname")" [ -n "$(type -P hostname)" ] && hostname -F "/etc/hostname" &>/dev/null || HOSTNAME="$(<"/etc/hostname")"
export HOSTNAME export HOSTNAME
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# import hosts file into container # import hosts file into container
[ -f "/usr/local/etc/hosts" ] && [ "$UPDATE_FILE_HOSTS" = "yes" ] && cat "/usr/local/etc/hosts" | grep -vF "$HOSTNAME" >>"/etc/hosts" [ -f "/usr/local/etc/hosts" ] && [ "$UPDATE_FILE_HOSTS" = "yes" ] && cat "/usr/local/etc/hosts" | grep -vF "$HOSTNAME" >>"/etc/hosts"
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# import resolv.conf file into container # import resolv.conf file into container
[ "$CUSTOM_DNS" != "yes" ] && [ -f "/usr/local/etc/resolv.conf" ] && [ "$UPDATE_FILE_RESOLV" = "yes" ] && cat "/usr/local/etc/resolv.conf" >"/etc/resolv.conf" [ "$CUSTOM_DNS" != "yes" ] && [ -f "/usr/local/etc/resolv.conf" ] && [ "$UPDATE_FILE_RESOLV" = "yes" ] && cat "/usr/local/etc/resolv.conf" >"/etc/resolv.conf"
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -n "$HOME" ] && [ -d "/usr/local/etc/skel" ]; then if [ -n "$HOME" ] && [ -d "/usr/local/etc/skel" ]; then
[ -d "$HOME" ] && cp -Rf "/usr/local/etc/skel/." "$HOME/" [ -d "$HOME" ] && cp -Rf "/usr/local/etc/skel/." "$HOME/"
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -332,53 +332,53 @@ __initialize_data_dir
__initialize_ssl_certs __initialize_ssl_certs
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -f "$ENTRYPOINT_INIT_FILE" ]; then if [ -f "$ENTRYPOINT_INIT_FILE" ]; then
ENTRYPOINT_FIRST_RUN="no" ENTRYPOINT_FIRST_RUN="no"
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -d "/config" ]; then if [ -d "/config" ]; then
echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_INIT_FILE" echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_INIT_FILE"
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Check if this is a new container # Check if this is a new container
if [ -f "$ENTRYPOINT_DATA_INIT_FILE" ]; then if [ -f "$ENTRYPOINT_DATA_INIT_FILE" ]; then
DATA_DIR_INITIALIZED="yes" DATA_DIR_INITIALIZED="yes"
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -d "/data" ]; then if [ -d "/data" ]; then
echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_DATA_INIT_FILE" echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_DATA_INIT_FILE"
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -f "$ENTRYPOINT_CONFIG_INIT_FILE" ]; then if [ -f "$ENTRYPOINT_CONFIG_INIT_FILE" ]; then
CONFIG_DIR_INITIALIZED="yes" CONFIG_DIR_INITIALIZED="yes"
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -d "/config" ]; then if [ -d "/config" ]; then
echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_CONFIG_INIT_FILE" echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_CONFIG_INIT_FILE"
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
if [ "$ENTRYPOINT_FIRST_RUN" != "no" ]; then if [ "$ENTRYPOINT_FIRST_RUN" != "no" ]; then
# setup the smtp server # setup the smtp server
__setup_mta __setup_mta
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# if no pid assume container restart - clean stale files on restart # if no pid assume container restart - clean stale files on restart
if [ -f "$ENTRYPOINT_PID_FILE" ]; then if [ -f "$ENTRYPOINT_PID_FILE" ]; then
START_SERVICES="no" START_SERVICES="no"
touch "$ENTRYPOINT_PID_FILE" touch "$ENTRYPOINT_PID_FILE"
else else
START_SERVICES=yes START_SERVICES=yes
# Clean any stale PID files on first run # Clean any stale PID files on first run
rm -f /run/__start_init_scripts.pid /run/init.d/*.pid /run/*.pid 2>/dev/null || true rm -f /run/__start_init_scripts.pid /run/init.d/*.pid /run/*.pid 2>/dev/null || true
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
[ "$ENTRYPOINT_MESSAGE" = "yes" ] && __printf_space "40" "The containers ip address is:" "$CONTAINER_IP4_ADDRESS" [ "$ENTRYPOINT_MESSAGE" = "yes" ] && __printf_space "40" "The containers ip address is:" "$CONTAINER_IP4_ADDRESS"
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Show configured listing processes # Show configured listing processes
if [ "$ENTRYPOINT_MESSAGE" = "yes" ] && [ -n "$ENV_PORTS" ]; then if [ "$ENTRYPOINT_MESSAGE" = "yes" ] && [ -n "$ENV_PORTS" ]; then
show_port="" show_port=""
for port in $ENV_PORTS; do [ -n "$port" ] && show_port+="$(printf '%s ' "${port// /}") "; done for port in $ENV_PORTS; do [ -n "$port" ] && show_port+="$(printf '%s ' "${port// /}") "; done
__printf_space "40" "The following ports are open:" "$show_port" __printf_space "40" "The following ports are open:" "$show_port"
unset port show_port unset port show_port
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# execute init script # execute init script
@@ -404,209 +404,209 @@ SKIP_SERVICE_START="no"
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Start all services if no pidfile and not skipping # Start all services if no pidfile and not skipping
if [ "$START_SERVICES" = "yes" ] || [ -z "$1" ]; then if [ "$START_SERVICES" = "yes" ] || [ -z "$1" ]; then
if [ "$SKIP_SERVICE_START" = "no" ]; then if [ "$SKIP_SERVICE_START" = "no" ]; then
[ "$1" = "start" ] && shift 1 [ "$1" = "start" ] && shift 1
[ "$1" = "all" ] && shift 1 [ "$1" = "all" ] && shift 1
rm -Rf "/run"/*/*pid 2>/dev/null || true rm -Rf "/run"/*/*pid 2>/dev/null || true
echo "$$" >"$ENTRYPOINT_PID_FILE" echo "$$" >"$ENTRYPOINT_PID_FILE"
__start_init_scripts "/usr/local/etc/docker/init.d" __start_init_scripts "/usr/local/etc/docker/init.d"
CONTAINER_INIT="${CONTAINER_INIT:-no}" CONTAINER_INIT="${CONTAINER_INIT:-no}"
fi fi
START_SERVICES="no" START_SERVICES="no"
fi fi
export START_SERVICES CONTAINER_INIT ENTRYPOINT_PID_FILE export START_SERVICES CONTAINER_INIT ENTRYPOINT_PID_FILE
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Begin options # Begin options
case "$1" in case "$1" in
init) init)
shift 1 shift 1
echo "Container has been Initialized" echo "Container has been Initialized"
exit 0 exit 0
;; ;;
tail) tail)
shift 1 shift 1
case "$1" in case "$1" in
null) null)
shift $# shift $#
tail -F "/dev/null" tail -F "/dev/null"
;; ;;
app) app)
shift $# shift $#
tail -F /data/logs/*/*.log tail -F /data/logs/*/*.log
;; ;;
-*) -*)
tail "$@" tail "$@"
;; ;;
*) *)
tail -F "${@:-/dev/null}" tail -F "${@:-/dev/null}"
;; ;;
esac esac
;; ;;
logs) logs)
shift 1 shift 1
case "$1" in case "$1" in
follow) follow)
tail -Fq /data/logs/*/* tail -Fq /data/logs/*/*
;; ;;
clean) clean)
log_files="$(find "/data/logs" -type f)" log_files="$(find "/data/logs" -type f)"
for log in "${log_files[@]}"; do for log in "${log_files[@]}"; do
echo "clearing $log" echo "clearing $log"
printf '' >$log printf '' >$log
done done
;; ;;
*) *)
echo "Usage: logs [follow,clean]" echo "Usage: logs [follow,clean]"
exit 0 exit 0
;; ;;
esac esac
;; ;;
cron) cron)
shift 1 shift 1
__cron "$@" & __cron "$@" &
echo "cron script is running with pid: $!" echo "cron script is running with pid: $!"
exit exit
;; ;;
# backup data and config dirs # backup data and config dirs
backup) backup)
shift 1 shift 1
__backup $BACKUP_MAX_DAYS $1 __backup $BACKUP_MAX_DAYS $1
exit $? exit $?
;; ;;
# Docker healthcheck # Docker healthcheck
healthcheck) healthcheck)
shift 1 shift 1
case "$1" in case "$1" in
init | test) init | test)
exit 0 exit 0
;; ;;
*) *)
arguments="$*" arguments="$*"
healthStatus=0 healthStatus=0
healthEnabled="${HEALTH_ENABLED:-}" healthEnabled="${HEALTH_ENABLED:-}"
healthPorts="${WEB_SERVER_PORTS:-}" healthPorts="${WEB_SERVER_PORTS:-}"
healthEndPoints="${HEALTH_ENDPOINTS:-}" healthEndPoints="${HEALTH_ENDPOINTS:-}"
SERVICES_LIST="${arguments:-$SERVICES_LIST}" SERVICES_LIST="${arguments:-$SERVICES_LIST}"
services="$(echo "${SERVICES_LIST//,/ }")" services="$(echo "${SERVICES_LIST//,/ }")"
healthMessage="Everything seems to be running" healthMessage="Everything seems to be running"
[ "$healthEnabled" = "yes" ] || exit 0 [ "$healthEnabled" = "yes" ] || exit 0
if [ -d "/run/healthcheck" ] && [ "$(ls -A "/run/healthcheck" | wc -l)" -ne 0 ]; then if [ -d "/run/healthcheck" ] && [ "$(ls -A "/run/healthcheck" | wc -l)" -ne 0 ]; then
for service in /run/healthcheck/*; do for service in /run/healthcheck/*; do
name=$(basename -- $service) name=$(basename -- $service)
services+="$name " services+="$name "
done done
fi fi
services="$(echo "$services" | tr ' ' '\n' | sort -u | grep -v '^$')" services="$(echo "$services" | tr ' ' '\n' | sort -u | grep -v '^$')"
for proc in $services; do for proc in $services; do
if [ -n "$proc" ]; then if [ -n "$proc" ]; then
if ! __pgrep "$proc"; then if ! __pgrep "$proc"; then
echo "$proc is not running" >&2 echo "$proc is not running" >&2
healthStatus=$((healthStatus + 1)) healthStatus=$((healthStatus + 1))
fi fi
fi fi
done done
for port in $ports; do for port in $ports; do
if [ -n "$(type -P netstat)" ] && [ -n "$port" ]; then if [ -n "$(type -P netstat)" ] && [ -n "$port" ]; then
if ! netstat -taupln | grep -q ":$port "; then if ! netstat -taupln | grep -q ":$port "; then
echo "$port isn't open" >&2 echo "$port isn't open" >&2
healthStatus=$((healthStatus + 1)) healthStatus=$((healthStatus + 1))
fi fi
fi fi
done done
for endpoint in $healthEndPoints; do for endpoint in $healthEndPoints; do
if [ -n "$endpoint" ]; then if [ -n "$endpoint" ]; then
if ! __curl "$endpoint"; then if ! __curl "$endpoint"; then
echo "Can not connect to $endpoint" >&2 echo "Can not connect to $endpoint" >&2
healthStatus=$((healthStatus + 1)) healthStatus=$((healthStatus + 1))
fi fi
fi fi
done done
[ "$healthStatus" -eq 0 ] || healthMessage="Errors reported see: docker logs --follow $CONTAINER_NAME" [ "$healthStatus" -eq 0 ] || healthMessage="Errors reported see: docker logs --follow $CONTAINER_NAME"
[ -n "$healthMessage" ] && echo "$healthMessage" [ -n "$healthMessage" ] && echo "$healthMessage"
exit $healthStatus exit $healthStatus
;; ;;
esac esac
;; ;;
# show open ports # show open ports
ports) ports)
shift 1 shift 1
ports="$(__netstat -taupln | awk -F ' ' '{print $4}' | awk -F ':' '{print $2}' | sort --unique --version-sort | grep -v '^$' | grep '^' || echo '')" ports="$(__netstat -taupln | awk -F ' ' '{print $4}' | awk -F ':' '{print $2}' | sort --unique --version-sort | grep -v '^$' | grep '^' || echo '')"
[ -n "$ports" ] && printf '%s\n%s\n' "The following are servers:" "$ports" | tr '\n' ' ' [ -n "$ports" ] && printf '%s\n%s\n' "The following are servers:" "$ports" | tr '\n' ' '
exit $? exit $?
;; ;;
# show running processes # show running processes
procs) procs)
shift 1 shift 1
ps="$(__ps axco command | grep -vE 'COMMAND|grep|ps' | sort -u || grep '^' || echo '')" ps="$(__ps axco command | grep -vE 'COMMAND|grep|ps' | sort -u || grep '^' || echo '')"
[ -n "$ps" ] && printf '%s\n%s\n' "Found the following processes" "$ps" | tr '\n' ' ' [ -n "$ps" ] && printf '%s\n%s\n' "Found the following processes" "$ps" | tr '\n' ' '
exit $? exit $?
;; ;;
# setup ssl # setup ssl
ssl) ssl)
shift 1 shift 1
__create_ssl_cert __create_ssl_cert
exit $? exit $?
;; ;;
# manage ssl certificate # manage ssl certificate
certbot) certbot)
shift 1 shift 1
CERT_BOT_ENABLED="yes" CERT_BOT_ENABLED="yes"
if [ "$1" = "create" ]; then if [ "$1" = "create" ]; then
shift 1 shift 1
__certbot "create" __certbot "create"
elif [ "$1" = "renew" ]; then elif [ "$1" = "renew" ]; then
shift 1 shift 1
__certbot "renew certonly --force-renew" __certbot "renew certonly --force-renew"
else else
__exec_command "certbot" "$@" __exec_command "certbot" "$@"
fi fi
exit $? exit $?
;; ;;
# Launch shell # Launch shell
*/bin/sh | */bin/bash | bash | sh | shell) */bin/sh | */bin/bash | bash | sh | shell)
shift 1 shift 1
__exec_command "${@:-/bin/bash -l}" __exec_command "${@:-/bin/bash -l}"
exit $? exit $?
;; ;;
# execute commands # execute commands
exec) exec)
shift 1 shift 1
__exec_command "${@:-echo "No commands given"}" __exec_command "${@:-echo "No commands given"}"
exit $? exit $?
;; ;;
# show/start init scripts # show/start init scripts
start) start)
shift 1 shift 1
export PATH="/usr/local/etc/docker/init.d:$PATH" export PATH="/usr/local/etc/docker/init.d:$PATH"
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
scripts="$(ls -A "/usr/local/etc/docker/init.d")" scripts="$(ls -A "/usr/local/etc/docker/init.d")"
[ -n "$scripts" ] && echo "$scripts" || echo "No scripts found in: /usr/local/etc/docker/init.d" [ -n "$scripts" ] && echo "$scripts" || echo "No scripts found in: /usr/local/etc/docker/init.d"
exit exit
elif [ "$1" = "all" ]; then elif [ "$1" = "all" ]; then
shift $# shift $#
if [ "$START_SERVICES" = "yes" ]; then if [ "$START_SERVICES" = "yes" ]; then
echo "$$" >"$ENTRYPOINT_PID_FILE" echo "$$" >"$ENTRYPOINT_PID_FILE"
__start_init_scripts "/usr/local/etc/docker/init.d" __start_init_scripts "/usr/local/etc/docker/init.d"
__no_exit __no_exit
elif [ -f "/usr/local/etc/docker/init.d/$1" ]; then elif [ -f "/usr/local/etc/docker/init.d/$1" ]; then
eval "/usr/local/etc/docker/init.d/$1" & eval "/usr/local/etc/docker/init.d/$1" &
__no_exit __no_exit
fi fi
fi fi
;; ;;
# Execute primary command # Execute primary command
*) *)
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
if [ ! -f "$ENTRYPOINT_PID_FILE" ]; then if [ ! -f "$ENTRYPOINT_PID_FILE" ]; then
echo "$$" >"$ENTRYPOINT_PID_FILE" echo "$$" >"$ENTRYPOINT_PID_FILE"
[ "$START_SERVICES" = "no" ] && [ "$CONTAINER_INIT" = "yes" ] || __start_init_scripts "/usr/local/etc/docker/init.d" [ "$START_SERVICES" = "no" ] && [ "$CONTAINER_INIT" = "yes" ] || __start_init_scripts "/usr/local/etc/docker/init.d"
fi fi
__no_exit __no_exit
else else
__exec_command "$@" __exec_command "$@"
fi fi
exit $? exit $?
;; ;;
esac esac
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# end of entrypoint # end of entrypoint

View File

@@ -29,9 +29,9 @@ GET_DNS_RECORD_CWD="$(realpath "$PWD")"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# colorization # colorization
if [ "$SHOW_RAW" = "true" ]; then if [ "$SHOW_RAW" = "true" ]; then
__printf_color() { printf '%b' "$1\n" | tr -d '\t' | sed '/^%b$/d;s,\x1B\[ 0-9;]*[a-zA-Z],,g'; } __printf_color() { printf '%b' "$1\n" | tr -d '\t' | sed '/^%b$/d;s,\x1B\[ 0-9;]*[a-zA-Z],,g'; }
else else
__printf_color() { { [ -z "$2" ] || DEFAULT_COLOR=$2; } && printf "%b" "$(tput setaf "$DEFAULT_COLOR" 2>/dev/null)" "$1\n" "$(tput sgr0 2>/dev/null)"; } __printf_color() { { [ -z "$2" ] || DEFAULT_COLOR=$2; } && printf "%b" "$(tput setaf "$DEFAULT_COLOR" 2>/dev/null)" "$1\n" "$(tput sgr0 2>/dev/null)"; }
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# check for command # check for command
@@ -45,10 +45,11 @@ __function_exists() { builtin type $1 >/dev/null 2>&1 || return 1; }
DEFAULT_COLOR="254" DEFAULT_COLOR="254"
GET_DNS_RECORD_EXIT_STATUS=0 GET_DNS_RECORD_EXIT_STATUS=0
GET_DNS_RECORD_DOMAIN_NAME="$1" GET_DNS_RECORD_DOMAIN_NAME="$1"
[ -n "$2" ] && GET_DNS_RECORD_TYPE=" $2 " || GET_DNS_RECORD_TYPE=" A "
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Main application # Main application
[ -n "$GET_DNS_RECORD_DOMAIN_NAME" ] || exit 2 [ -n "$GET_DNS_RECORD_DOMAIN_NAME" ] || exit 2
grep '^@' "/data/bind/zones/$GET_DNS_RECORD_DOMAIN_NAME.zone" | grep 'IN' | grep ' A ' | sed 's|.*A||g;s|;.*||g;s/^[ \t]*//' || exit 2 grep '^@' "/data/bind/zones/$GET_DNS_RECORD_DOMAIN_NAME.zone" | grep 'IN' | grep "$GET_DNS_RECORD_TYPE" | sed 's|.*A||g;s|;.*||g;s/^[ \t]*//' || exit 2
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# End application # End application
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -