Compare commits

...
3 Commits
Author SHA1 Message Date
github-actions cb7c0b72a0 GitHub bot: changelog 2025-12-08 18:15:13 +00:00
Alexandre c828a2b0ba Update version to v3.6.1-2 2025-12-08 18:54:09 +01:00
Alexandre 61972255ee Implement dynamic shebang detection and permission handling
Added logic to determine and set the appropriate shebang for scripts based on available interpreters. Enhanced permission handling for scripts based on user privileges.
2025-12-08 18:53:45 +01:00
3 changed files with 61 additions and 8 deletions

No files matched your search

+2
View File
@@ -1,3 +1,5 @@
## v3.6.1-2 (08-12-2025)
- Minor bugs fixed
## v3.6.1 (06-12-2025)
- Update to latest version from mealie-recipes/mealie (changelog : https://github.com/mealie-recipes/mealie/releases)
+1 -1
View File
@@ -114,4 +114,4 @@ schema:
slug: mealie
udev: true
url: https://github.com/alexbelgium/hassio-addons
version: "v3.6.1"
version: v3.6.1-2
+58 -7
View File
@@ -10,16 +10,67 @@ touch /started
# Starting scripts #
####################
candidate_shebangs+=(
"/usr/bin/env bashio"
"/usr/bin/bashio"
"/usr/bin/bash"
"/usr/bin/sh"
"/bin/bash"
"/bin/sh"
)
# Find the first valid shebang interpreter in candidate list
shebang=""
for candidate in "${candidate_shebangs[@]}"; do
command_path="${candidate%% *}"
# Test if command exists and can actually execute a shell command (for shells)
if [ -x "$command_path" ]; then
# Try as both 'sh -c' and 'bashio echo' style
if "$command_path" -c 'echo yes' > /dev/null 2>&1 || "$command_path" echo "yes" > /dev/null 2>&1; then
shebang="$candidate"
break
fi
fi
done
if [ -z "$shebang" ]; then
echo "ERROR: No valid shebang found!"
exit 1
fi
for SCRIPTS in /etc/cont-init.d/*; do
[ -e "$SCRIPTS" ] || continue
echo "$SCRIPTS: executing"
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"
sed -i "/exit 0/d" "$SCRIPTS"
. "$SCRIPTS" || echo -e "\033[0;31mError\033[0m : $SCRIPTS exiting $?"
rm "$SCRIPTS"
# Check if run as root (UID 0)
if [ "$(id -u)" -eq 0 ]; then
# Fix permissions for root user
chown "$(id -u)":"$(id -g)" "$SCRIPTS"
chmod a+x "$SCRIPTS"
else
echo -e "\e[38;5;214m$(date) WARNING: Script executed with user $(id -u):$(id -g), things can break and chown won't work\e[0m"
# Disable chown and chmod commands inside the script for non-root users
sed -i "s/^\s*chown /true # chown /g" "$SCRIPTS"
sed -i "s/^\s*chmod /true # chmod /g" "$SCRIPTS"
fi
# Prepare to run
sed -i "1s|^.*|#!$shebang|" "$SCRIPTS"
chmod +x "$SCRIPTS"
# Optionally use 'source' to share env variables, when requested
if [ "${ha_entry_source:-null}" = true ]; then
# Replace exit with return, so sourced scripts can return errors
sed -i -E 's/^\s*exit ([0-9]+)/return \1 \|\| exit \1/g' "$SCRIPTS"
sed -i 's/bashio::exit\.nok/return 1/g' "$SCRIPTS"
sed -i 's/bashio::exit\.ok/return 0/g' "$SCRIPTS"
# shellcheck disable=SC1090
source "$SCRIPTS" || echo -e "\033[0;31mError\033[0m : $SCRIPTS exiting $?"
else
"$SCRIPTS" || echo -e "\033[0;31mError\033[0m : $SCRIPTS exiting $?"
fi
# Cleanup after execution
sed -i '1a exit 0' "$SCRIPTS"
done
rm /.env || true