From 32b9bdaa51a7851539b24b3cb31becd4b09d156f Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Thu, 24 Jul 2025 14:55:21 +0200 Subject: [PATCH] Update ha_entrypoint.sh --- .templates/ha_entrypoint.sh | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/.templates/ha_entrypoint.sh b/.templates/ha_entrypoint.sh index e6e26a7dd..ccc3cd712 100644 --- a/.templates/ha_entrypoint.sh +++ b/.templates/ha_entrypoint.sh @@ -28,30 +28,16 @@ run_script() { fi # Get current shebang, if not available use another - currentshebang="$(sed -n '1{s/^#![[:space:]]*//p;q}' "$runfile")" - interp="${currentshebang%% *}" - - if [ -z "$currentshebang" ] || [ ! -x "$interp" ]; then - for candidate in \ - "/command/with-contenv bashio" \ - "/usr/bin/with-contenv bashio" \ - "/usr/bin/env bashio" \ - "/usr/bin/bashio" \ - "/usr/bin/bash" "/usr/bin/sh" "/bin/bash" "/bin/sh" - do - cmd="${candidate%% *}" - if [ -x "$cmd" ]; then - new_shebang="$candidate" - echo "Valid shebang: $new_shebang" - # Replace only the first line - if [ -n "$currentshebang" ]; then - sed -i "1s|.*|#!${new_shebang}|" "$runfile" - else - sed -i "1i#!"${new_shebang} "$runfile" - fi + currentshebang="$(sed -n '1{s/^#![[:blank:]]*//p;q}' "$SCRIPTS")" + if [ ! -f "${currentshebang%% *}" ]; then + for shebang in "/command/with-contenv bashio" "/usr/bin/with-contenv bashio" "/usr/bin/env bashio" "/usr/bin/bashio" "/usr/bin/bash" "/usr/bin/sh" "/bin/bash" "/bin/sh"; do + command_path="${shebang%% *}" + if [ -x "$command_path" ] && "$command_path" echo "yes" > /dev/null 2>&1; then + echo "Valid shebang: $shebang" break fi done + sed -i "s|$currentshebang|$shebang|g" "$SCRIPTS" fi # Use source to share env variables when requested