1
0
Fork 0
pixelfed/docker/shared/root/docker/entrypoint.sh

90 lines
2.5 KiB
Bash
Raw Normal View History

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-04 22:16:25 +00:00
# Directory where entrypoint scripts lives
2024-01-04 20:55:04 +00:00
: ${ENTRYPOINT_ROOT:="/docker/entrypoint.d/"}
export ENTRYPOINT_ROOT
2024-01-04 22:16:25 +00:00
# Space separated list of scripts the entrypoint runner should skip
: ${ENTRYPOINT_SKIP_SCRIPTS:=""}
# Load helper scripts
2024-01-04 21:55:24 +00:00
source /docker/helpers.sh
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
IFS=' ' read -a 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-04 21:55:24 +00:00
mkdir -p "${ENTRYPOINT_ROOT}"
2024-01-04 21:21:00 +00:00
2024-01-04 22:16:25 +00:00
# If ENTRYPOINT_ROOT directory is empty, warn and run the regular command
if is-directory-empty "${ENTRYPOINT_ROOT}"; then
log-warning "No files found in ${ENTRYPOINT_ROOT}, skipping configuration"
exec "$@"
fi
2024-01-04 20:55:04 +00:00
2024-01-05 23:16:26 +00:00
acquire-lock
2024-01-04 22:16:25 +00:00
# Start scanning for entrypoint.d files to source or run
log-info "looking for shell scripts in [${ENTRYPOINT_ROOT}]"
2024-01-04 20:55:04 +00:00
2024-01-04 22:16:25 +00:00
find "${ENTRYPOINT_ROOT}" -follow -type f -print | sort -V | while read -r file; do
# Skip the script if it's in the skip-script list
if in-array $(get-entrypoint-script-name "${file}") skip_scripts; then
log-warning "Skipping script [${script_name}] 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
2024-01-04 21:55:24 +00:00
2024-01-05 23:16:26 +00:00
log-info ""
log-info "${notice_message_color}Sourcing [${file}]${color_clear}"
log-info ""
2024-01-04 21:55:24 +00:00
2024-01-04 22:16:25 +00:00
source "${file}"
2024-01-04 20:55:04 +00:00
2024-01-04 22:16:25 +00:00
# the sourced file will (should) than the log prefix, so this restores our own
# "global" log prefix once the file is done being sourced
2024-01-05 00:11:20 +00:00
entrypoint-restore-script-name
2024-01-04 22:16:25 +00:00
;;
2024-01-04 20:55:04 +00:00
2024-01-04 22:16:25 +00:00
*.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
2024-01-04 16:08:01 +00:00
2024-01-05 23:16:26 +00:00
log-info ""
log-info "${notice_message_color}Executing [${file}]${color_clear}"
log-info ""
2024-01-04 23:04:25 +00:00
2024-01-04 22:16:25 +00:00
"${file}"
;;
2024-01-04 21:55:24 +00:00
2024-01-04 22:16:25 +00:00
*)
log-warning "Ignoring unrecognized file [${file}]"
;;
esac
done
2024-01-04 21:55:24 +00:00
2024-01-05 23:16:26 +00:00
release-lock
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 "$@"