Improve shebang detection

This commit is contained in:
Alexandre
2023-09-09 12:29:08 +02:00
committed by GitHub
parent 2411e87548
commit 82fdb76c36

View File

@@ -9,11 +9,22 @@ echo "Starting..."
for SCRIPTS in /etc/cont-init.d/*; do
[ -e "$SCRIPTS" ] || continue
echo "$SCRIPTS: executing"
# Ensure permissions
chown "$(id -u)":"$(id -g)" "$SCRIPTS"
chmod a+x "$SCRIPTS"
# Change shebang if no s6 supervision
sed -i 's|/usr/bin/with-contenv bashio|/usr/bin/env bashio|g' "$SCRIPTS"
/usr/bin/env bashio "$SCRIPTS" || echo -e "\033[0;31mError\033[0m : $SCRIPTS exiting $?"
# Get current shebang, if not available use another
currentshebang="$(sed -n '1{s/^#![[:blank:]]*//p;q}' "$SCRIPTS")"
if [ ! -f "${currentshebang%% *}" ]; then
for shebang in "/command/with-contenv bashio" "/usr/bin/env bashio" "/usr/bin/bashio" "/bin/bash" "/bin/sh"; do if [ -f "${shebang%% *}" ]; then break; fi; done
sed -i "s|$currentshebang|$shebang|g" "$SCRIPTS"
fi
# Start the script
/./ "$SCRIPTS" || echo -e "\033[0;31mError\033[0m : $SCRIPTS exiting $?"
# Cleanup
rm "$SCRIPTS"
done