This commit is contained in:
2026-08-17 11:19:05 -07:00
parent ca0f89a671
commit cf87fdba1a
6 changed files with 199 additions and 5 deletions
+16 -4
View File
@@ -98,12 +98,24 @@ log "Installing Python dependencies (this takes a minute)"
chown -R "$SVC_USER:$SVC_USER" "$APP_DIR"
# --- Configuration --------------------------------------------------------
# --- Configuration --------------------------------------------------------
# Prefer a filled-in .env if one exists, otherwise fall back to the template.
ENV_SRC=""
for candidate in "$SRC_DIR/.env" "$SRC_DIR/.env.example"; do
[[ -f "$candidate" ]] && { ENV_SRC="$candidate"; break; }
done
[[ -n "$ENV_SRC" ]] || die "Can't find $SRC_DIR/.env or $SRC_DIR/.env.example to seed the config from."
mkdir -p "$CONF_DIR"
if [[ ! -f "$CONF_DIR/env" ]]; then
log "Creating $CONF_DIR/env from the template"
# An empty file counts as "not configured" -- a previous failed run can leave
# a zero-byte config behind, and silently keeping it is worse than replacing it.
if [[ ! -s "$CONF_DIR/env" ]]; then
log "Creating $CONF_DIR/env from $(basename "$ENV_SRC")"
# systemd EnvironmentFile does not understand quotes or inline comments the
# way a shell does, so strip comments and blank lines out of the example.
grep -vE '^\s*(#|$)' "$SRC_DIR/.env.example" > "$CONF_DIR/env"
# way a shell does, so strip comments and blank lines out of the source.
# Write to a temp file first so a failure here can't leave an empty config.
grep -vE '^\s*(#|$)' "$ENV_SRC" > "$CONF_DIR/env.tmp"
mv "$CONF_DIR/env.tmp" "$CONF_DIR/env"
NEW_CONFIG=1
else
log "Keeping existing $CONF_DIR/env"