This commit is contained in:
Alexandre
2025-07-30 06:25:30 +02:00
committed by GitHub
parent 9416c80b14
commit dddf9adfa6

View File

@@ -7,10 +7,17 @@ echo "Starting..."
# Starting scripts # # Starting scripts #
#################### ####################
# Detect if this is PID1 (main container process) — do this once at the start
PID1=false
if [ "$$" -eq 1 ]; then
PID1=true
fi
run_script() { run_script() {
runfile="$1" runfile="$1"
script_kind="$2" script_kind="$2"
echo "$runfile: executing" echo "$runfile: executing"
# Check if run as root # Check if run as root
if [ "$(id -u)" -eq 0 ]; then if [ "$(id -u)" -eq 0 ]; then
chown "$(id -u)":"$(id -g)" "$runfile" chown "$(id -u)":"$(id -g)" "$runfile"
@@ -27,7 +34,10 @@ run_script() {
sed -i -E 's|s6-setuidgid[[:space:]]+([a-zA-Z0-9._-]+)[[:space:]]+(.*)$|su -s /bin/bash \1 -c "\2"|g' "$runfile" sed -i -E 's|s6-setuidgid[[:space:]]+([a-zA-Z0-9._-]+)[[:space:]]+(.*)$|su -s /bin/bash \1 -c "\2"|g' "$runfile"
fi fi
# Prepare candidate shebangs: contenv first if PID1 # Shebang check/replacement (only if missing or invalid)
currentshebang="$(sed -n '1{s/^#![[:blank:]]*//p;q}' "$runfile")"
command_path="${currentshebang%% *}"
if [ ! -x "$command_path" ]; then
candidate_shebangs=() candidate_shebangs=()
if $PID1; then if $PID1; then
candidate_shebangs+=("/command/with-contenv bashio" "/usr/bin/with-contenv bashio") candidate_shebangs+=("/command/with-contenv bashio" "/usr/bin/with-contenv bashio")
@@ -52,11 +62,12 @@ run_script() {
rm -f "$tmpfile" rm -f "$tmpfile"
if [[ -n "$output" ]]; then if [[ -n "$output" ]]; then
echo "Valid shebang: $shebang (output: $output)" echo "Valid shebang: $shebang (output: $output)"
sed -i "1s|^#![^\n]*|#!$shebang|" "$SCRIPTS" sed -i "1s|^#![^\n]*|#!$shebang|" "$runfile"
break break
fi fi
fi fi
done done
fi
# Use source to share env variables when requested # Use source to share env variables when requested
if [[ "$script_kind" == service ]]; then if [[ "$script_kind" == service ]]; then
@@ -93,7 +104,7 @@ for SCRIPTS in /etc/s6-overlay/s6-rc.d/*/run; do
done || true done || true
# Start services.d # Start services.d
if [ "$$" -eq 1 ]; then if $PID1; then
for service_dir in /etc/services.d/*; do for service_dir in /etc/services.d/*; do
SCRIPTS="${service_dir}/run" SCRIPTS="${service_dir}/run"
[ -e "$SCRIPTS" ] || continue [ -e "$SCRIPTS" ] || continue
@@ -108,7 +119,7 @@ fi
###################### ######################
# If PID 1, keep alive and manage sigterm # If PID 1, keep alive and manage sigterm
if [ "$$" -eq 1 ]; then if $PID1; then
echo " " echo " "
echo -e "\033[0;32mEverything started!\033[0m" echo -e "\033[0;32mEverything started!\033[0m"
terminate() { terminate() {