Files
2026-09-09 14:37:20 +02:00

40 lines
1.5 KiB
Bash

#!/usr/bin/env bash
# Read literal .env values without executing shell code. Environment wins.
env_value() {
python3 - "$ROOT/.env" "$1" <<'PY'
import os, pathlib, shlex, sys
path, key = pathlib.Path(sys.argv[1]), sys.argv[2]
if key in os.environ:
print(os.environ[key], end='')
elif path.exists():
for line in path.read_text().splitlines():
line = line.strip().removeprefix('export ')
name, sep, value = line.partition('=')
if sep and name.strip() == key:
parts = shlex.split(value, comments=True)
if len(parts) > 1:
raise SystemExit(f'Quote whitespace in .env value {key}')
print(parts[0] if parts else '', end='')
break
PY
}
# These deployment procedures manage the established Hostsharing layout only.
require_deploy_layout() {
local deploy_login=$1 setting expected configured
for setting in BACKEND_DIR BACKEND_JDK_DIR BACKEND_PORT BACKEND_URL DEPLOY_TARGET; do
case "$setting" in
BACKEND_DIR) expected=opt/werkjournal ;;
BACKEND_JDK_DIR) expected=opt/jdk25 ;;
BACKEND_PORT) expected=18090 ;;
BACKEND_URL) expected=https://werkjournal.javagil.de ;;
DEPLOY_TARGET) expected="$deploy_login:doms/werkjournal.javagil.de/htdocs-ssl" ;;
esac
configured=$(env_value "$setting")
if [[ -n $configured && $configured != "$expected" ]]; then
printf '%s differs from the supported deployment layout.\n' "$setting" >&2
return 2
fi
done
}