From 6a2a67245c2faa226b5a698041c8c8e7923cb75a Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Wed, 10 Jan 2024 10:27:33 +0100 Subject: [PATCH] Disable chown if not root --- .templates/ha_entrypoint.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.templates/ha_entrypoint.sh b/.templates/ha_entrypoint.sh index 60d7ee1a0..66eb312e2 100755 --- a/.templates/ha_entrypoint.sh +++ b/.templates/ha_entrypoint.sh @@ -11,9 +11,15 @@ 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" + # Check if run as root + if test "$(id -u)" == 0 && test "$(id -u)" == 0; then + chown "$(id -u)":"$(id -g)" "$SCRIPTS" + chmod a+x "$SCRIPTS" + else + bashio::log.warning "Script executed with user $(id -u):$(id -g), things can break and chown won't work" + # Disable chown in scripts + sed -i "s/chown /true # chown /g" "$SCRIPTS" + fi # Get current shebang, if not available use another currentshebang="$(sed -n '1{s/^#![[:blank:]]*//p;q}' "$SCRIPTS")"