Update ha_entrypoint.sh

This commit is contained in:
Alexandre
2025-08-01 16:29:40 +02:00
committed by GitHub
parent fea26a344c
commit 2d96d65ab9

View File

@@ -3,14 +3,12 @@
set -e # Exit immediately if a command exits with a non-zero status set -e # Exit immediately if a command exits with a non-zero status
echo "Starting..."
# Detect if this is PID1 (main container process) — do this once at the start # Detect if this is PID1 (main container process) — do this once at the start
PID1=false PID1=false
if [ "$$" -eq 1 ]; then if [ "$$" -eq 1 ]; then
PID1=true PID1=true
echo "Starting as entrypoint"
else
echo "Starting custom scripts"
fi fi
###################### ######################
@@ -25,34 +23,27 @@ fi
candidate_shebangs+=( candidate_shebangs+=(
"/usr/bin/env bashio" "/usr/bin/env bashio"
"/usr/bin/bashio" "/usr/bin/bashio"
"/usr/bin/bash"
"/usr/bin/sh"
"/bin/bash"
"/bin/sh"
) )
# Find the first valid shebang interpreter in candidate list by probing bashio::addon.version # Find the first valid shebang interpreter in candidate list
shebang="" shebang=""
tmp="$(mktemp)"
trap 'rm -f "$tmp"' EXIT
for candidate in "${candidate_shebangs[@]}"; do for candidate in "${candidate_shebangs[@]}"; do
echo "Trying $candidate" command_path="${candidate%% *}"
# Build a tiny probe script that prints the addon version # Test if command exists and can actually execute a shell command (for shells)
printf '#!%s\n' "$candidate" >"$tmp" if [ -x "$command_path" ]; then
cat >>"$tmp" <<'EOF' # Try as both 'sh -c' and 'bashio echo' style
out="$(bashio::addon.version 2>/dev/null || true)" if "$command_path" -c 'echo yes' >/dev/null 2>&1 || "$command_path" echo "yes" >/dev/null 2>&1; then
[ -n "$out" ] && printf '%s\n' "$out" shebang="$candidate"
EOF break
chmod +x "$tmp" fi
# Run the probe and check for at least one digit in the output
out="$("$tmp" 2>/dev/null || true)"
echo "Output is $out"
if printf '%s' "$out" | grep -qE '[0-9]'; then
shebang="$candidate"
break
fi fi
done done
if [ -z "$shebang" ]; then if [ -z "$shebang" ]; then
echo "ERROR: No valid shebang found!" >&2 echo "ERROR: No valid shebang found!"
exit 1 exit 1
fi fi