mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-09-25 02:53:58 +02:00
Compare commits
1 Commits
38eac4c510
...
claude/rev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f00c8b9210 |
@@ -82,11 +82,10 @@ dotenv_quote() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
shell_quote() {
|
shell_quote() {
|
||||||
# Single-quote for safe injection in shell code
|
# Single-quote for safe injection in shell code.
|
||||||
local s="$1"
|
# Inside single quotes only the single quote needs escaping ('->'\'').
|
||||||
s="${s//\\/\\\\}"
|
# Do NOT escape backslashes: they are literal inside single quotes.
|
||||||
s="${s//\'/\'\"\'\"\' }"
|
local s="${1//\'/\'\\\'\'}"
|
||||||
s="${s% }"
|
|
||||||
printf "'%s'" "$s"
|
printf "'%s'" "$s"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,9 +165,9 @@ export_var() {
|
|||||||
# Runtime environment (no eval, safe for special chars)
|
# Runtime environment (no eval, safe for special chars)
|
||||||
export "$k=$v"
|
export "$k=$v"
|
||||||
|
|
||||||
# S6 environment (preferred for services)
|
# S6 environment (preferred for services); best-effort, tolerate RO mounts
|
||||||
if [[ -d /var/run/s6/container_environment ]]; then
|
if [[ -d /var/run/s6/container_environment ]]; then
|
||||||
printf '%s' "$v" > "/var/run/s6/container_environment/$k"
|
printf '%s' "$v" > "/var/run/s6/container_environment/$k" || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Queue for .env and /etc/environment (written once, idempotent)
|
# Queue for .env and /etc/environment (written once, idempotent)
|
||||||
@@ -219,18 +218,31 @@ done < <(
|
|||||||
)
|
)
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Write .env and /etc/environment (idempotent: replace whole file content)
|
# Write .env and /etc/environment (idempotent: replace only our block,
|
||||||
|
# preserving any pre-existing content from the upstream image / system).
|
||||||
# Notes:
|
# Notes:
|
||||||
# - /.env is commonly used by apps expecting dotenv format
|
# - /.env is commonly used by apps expecting dotenv format
|
||||||
# - /etc/environment is read by PAM/system tooling; KEY="value" is acceptable
|
# - /etc/environment is read by PAM/system tooling; KEY="value" is acceptable
|
||||||
################################################################################
|
################################################################################
|
||||||
{
|
update_env_file() {
|
||||||
echo "$BLOCK_BEGIN"
|
local f="$1" tmp
|
||||||
cat "$KV_FILE"
|
tmp="$(mktemp_safe)"
|
||||||
echo "$BLOCK_END"
|
if [[ -f "$f" ]]; then
|
||||||
} > "$ENV_FILE.tmp"
|
awk -v b="$BLOCK_BEGIN" -v e="$BLOCK_END" '
|
||||||
mv "$ENV_FILE.tmp" "$ENV_FILE"
|
$0==b { skip=1; next }
|
||||||
cp "$ENV_FILE" "$ETC_ENV_FILE"
|
$0==e { skip=0; next }
|
||||||
|
!skip
|
||||||
|
' "$f" > "$tmp"
|
||||||
|
fi
|
||||||
|
{
|
||||||
|
echo "$BLOCK_BEGIN"
|
||||||
|
cat "$KV_FILE"
|
||||||
|
echo "$BLOCK_END"
|
||||||
|
} >> "$tmp"
|
||||||
|
mv "$tmp" "$f"
|
||||||
|
}
|
||||||
|
update_env_file "$ENV_FILE"
|
||||||
|
update_env_file "$ETC_ENV_FILE"
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Inject into scripts and shells (best-effort)
|
# Inject into scripts and shells (best-effort)
|
||||||
|
|||||||
Reference in New Issue
Block a user