pixelfed/docker/shared/root/docker/entrypoint.sh

106 wiersze
3.6 KiB
Bash
Czysty Zwykły widok Historia

2024-01-04 16:08:01 +00:00
#!/bin/bash
2024-01-04 22:16:25 +00:00
# short curcuit the entrypoint if $ENTRYPOINT_SKIP isn't set to 0
2024-01-04 21:55:24 +00:00
if [[ ${ENTRYPOINT_SKIP:=0} != 0 ]]; then
exec "$@"
fi
2024-01-04 16:08:01 +00:00
2024-01-15 17:16:00 +00:00
: "${ENTRYPOINT_ROOT:="/docker"}"
2024-01-04 20:55:04 +00:00
export ENTRYPOINT_ROOT
2024-01-15 17:16:00 +00:00
# Directory where entrypoint scripts lives
: "${ENTRYPOINT_D_ROOT:="${ENTRYPOINT_ROOT}/entrypoint.d/"}"
export ENTRYPOINT_D_ROOT
: "${DOCKER_APP_HOST_OVERRIDES_PATH:="${ENTRYPOINT_ROOT}/overrides"}"
export DOCKER_APP_HOST_OVERRIDES_PATH
2024-01-04 22:16:25 +00:00
# Space separated list of scripts the entrypoint runner should skip
2024-01-15 17:16:00 +00:00
: "${ENTRYPOINT_SKIP_SCRIPTS:=""}"
2024-01-04 22:16:25 +00:00
# Load helper scripts
2024-01-15 17:16:00 +00:00
#
# shellcheck source=SCRIPTDIR/helpers.sh
source "${ENTRYPOINT_ROOT}/helpers.sh"
2024-01-04 21:55:24 +00:00
2024-01-04 22:16:25 +00:00
# Set the entrypoint name for logging
2024-01-05 00:11:20 +00:00
entrypoint-set-script-name "entrypoint.sh"
2024-01-04 21:55:24 +00:00
2024-01-04 22:16:25 +00:00
# Convert ENTRYPOINT_SKIP_SCRIPTS into a native bash array for easier lookup
2024-01-04 21:55:24 +00:00
declare -a skip_scripts
2024-01-15 17:16:00 +00:00
# shellcheck disable=SC2034
IFS=' ' read -ar skip_scripts <<< "$ENTRYPOINT_SKIP_SCRIPTS"
2024-01-04 20:55:04 +00:00
2024-01-04 22:16:25 +00:00
# Ensure the entrypoint root folder exists
2024-01-15 17:16:00 +00:00
mkdir -p "${ENTRYPOINT_D_ROOT}"
2024-01-04 21:21:00 +00:00
2024-01-15 17:16:00 +00:00
# If ENTRYPOINT_D_ROOT directory is empty, warn and run the regular command
2024-01-26 20:17:54 +00:00
if directory-is-empty "${ENTRYPOINT_D_ROOT}"; then
2024-01-15 17:16:00 +00:00
log-warning "No files found in ${ENTRYPOINT_D_ROOT}, skipping configuration"
2024-01-04 22:16:25 +00:00
exec "$@"
fi
2024-01-04 20:55:04 +00:00
# If the overridess directory exists, then copy all files into the container
if ! directory-is-empty "${DOCKER_APP_HOST_OVERRIDES_PATH}"; then
log-info "Overrides directory is not empty, copying files"
run-as-current-user cp --verbose --recursive "${DOCKER_APP_HOST_OVERRIDES_PATH}/." /
fi
2024-01-15 17:16:00 +00:00
acquire-lock "entrypoint.sh"
2024-01-05 23:16:26 +00:00
2024-01-04 22:16:25 +00:00
# Start scanning for entrypoint.d files to source or run
2024-01-15 17:16:00 +00:00
log-info "looking for shell scripts in [${ENTRYPOINT_D_ROOT}]"
2024-01-04 20:55:04 +00:00
2024-01-15 17:16:00 +00:00
find "${ENTRYPOINT_D_ROOT}" -follow -type f -print | sort -V | while read -r file; do
2024-01-04 22:16:25 +00:00
# Skip the script if it's in the skip-script list
2024-01-15 17:16:00 +00:00
if in-array "$(get-entrypoint-script-name "${file}")" skip_scripts; then
log-warning "Skipping script [${file}] since it's in the skip list (\$ENTRYPOINT_SKIP_SCRIPTS)"
2024-01-04 20:55:04 +00:00
2024-01-04 22:16:25 +00:00
continue
fi
2024-01-04 21:21:00 +00:00
2024-01-04 22:16:25 +00:00
# Inspect the file extension of the file we're processing
case "${file}" in
*.envsh)
if ! is-executable "${file}"; then
# warn on shell scripts without exec bit
log-error-and-exit "File [${file}] is not executable (please 'chmod +x' it)"
fi
log-info "${section_message_color}============================================================${color_clear}"
log-info "${section_message_color}Sourcing [${file}]${color_clear}"
log-info "${section_message_color}============================================================${color_clear}"
# shellcheck disable=SC1090
source "${file}"
# the sourced file will (should) than the log prefix, so this restores our own
# "global" log prefix once the file is done being sourced
entrypoint-restore-script-name
;;
*.sh)
if ! is-executable "${file}"; then
# warn on shell scripts without exec bit
log-error-and-exit "File [${file}] is not executable (please 'chmod +x' it)"
fi
log-info "${section_message_color}============================================================${color_clear}"
log-info "${section_message_color}Executing [${file}]${color_clear}"
log-info "${section_message_color}============================================================${color_clear}"
"${file}"
;;
*)
log-warning "Ignoring unrecognized file [${file}]"
;;
2024-01-04 22:16:25 +00:00
esac
done
2024-01-04 21:55:24 +00:00
2024-01-15 17:16:00 +00:00
release-lock "entrypoint.sh"
2024-01-05 23:16:26 +00:00
2024-01-04 22:16:25 +00:00
log-info "Configuration complete; ready for start up"
2024-01-04 16:08:01 +00:00
exec "$@"