mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-01-11 18:31:02 +01:00
Improve shebang detection
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user