From d4ce4160a8405aab52f222223feea6a6927ff5b5 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Mon, 15 Sep 2025 15:49:01 +0200 Subject: [PATCH] feat: unify s6 modifications --- .templates/ha_entrypoint.sh | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/.templates/ha_entrypoint.sh b/.templates/ha_entrypoint.sh index 76d31963d..922a1e94c 100755 --- a/.templates/ha_entrypoint.sh +++ b/.templates/ha_entrypoint.sh @@ -48,6 +48,18 @@ if [ -z "$shebang" ]; then exit 1 fi +#################### +# Helper functions # +#################### + +apply_s6_mods() { + local file="$1" + sed -i "1s|^.*|#!$shebang|" "$file" + sed -i -E 's|^s6-setuidgid[[:space:]]+([a-zA-Z0-9._-]+)[[:space:]]+(.*)$|su -s /bin/bash \\1 -c "\\2"|g' "$file" + sed -i -E 's|s6-svwait[[:space:]]+-d[[:space:]]+([^[:space:]]+)|bash -c '\''while [ -f \\1/supervise/pid ]; do sleep 0.5; done'\''|g' "$file" + chmod +x "$file" || true +} + #################### # Starting scripts # #################### @@ -69,8 +81,8 @@ for SCRIPTS in /etc/cont-init.d/*; do sed -i "s/^\s*chmod /true # chmod /g" "$SCRIPTS" fi - # Replace the shebang in the script with the valid one - sed -i "1s|^.*|#!$shebang|" "$SCRIPTS" + # Apply s6 compatibility tweaks + apply_s6_mods "$SCRIPTS" # Optionally use 'source' to share env variables, when requested if [ "${ha_entry_source:-null}" = true ]; then @@ -94,13 +106,7 @@ if $PID1; then for runfile in /etc/services.d/*/run /etc/s6-overlay/s6-rc.d/*/run /etc/cont-init.d/*; do [ -f "$runfile" ] || continue echo "Starting: $runfile" - # Replace the shebang line in each runfile - sed -i "1s|^.*|#!$shebang|" "$runfile" - # Replace s6-setuidgid calls with 'su' (bash-based) equivalents - sed -i -E 's|^s6-setuidgid[[:space:]]+([a-zA-Z0-9._-]+)[[:space:]]+(.*)$|su -s /bin/bash \1 -c "\2"|g' "$runfile" - # Replace s6-svwait calls with bash-based waiting loops - sed -i -E 's|s6-svwait[[:space:]]+-d[[:space:]]+([^[:space:]]+)|bash -c '\''while [ -f \1/supervise/pid ]; do sleep 0.5; done'\''|g' "$runfile" - chmod +x "$runfile" + apply_s6_mods "$runfile" (exec "$runfile") & true done