mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-04-18 05:09:09 +02:00
Fix Settings.yaml corruption: move bashio::log calls outside stdout redirect block
The bashio-standalone.sh library writes log output to stdout (fd 1), not to
a preserved LOG_FD like the real bashio library. When bashio::log.info calls
were inside the { ... } > Settings.yaml block in immich_frame's 99-run.sh,
log messages leaked into the generated YAML file, corrupting it and causing
ImmichFrame to fail to parse account configuration correctly.
Changes:
- bashio-standalone.sh: redirect log output to LOG_FD (if available) or
stderr, matching real bashio behavior
- bashio-standalone.sh: add missing bashio::log.fatal and bashio::log.notice
aliases
- immich_frame 99-run.sh: move all bashio::log calls outside the
{ ... } > Settings.yaml block so only YAML content goes to the file
Agent-Logs-Url: https://github.com/alexbelgium/hassio-addons/sessions/87f542ba-1e4a-4b71-a787-e979818997df
Co-authored-by: alexbelgium <44178713+alexbelgium@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
82b0182b6a
commit
0b4da732ca
@@ -47,7 +47,14 @@ _bashio_color() {
|
||||
|
||||
_bashio_log() {
|
||||
local c="${1:-}"; shift || true
|
||||
printf '%s%s%s\n' "$(_bashio_color "$c")" "$*" "$(_bashio_color reset)"
|
||||
# Use LOG_FD (set by real bashio) if available, otherwise stderr.
|
||||
# This prevents log output from leaking into stdout when it is redirected
|
||||
# (e.g., { echo yaml; } > file).
|
||||
if [[ "${LOG_FD:-}" =~ ^[0-9]+$ ]] && { : >&"${LOG_FD}"; } 2>/dev/null; then
|
||||
printf '%s%s%s\n' "$(_bashio_color "$c")" "$*" "$(_bashio_color reset)" >&"$LOG_FD"
|
||||
else
|
||||
printf '%s%s%s\n' "$(_bashio_color "$c")" "$*" "$(_bashio_color reset)" >&2
|
||||
fi
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
@@ -155,9 +162,11 @@ bashio::log.magenta() { _bashio_log magenta "$*"; }
|
||||
|
||||
# Common aliases
|
||||
bashio::log.info() { bashio::log.blue "$@"; }
|
||||
bashio::log.notice() { bashio::log.blue "$@"; }
|
||||
bashio::log.warning() { bashio::log.yellow "$@"; }
|
||||
bashio::log.error() { bashio::log.red "$@"; }
|
||||
bashio::log.debug() { printf '%s\n' "$*"; }
|
||||
bashio::log.fatal() { bashio::log.red "$@"; }
|
||||
bashio::log.debug() { _bashio_log "" "$*"; }
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Supervisor shim
|
||||
|
||||
@@ -115,6 +115,25 @@ ACCOUNT_SCHEMA_OPTS="Albums ExcludedAlbums People Tags ShowFavorites ShowMemorie
|
||||
ShowArchived ShowVideos ImagesFromDays ImagesFromDate ImagesUntilDate Rating"
|
||||
|
||||
# ---- Build Settings.yaml ----
|
||||
|
||||
# Determine account configuration mode (and validate) before writing the file
|
||||
ACCOUNT_COUNT=$(jq '.Accounts // [] | length' /data/options.json 2>/dev/null || echo 0)
|
||||
|
||||
if [ "$ACCOUNT_COUNT" -gt 0 ]; then
|
||||
ACCOUNT_MODE="accounts_list"
|
||||
bashio::log.info "Configuring ${ACCOUNT_COUNT} account(s) from Accounts list"
|
||||
elif config_has '.ApiKey' && config_has '.ImmichServerUrl'; then
|
||||
ACCOUNT_MODE="single"
|
||||
bashio::log.info "Using single account configuration"
|
||||
elif [ -n "${ACCOUNT_ENVS[ImmichServerUrl]:-}" ] && [ -n "${ACCOUNT_ENVS[ApiKey]:-}" ]; then
|
||||
ACCOUNT_MODE="env_vars"
|
||||
bashio::log.info "Using account configuration from env_vars"
|
||||
else
|
||||
bashio::log.fatal "No accounts configured! Set either 'Accounts' list or both 'ApiKey' and 'ImmichServerUrl'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Generate Settings.yaml — only echo/yaml_kv inside this block (no bashio::log)
|
||||
{
|
||||
# -- General section --
|
||||
GENERAL_STARTED=false
|
||||
@@ -135,10 +154,7 @@ ACCOUNT_SCHEMA_OPTS="Albums ExcludedAlbums People Tags ShowFavorites ShowMemorie
|
||||
done
|
||||
|
||||
# -- Accounts section --
|
||||
ACCOUNT_COUNT=$(jq '.Accounts // [] | length' /data/options.json 2>/dev/null || echo 0)
|
||||
|
||||
if [ "$ACCOUNT_COUNT" -gt 0 ]; then
|
||||
bashio::log.info "Configuring ${ACCOUNT_COUNT} account(s) from Accounts list"
|
||||
if [ "$ACCOUNT_MODE" = "accounts_list" ]; then
|
||||
echo "Accounts:"
|
||||
for i in $(seq 0 $((ACCOUNT_COUNT - 1))); do
|
||||
SRV="$(config_val ".Accounts[${i}].ImmichServerUrl")"
|
||||
@@ -159,12 +175,9 @@ ACCOUNT_SCHEMA_OPTS="Albums ExcludedAlbums People Tags ShowFavorites ShowMemorie
|
||||
yaml_kv " " "$key" "${ACCOUNT_ENVS[$key]}"
|
||||
fi
|
||||
done
|
||||
|
||||
bashio::log.info " Account $((i + 1)): ${SRV}"
|
||||
done
|
||||
|
||||
elif config_has '.ApiKey' && config_has '.ImmichServerUrl'; then
|
||||
bashio::log.info "Using single account configuration"
|
||||
elif [ "$ACCOUNT_MODE" = "single" ]; then
|
||||
SRV="$(config_val '.ImmichServerUrl')"
|
||||
KEY="$(config_val '.ApiKey')"
|
||||
echo "Accounts:"
|
||||
@@ -177,8 +190,7 @@ ACCOUNT_SCHEMA_OPTS="Albums ExcludedAlbums People Tags ShowFavorites ShowMemorie
|
||||
yaml_kv " " "$key" "${ACCOUNT_ENVS[$key]}"
|
||||
done
|
||||
|
||||
elif [ -n "${ACCOUNT_ENVS[ImmichServerUrl]:-}" ] && [ -n "${ACCOUNT_ENVS[ApiKey]:-}" ]; then
|
||||
bashio::log.info "Using account configuration from env_vars"
|
||||
elif [ "$ACCOUNT_MODE" = "env_vars" ]; then
|
||||
echo "Accounts:"
|
||||
echo " - ImmichServerUrl: '${ACCOUNT_ENVS[ImmichServerUrl]//\'/\'\'}'"
|
||||
echo " ApiKey: '${ACCOUNT_ENVS[ApiKey]//\'/\'\'}'"
|
||||
@@ -187,12 +199,16 @@ ACCOUNT_SCHEMA_OPTS="Albums ExcludedAlbums People Tags ShowFavorites ShowMemorie
|
||||
in_list "$key" " ImmichServerUrl ApiKey " && continue
|
||||
yaml_kv " " "$key" "${ACCOUNT_ENVS[$key]}"
|
||||
done
|
||||
else
|
||||
bashio::log.fatal "No accounts configured! Set either 'Accounts' list or both 'ApiKey' and 'ImmichServerUrl'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
} > "${SETTINGS_FILE}"
|
||||
|
||||
# Log account details after YAML generation
|
||||
if [ "$ACCOUNT_MODE" = "accounts_list" ]; then
|
||||
for i in $(seq 0 $((ACCOUNT_COUNT - 1))); do
|
||||
bashio::log.info " Account $((i + 1)): $(config_val ".Accounts[${i}].ImmichServerUrl")"
|
||||
done
|
||||
fi
|
||||
chmod 600 "${SETTINGS_FILE}"
|
||||
bashio::log.info "Settings.yaml generated at ${SETTINGS_FILE}"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user