mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-05-26 02:31:51 +02:00
Improve shebang detection
This commit is contained in:
@@ -9,11 +9,22 @@ echo "Starting..."
|
|||||||
for SCRIPTS in /etc/cont-init.d/*; do
|
for SCRIPTS in /etc/cont-init.d/*; do
|
||||||
[ -e "$SCRIPTS" ] || continue
|
[ -e "$SCRIPTS" ] || continue
|
||||||
echo "$SCRIPTS: executing"
|
echo "$SCRIPTS: executing"
|
||||||
|
|
||||||
|
# Ensure permissions
|
||||||
chown "$(id -u)":"$(id -g)" "$SCRIPTS"
|
chown "$(id -u)":"$(id -g)" "$SCRIPTS"
|
||||||
chmod a+x "$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"
|
# Get current shebang, if not available use another
|
||||||
/usr/bin/env bashio "$SCRIPTS" || echo -e "\033[0;31mError\033[0m : $SCRIPTS exiting $?"
|
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"
|
rm "$SCRIPTS"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user