infra: CHANGE some cleanup regarding the .env process with container
This commit is contained in:
parent
d0373f0198
commit
8b135a321a
3 changed files with 43 additions and 12 deletions
29
build.sh
29
build.sh
|
|
@ -11,17 +11,28 @@ TEMPLATES_DIR="templates"
|
|||
ASSETS_DIR="assets"
|
||||
|
||||
# Load .env if present; see .env.example for every option and its default.
|
||||
# Precedence: command line flags > environment > .env > built-in defaults.
|
||||
# Parsed as plain KEY=VALUE (not sourced), so the same file also works with
|
||||
# `podman run --env-file`. Values already in the environment are left alone,
|
||||
# which gives: flags > environment > .env > built-in defaults.
|
||||
ENV_FILE="${ENV_FILE:-.env}"
|
||||
if [[ -f "$ENV_FILE" ]]; then
|
||||
# Remember caller-supplied values so the file cannot clobber them
|
||||
env_override=$(export -p | grep -E '^declare -x (STRIP_EXIF|GALLERY_TITLE|SHOW_FOOTER)=' || true)
|
||||
# shellcheck source=/dev/null
|
||||
source "$ENV_FILE"
|
||||
if [[ -n "$env_override" ]]; then
|
||||
eval "$env_override"
|
||||
fi
|
||||
unset env_override
|
||||
while IFS= read -r env_line || [[ -n "$env_line" ]]; do
|
||||
env_line="${env_line%$'\r'}" # tolerate CRLF
|
||||
env_line="${env_line#"${env_line%%[![:space:]]*}"}" # trim leading space
|
||||
[[ -z "$env_line" || "$env_line" == \#* ]] && continue
|
||||
[[ "$env_line" == *=* ]] || continue
|
||||
env_key="${env_line%%=*}"
|
||||
env_val="${env_line#*=}"
|
||||
env_key="${env_key%"${env_key##*[![:space:]]}"}" # trim trailing space
|
||||
[[ "$env_key" =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]] || continue
|
||||
# Strip one layer of matching quotes (omit them for --env-file compatibility)
|
||||
if [[ ${#env_val} -ge 2 && ( "$env_val" == \"*\" || "$env_val" == \'*\' ) ]]; then
|
||||
env_val="${env_val:1:${#env_val}-2}"
|
||||
fi
|
||||
# Anything already set (environment, or earlier in this script) wins
|
||||
[[ -n "${!env_key+x}" ]] || printf -v "$env_key" '%s' "$env_val"
|
||||
done < "$ENV_FILE"
|
||||
unset env_line env_key env_val
|
||||
fi
|
||||
|
||||
# Image metadata (EXIF/GPS/IPTC/XMP) is stripped by default.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue