From b477a329ceaf5546c1c8a07569cd7850c00180ac Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 5 Jul 2025 08:25:41 +0000 Subject: [PATCH] GitHub bot: fix linting issues (nobuild) --- .templates/01-config_yaml.sh | 118 ++++++++++++++++++----------------- 1 file changed, 60 insertions(+), 58 deletions(-) diff --git a/.templates/01-config_yaml.sh b/.templates/01-config_yaml.sh index 79be8a7eb..1c233029c 100644 --- a/.templates/01-config_yaml.sh +++ b/.templates/01-config_yaml.sh @@ -16,39 +16,40 @@ set -euo pipefail # Run outside HA? then do nothing if [[ ! -d /config ]] || ! bashio::supervisor.ping &>/dev/null; then - echo "..." - exit 0 + echo "..." + exit 0 fi -slug="${HOSTNAME/-/_}" ; slug="${slug#*_}" +slug="${HOSTNAME/-/_}" +slug="${slug#*_}" # ----------------------------------------------------------------------------- # Resolve CONFIGSOURCE # # ----------------------------------------------------------------------------- if [[ ! -f /config/configuration.yaml && ! -f /config/configuration.json ]]; then - CONFIGLOCATION="/config" # New architecture - CONFIGFILEBROWSER="/addon_configs/${HOSTNAME/-/_}/config.yaml" + CONFIGLOCATION="/config" # New architecture + CONFIGFILEBROWSER="/addon_configs/${HOSTNAME/-/_}/config.yaml" else - CONFIGLOCATION="/config/addons_config/${slug}" # Legacy architecture - CONFIGFILEBROWSER="/homeassistant/addons_config/${slug}/config.yaml" + CONFIGLOCATION="/config/addons_config/${slug}" # Legacy architecture + CONFIGFILEBROWSER="/homeassistant/addons_config/${slug}/config.yaml" fi mkdir -p "$CONFIGLOCATION" CONFIGSOURCE="$CONFIGLOCATION/config.yaml" if bashio::config.has_value 'CONFIG_LOCATION'; then - CONFIGSOURCE="$(bashio::config "CONFIG_LOCATION")" - [[ "$CONFIGSOURCE" == *.* ]] && CONFIGSOURCE="$(dirname "$CONFIGSOURCE")" - [[ "$CONFIGSOURCE" != *.yaml ]] && CONFIGSOURCE="${CONFIGSOURCE%/}/config.yaml" - case "$CONFIGSOURCE" in - /share/*|/config/*|/data/*) :;; - *) bashio::log.red "CONFIG_LOCATION must be in /share, /config or /data – defaulting." && CONFIGSOURCE="$CONFIGLOCATION/config.yaml";; - esac + CONFIGSOURCE="$(bashio::config "CONFIG_LOCATION")" + [[ "$CONFIGSOURCE" == *.* ]] && CONFIGSOURCE="$(dirname "$CONFIGSOURCE")" + [[ "$CONFIGSOURCE" != *.yaml ]] && CONFIGSOURCE="${CONFIGSOURCE%/}/config.yaml" + case "$CONFIGSOURCE" in + /share/* | /config/* | /data/*) : ;; + *) bashio::log.red "CONFIG_LOCATION must be in /share, /config or /data – defaulting." && CONFIGSOURCE="$CONFIGLOCATION/config.yaml" ;; + esac fi if [[ "$CONFIGLOCATION" == "/config" && -f "/homeassistant/addons_config/${slug}/config.yaml" && ! -L "/homeassistant/addons_config/${slug}" ]]; then - echo "Migrating config.yaml to $CONFIGLOCATION" - mv "/homeassistant/addons_config/${slug}/config.yaml" "$CONFIGSOURCE" + echo "Migrating config.yaml to $CONFIGLOCATION" + mv "/homeassistant/addons_config/${slug}/config.yaml" "$CONFIGSOURCE" fi chmod -R 755 "$(dirname "$CONFIGSOURCE")" @@ -58,19 +59,19 @@ chmod -R 755 "$(dirname "$CONFIGSOURCE")" #################### if [[ ! -f "$CONFIGSOURCE" ]]; then - echo "... no config file, creating one from template." - mkdir -p "$(dirname "$CONFIGSOURCE")" - if [[ -f /templates/config.yaml ]]; then - cp /templates/config.yaml "$CONFIGSOURCE" - else - curl -fsSL "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/config.template" -o "$CONFIGSOURCE" - fi - bashio::log.green "Edit $CONFIGSOURCE then restart the add‑on." + echo "... no config file, creating one from template." + mkdir -p "$(dirname "$CONFIGSOURCE")" + if [[ -f /templates/config.yaml ]]; then + cp /templates/config.yaml "$CONFIGSOURCE" + else + curl -fsSL "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/config.template" -o "$CONFIGSOURCE" + fi + bashio::log.green "Edit $CONFIGSOURCE then restart the add‑on." fi if ! grep -qE '^[[:space:]]*[A-Za-z0-9_]+:' "$CONFIGSOURCE"; then - bashio::log.green "... no env variables found, exiting" - exit 0 + bashio::log.green "... no env variables found, exiting" + exit 0 fi ############################################ @@ -78,7 +79,7 @@ fi ############################################ # Prints flattened KEY=value lines for scalar leaves. read_yaml() { - python3 - "$1" <<'PY' + python3 - "$1" <<'PY' import sys, yaml, json, pathlib from collections.abc import Mapping, Sequence @@ -106,7 +107,7 @@ PY ############################################ # Uses printf %q – POSIX‑sh safe quoting. shell_escape() { - printf '%q' "$1" + printf '%q' "$1" } ############################################ @@ -116,7 +117,7 @@ SECRETSFILE="/config/secrets.yaml" [[ -f "$SECRETSFILE" ]] || SECRETSFILE="/homeassistant/secrets.yaml" get_secret() { - python3 - "$SECRETSFILE" "$1" <<'PY' + python3 - "$SECRETSFILE" "$1" <<'PY' import sys, yaml, pathlib sec, key = sys.argv[1:3] try: @@ -132,22 +133,23 @@ PY # MAIN LOOP # ############################################ while IFS= read -r PAIR; do - KEY="${PAIR%%=*}" ; VALUE="${PAIR#*=}" + KEY="${PAIR%%=*}" + VALUE="${PAIR#*=}" - # !secret support - if [[ "$VALUE" =~ ^!secret[[:space:]]+(.+) ]]; then - NAME="${BASH_REMATCH[1]}" - VALUE="$(get_secret "$NAME")" - [[ -z "$VALUE" ]] && bashio::exit.nok "Secret '$NAME' not found in $SECRETSFILE" - fi + # !secret support + if [[ "$VALUE" =~ ^!secret[[:space:]]+(.+) ]]; then + NAME="${BASH_REMATCH[1]}" + VALUE="$(get_secret "$NAME")" + [[ -z "$VALUE" ]] && bashio::exit.nok "Secret '$NAME' not found in $SECRETSFILE" + fi - SAFE_VALUE=$(shell_escape "$VALUE") + SAFE_VALUE=$(shell_escape "$VALUE") - # 1) Export to current shell - export "$KEY=$VALUE" + # 1) Export to current shell + export "$KEY=$VALUE" - # 2) env.py (idempotent) - python3 - "$KEY" "$VALUE" <<'PY' + # 2) env.py (idempotent) + python3 - "$KEY" "$VALUE" <<'PY' import json, os, pathlib, sys k, v = sys.argv[1:3] p = pathlib.Path('/env.py') @@ -158,27 +160,27 @@ with p.open('a') as f: os.environ[k] = v PY - # 3) .env & /etc/environment (double‑quoted, internal " escaped) - env_val="${VALUE//\"/\"}" - printf '%s="%s"\n' "$KEY" "$env_val" >> /.env - printf '%s="%s"\n' "$KEY" "$env_val" >> /etc/environment + # 3) .env & /etc/environment (double‑quoted, internal " escaped) + env_val="${VALUE//\"/\"}" + printf '%s="%s"\n' "$KEY" "$env_val" >>/.env + printf '%s="%s"\n' "$KEY" "$env_val" >>/etc/environment - # 4) s6 container_environment (raw value) - if [[ -d /var/run/s6/container_environment ]]; then - printf '%s' "$VALUE" > "/var/run/s6/container_environment/$KEY" - fi + # 4) s6 container_environment (raw value) + if [[ -d /var/run/s6/container_environment ]]; then + printf '%s' "$VALUE" >"/var/run/s6/container_environment/$KEY" + fi - # 5) Prepend export to service scripts - for script in /etc/services.d/*/*run* /etc/cont-init.d/*run*; do - [[ -f $script ]] || continue - grep -q "^export $KEY=" "$script" || sed -i "1i export $KEY=$SAFE_VALUE" "$script" - done + # 5) Prepend export to service scripts + for script in /etc/services.d/*/*run* /etc/cont-init.d/*run*; do + [[ -f $script ]] || continue + grep -q "^export $KEY=" "$script" || sed -i "1i export $KEY=$SAFE_VALUE" "$script" + done - # 6) Persist for interactive shells - grep -q "^export $KEY=" ~/.bashrc || echo "export $KEY=$SAFE_VALUE" >> ~/.bashrc + # 6) Persist for interactive shells + grep -q "^export $KEY=" ~/.bashrc || echo "export $KEY=$SAFE_VALUE" >>~/.bashrc - # 7) Log (truncate long values) - bashio::log.blue "$KEY='${VALUE:0:60}'${VALUE:60:+…}" + # 7) Log (truncate long values) + bashio::log.blue "$KEY='${VALUE:0:60}'${VALUE:60:+…}" done < <(read_yaml "$CONFIGSOURCE") bashio::log.green "Environment variables successfully loaded."