mirror of
https://github.com/dockersrc/debian
synced 2026-06-30 17:45:56 -04:00
🗃 Modified: rootfs/usr/local/etc/docker/functions/entrypoint.sh 🗃
Modified: rootfs/usr/local/etc/docker/functions/entrypoint.sh
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck shell=bash
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
##@Version : 202606041215-git
|
||||
##@Version : 202606261430-git
|
||||
# @@Author : Jason Hempstead
|
||||
# @@Contact : git-admin@casjaysdev.pro
|
||||
# @@License : LICENSE.md
|
||||
@@ -364,14 +364,14 @@ __init_working_dir() {
|
||||
# cd to dir
|
||||
__cd "${workdir:-$home}"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
echo "Setting the working directory to: $PWD"
|
||||
[ "$DEBUGGER" = "on" ] && echo "Setting the working directory to: $PWD"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
export WORK_DIR="$workdir" HOME="$home"
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__exec_service() {
|
||||
local count=6
|
||||
echo "Starting $1"
|
||||
[ "$DEBUGGER" = "on" ] && echo "Starting $1"
|
||||
eval "$@" 2>>/dev/stderr >>/data/logs/start.log &
|
||||
while [ $count -ne 0 ]; do
|
||||
sleep 3
|
||||
@@ -597,7 +597,7 @@ __cron() {
|
||||
[ -d "/run/cron" ] || mkdir -p "/run/cron"
|
||||
echo "$pid" >"/run/cron/$bin.pid"
|
||||
echo "$command" >"/run/cron/$bin.run"
|
||||
echo "Log is saved to /data/logs/cron.log"
|
||||
[ "$DEBUGGER" = "on" ] && echo "Log is saved to /data/logs/cron.log"
|
||||
# eval is intentional: $command is operator-controlled input from this container's init
|
||||
while :; do
|
||||
eval "$command"
|
||||
@@ -635,7 +635,7 @@ __symlink() {
|
||||
[ "$from" = "$to" ] && return 0
|
||||
__rm "$from"
|
||||
[ -d "${from%/*}" ] || mkdir -p "${from%/*}" 2>/dev/null
|
||||
ln -sf "$to" "$from" && echo "Created symlink to $from > $to"
|
||||
ln -sf "$to" "$from" && [ "$DEBUGGER" = "on" ] && echo "Created symlink: $from -> $to"
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__file_copy() {
|
||||
@@ -647,7 +647,7 @@ __file_copy() {
|
||||
if [ -n "$from" ] && [ -e "$from" ] && [ -n "$dest" ]; then
|
||||
if [ -d "$from" ]; then
|
||||
if cp -Rf "$from/." "$dest/" &>/dev/null; then
|
||||
printf '%s\n' "Copied: $from > $dest"
|
||||
[ "$DEBUGGER" = "on" ] && printf '%s\n' "Copied: $from > $dest"
|
||||
return 0
|
||||
else
|
||||
printf '%s\n' "Copy failed: $from < $dest" >&2
|
||||
@@ -655,7 +655,7 @@ __file_copy() {
|
||||
fi
|
||||
else
|
||||
if cp -Rf "$from" "$dest" &>/dev/null; then
|
||||
printf '%s\n' "Copied: $from > $dest"
|
||||
[ "$DEBUGGER" = "on" ] && printf '%s\n' "Copied: $from > $dest"
|
||||
return 0
|
||||
else
|
||||
printf '%s\n' "Copy failed: $from < $dest" >&2
|
||||
@@ -691,25 +691,33 @@ __setup_directories() {
|
||||
if [ "$IS_WEB_SERVER" = "yes" ]; then
|
||||
APPLICATION_DIRS="$APPLICATION_DIRS $WWW_ROOT_DIR"
|
||||
__initialize_www_root
|
||||
(echo "Creating directory $WWW_ROOT_DIR with permissions 777" && mkdir -p "$WWW_ROOT_DIR" && find "$WWW_ROOT_DIR" -type d -exec chmod -f 777 {} \;) 2>/dev/stderr | tee -p -a "/data/logs/init.txt"
|
||||
mkdir -p "$WWW_ROOT_DIR" 2>/dev/null
|
||||
find "$WWW_ROOT_DIR" -type d -exec chmod -f 777 {} \; 2>/dev/null
|
||||
[ "$DEBUGGER" = "on" ] && echo "Created directory $WWW_ROOT_DIR"
|
||||
fi
|
||||
# Setup DATABASE_DIR
|
||||
if [ "$IS_DATABASE_SERVICE" = "yes" ] || [ "$USES_DATABASE_SERVICE" = "yes" ]; then
|
||||
APPLICATION_DIRS="$APPLICATION_DIRS $DATABASE_DIR"
|
||||
if __is_dir_empty "$DATABASE_DIR" || [ ! -d "$DATABASE_DIR" ]; then
|
||||
(echo "Creating directory $DATABASE_DIR with permissions 777" && mkdir -p "$DATABASE_DIR" && chmod -f 777 "$DATABASE_DIR") 2>/dev/stderr | tee -p -a "/data/logs/init.txt"
|
||||
mkdir -p "$DATABASE_DIR" 2>/dev/null
|
||||
chmod -f 777 "$DATABASE_DIR" 2>/dev/null
|
||||
[ "$DEBUGGER" = "on" ] && echo "Created directory $DATABASE_DIR"
|
||||
fi
|
||||
fi
|
||||
# create default directories
|
||||
for filedirs in $ADD_APPLICATION_DIRS $APPLICATION_DIRS; do
|
||||
if [ -n "$filedirs" ] && [ ! -d "$filedirs" ]; then
|
||||
(echo "Creating directory $filedirs with permissions 777" && mkdir -p "$filedirs" && chmod -f 777 "$filedirs") 2>/dev/stderr | tee -p -a "/data/logs/init.txt"
|
||||
mkdir -p "$filedirs" 2>/dev/null
|
||||
chmod -f 777 "$filedirs" 2>/dev/null
|
||||
[ "$DEBUGGER" = "on" ] && echo "Created directory $filedirs"
|
||||
fi
|
||||
done
|
||||
# create default files
|
||||
for application_files in $ADD_APPLICATION_FILES $APPLICATION_FILES; do
|
||||
if [ -n "$application_files" ] && [ ! -e "$application_files" ]; then
|
||||
(echo "Creating file $application_files with permissions 777" && touch "$application_files" && chmod -Rf 777 "$application_files") 2>/dev/stderr | tee -p -a "/data/logs/init.txt"
|
||||
touch "$application_files" 2>/dev/null
|
||||
chmod -Rf 777 "$application_files" 2>/dev/null
|
||||
[ "$DEBUGGER" = "on" ] && echo "Created file $application_files"
|
||||
fi
|
||||
done
|
||||
}
|
||||
@@ -723,7 +731,8 @@ __fix_permissions() {
|
||||
if grep -shq "^$change_user:" "/etc/passwd"; then
|
||||
for permissions in $ADD_APPLICATION_DIRS $APPLICATION_DIRS; do
|
||||
if [ -n "$permissions" ] && [ -e "$permissions" ]; then
|
||||
(chown -Rf $change_user "$permissions" && echo "changed ownership on $permissions to user:$change_user") 2>/dev/stderr | tee -p -a "/data/logs/init.txt"
|
||||
chown -Rf "$change_user" "$permissions" 2>/dev/null
|
||||
[ "$DEBUGGER" = "on" ] && echo "Changed ownership of $permissions to $change_user"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
@@ -732,7 +741,8 @@ __fix_permissions() {
|
||||
if grep -shq "^$change_group:" "/etc/group"; then
|
||||
for permissions in $ADD_APPLICATION_DIRS $APPLICATION_DIRS; do
|
||||
if [ -n "$permissions" ] && [ -e "$permissions" ]; then
|
||||
(chgrp -Rf $change_group "$permissions" && echo "changed group ownership on $permissions to group $change_group") 2>/dev/stderr | tee -p -a "/data/logs/init.txt"
|
||||
chgrp -Rf "$change_group" "$permissions" 2>/dev/null
|
||||
[ "$DEBUGGER" = "on" ] && echo "Changed group of $permissions to $change_group"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
@@ -792,7 +802,7 @@ __set_user_group_id() {
|
||||
return 0
|
||||
fi
|
||||
if [ -z "$set_user" ] || [ "$set_user" = "root" ]; then
|
||||
return
|
||||
return 0
|
||||
fi
|
||||
if grep -shq "^$set_user:" "/etc/passwd" "/etc/group"; then
|
||||
if __check_for_guid "$set_gid"; then
|
||||
@@ -1005,7 +1015,7 @@ __start_init_scripts() {
|
||||
|
||||
# Clean stale PID files from previous runs
|
||||
if [ ! -f "/run/.start_init_scripts.pid" ]; then
|
||||
echo "🧹 Cleaning stale PID files from previous container run"
|
||||
[ "$DEBUGGER" = "on" ] && echo "Cleaning stale PID files from previous container run"
|
||||
rm -f /run/*.pid /run/init.d/*.pid 2>/dev/null || true
|
||||
fi
|
||||
|
||||
@@ -1022,18 +1032,18 @@ __start_init_scripts() {
|
||||
done
|
||||
(shopt -s nullglob; chmod -Rf 755 "$init_dir"/*.sh 2>/dev/null || true)
|
||||
|
||||
echo "🚀 Starting container services initialization"
|
||||
echo "📂 Init directory: $init_dir"
|
||||
echo "📊 Services to start: $init_count"
|
||||
echo "📋 Found $init_count service scripts to execute"
|
||||
if [ "$DEBUGGER" = "on" ]; then
|
||||
echo "Starting container services initialization"
|
||||
echo "Init directory: $init_dir — $init_count service scripts to execute"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
for init in "$init_dir"/*.sh; do
|
||||
if [ -x "$init" ]; then
|
||||
touch "$pidFile"
|
||||
name="${init##*/}"
|
||||
service="${name#*-}"; service="${service%.sh}"
|
||||
__service_banner "🔧" "Executing service script:" "${init##*/}"
|
||||
[ "$DEBUGGER" = "on" ] && __service_banner "🔧" "Executing service script:" "${init##*/}"
|
||||
# Execute the init script and capture the exit code (subshell isolates exit calls)
|
||||
if ( source "$init" ); then
|
||||
# Check if service was disabled first
|
||||
@@ -1125,10 +1135,9 @@ __start_init_scripts() {
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__setup_mta() {
|
||||
[ -d "/etc/ssmtp" ] || [ -d "/etc/postfix" ] || return
|
||||
if [ ! -d "/config/ssmtp" ] || [ ! -d "/config/postfix" ]; then
|
||||
echo "Configuring smtp server"
|
||||
fi
|
||||
# Check for an installed MTA binary — directories alone cannot be trusted because
|
||||
# /etc/postfix ships in some base images (casjaysdev/alpine) even without postfix.
|
||||
command -v ssmtp &>/dev/null || command -v postfix &>/dev/null || return 0
|
||||
local exitCode=0
|
||||
local relay_port="${EMAIL_RELAY//*:/}"
|
||||
local relay_server="${EMAIL_RELAY//:*/}"
|
||||
@@ -1172,7 +1181,7 @@ EOF
|
||||
__symlink "/config/ssmtp/revaliases" "/etc/ssmtp/revaliases"
|
||||
__initialize_replace_variables "/etc/ssmtp/revaliases"
|
||||
fi
|
||||
echo "Done setting up ssmtp"
|
||||
[ "$DEBUGGER" = "on" ] && echo "Done setting up ssmtp"
|
||||
fi
|
||||
|
||||
################# postfix relay setup
|
||||
@@ -1224,7 +1233,7 @@ EOF
|
||||
if [ ! -f "/run/init.d/postfix.pid" ]; then
|
||||
__exec_service postfix start
|
||||
fi
|
||||
echo "Done setting up postfix"
|
||||
[ "$DEBUGGER" = "on" ] && echo "Done setting up postfix"
|
||||
fi
|
||||
fi
|
||||
[ -f "/root/dead.letter" ] && __rm "/root/dead.letter"
|
||||
@@ -1335,12 +1344,12 @@ __initialize_system_etc() {
|
||||
if [ -n "$conf_dir" ] && [ -e "$conf_dir" ]; then
|
||||
files=$(find "$conf_dir"/* -not -path '*/env/*' -type f 2>/dev/null | sort -u | sed 's|/config/||')
|
||||
directories=$(find "$conf_dir"/* -not -path '*/env/*' -type d 2>/dev/null | sort -u | sed 's|/config/||')
|
||||
echo "Copying config files to system: $conf_dir > /etc/${conf_dir//\/config\//}"
|
||||
[ "$DEBUGGER" = "on" ] && echo "Copying config: $conf_dir > /etc/${conf_dir//\/config\//}"
|
||||
if [ -n "$directories" ]; then
|
||||
for d in $directories; do
|
||||
dir="/etc/$d"
|
||||
echo "Creating directory: $dir"
|
||||
mkdir -p "$dir"
|
||||
[ "$DEBUGGER" = "on" ] && echo "Created directory: $dir"
|
||||
done
|
||||
fi
|
||||
for f in $files; do
|
||||
@@ -1359,7 +1368,7 @@ __initialize_custom_bin_dir() {
|
||||
[ -d "/data/bin" ] && SET_USR_BIN+="$(__find /data/bin f) "
|
||||
[ -d "/config/bin" ] && SET_USR_BIN+="$(__find /config/bin f) "
|
||||
if [ -n "$SET_USR_BIN" ]; then
|
||||
echo "Setting up bin $SET_USR_BIN > $LOCAL_BIN_DIR"
|
||||
[ "$DEBUGGER" = "on" ] && echo "Setting up bin: $SET_USR_BIN > $LOCAL_BIN_DIR"
|
||||
for create_bin_template in $SET_USR_BIN; do
|
||||
if [ -n "$create_bin_template" ]; then
|
||||
create_bin_name="${create_bin_template##*/}"
|
||||
@@ -1621,3 +1630,4 @@ export ENTRYPOINT_PID_FILE ENTRYPOINT_INIT_FILE ENTRYPOINT_FIRST_RUN
|
||||
export -f __get_pid __start_init_scripts __is_running __update_ssl_certs __create_ssl_cert
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# end of functions
|
||||
# vim: set ft=sh ts=4 sw=4 st=4 et :
|
||||
|
||||
Reference in New Issue
Block a user