Update 01-custom_script.sh

This commit is contained in:
Alexandre
2026-03-07 21:28:55 +01:00
committed by GitHub
parent 8ea0ad30ea
commit b87beb9a08

View File

@@ -58,13 +58,13 @@ if ! command -v bashio::addon.version >/dev/null 2>&1; then
/usr/local/lib/bashio/bashio.sh /usr/local/lib/bashio/bashio.sh
do do
if [ -f "$f" ]; then if [ -f "$f" ]; then
# shellcheck disable=SC1090
. "$f" . "$f"
break break
fi fi
done done
fi fi
# Try regular bashio, fallback to standalone if unavailable or fails
set +e set +e
_bv="$(bashio::addon.version 2>/dev/null)" _bv="$(bashio::addon.version 2>/dev/null)"
_rc=$? _rc=$?
@@ -73,6 +73,7 @@ set -e
if [ "$_rc" -ne 0 ] || [ -z "$_bv" ] || [ "$_bv" = "null" ]; then if [ "$_rc" -ne 0 ] || [ -z "$_bv" ] || [ "$_bv" = "null" ]; then
for _sf in /usr/local/lib/bashio-standalone.sh /.bashio-standalone.sh; do for _sf in /usr/local/lib/bashio-standalone.sh /.bashio-standalone.sh; do
if [ -f "$_sf" ]; then if [ -f "$_sf" ]; then
# shellcheck disable=SC1090
. "$_sf" . "$_sf"
_bv="$(bashio::addon.version 2>/dev/null || true)" _bv="$(bashio::addon.version 2>/dev/null || true)"
break break
@@ -146,8 +147,6 @@ if [ -z "$shebang" ]; then
exit 1 exit 1
fi fi
sed -i "1s|^.*|#!$shebang|" "$0"
if ! command -v bashio::addon.version >/dev/null 2>&1; then if ! command -v bashio::addon.version >/dev/null 2>&1; then
for f in /usr/lib/bashio/bashio.sh /usr/lib/bashio/lib.sh /usr/src/bashio/bashio.sh /usr/local/lib/bashio/bashio.sh /usr/local/lib/bashio-standalone.sh; do for f in /usr/lib/bashio/bashio.sh /usr/lib/bashio/lib.sh /usr/src/bashio/bashio.sh /usr/local/lib/bashio/bashio.sh /usr/local/lib/bashio-standalone.sh; do
if [ -f "$f" ]; then if [ -f "$f" ]; then
@@ -174,11 +173,9 @@ slug="${slug#*_}"
# Check type of config folder # Check type of config folder
if [ ! -f /config/configuration.yaml ] && [ ! -f /config/configuration.json ]; then if [ ! -f /config/configuration.yaml ] && [ ! -f /config/configuration.json ]; then
# New config location
CONFIGLOCATION="/config" CONFIGLOCATION="/config"
CONFIGFILEBROWSER="/addon_configs/${HOSTNAME/-/_}/$slug.sh" CONFIGFILEBROWSER="/addon_configs/${HOSTNAME/-/_}/$slug.sh"
else else
# Legacy config location
CONFIGLOCATION="/config/addons_autoscripts" CONFIGLOCATION="/config/addons_autoscripts"
CONFIGFILEBROWSER="/homeassistant/addons_autoscripts/$slug.sh" CONFIGFILEBROWSER="/homeassistant/addons_autoscripts/$slug.sh"
fi fi
@@ -198,20 +195,22 @@ if [ ! -f "$CONFIGSOURCE" ]; then
fi fi
# Convert scripts to linux # Convert scripts to linux
dos2unix "$CONFIGSOURCE" &> /dev/null || true dos2unix "$CONFIGSOURCE" >/dev/null 2>&1 || true
chmod +x "$CONFIGSOURCE" chmod +x "$CONFIGSOURCE"
if grep -q 'bashio' "$CONFIGSOURCE"; then
sed -i "1s|^.*|#!$shebang|" "$CONFIGSOURCE" sed -i "1s|^.*|#!$shebang|" "$CONFIGSOURCE"
else
sed -i '1s|^.*|#!/bin/bash|' "$CONFIGSOURCE"
fi
# Check if there is actual commands # Check if there is actual commands
while IFS= read -r line; do while IFS= read -r line; do
# Remove leading and trailing whitespaces
line="$(echo "$line" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" line="$(echo "$line" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
# Check if line is not empty and does not start with #
if [[ -n "$line" ]] && [[ ! "$line" =~ ^# ]]; then if [[ -n "$line" ]] && [[ ! "$line" =~ ^# ]]; then
bashio::log.green "... script found, executing" bashio::log.green "... script found, executing"
/."$CONFIGSOURCE" "$CONFIGSOURCE"
break break
fi fi
done < "$CONFIGSOURCE" done < "$CONFIGSOURCE"