mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-07-06 22:18:48 +02:00
Update 01-custom_script.sh
This commit is contained in:
@@ -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
|
||||||
@@ -163,9 +162,9 @@ fi
|
|||||||
##################
|
##################
|
||||||
|
|
||||||
# Exit if /config is not mounted or HA not used
|
# Exit if /config is not mounted or HA not used
|
||||||
if [ ! -d /config ] || ! bashio::supervisor.ping 2> /dev/null; then
|
if [ ! -d /config ] || ! bashio::supervisor.ping 2>/dev/null; then
|
||||||
echo "..."
|
echo "..."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Define slug
|
# Define slug
|
||||||
@@ -174,13 +173,11 @@ 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
|
||||||
|
|
||||||
# Default location
|
# Default location
|
||||||
@@ -192,26 +189,28 @@ bashio::log.green "Execute $CONFIGFILEBROWSER if existing"
|
|||||||
|
|
||||||
# Download template if no script found and exit
|
# Download template if no script found and exit
|
||||||
if [ ! -f "$CONFIGSOURCE" ]; then
|
if [ ! -f "$CONFIGSOURCE" ]; then
|
||||||
TEMPLATESOURCE="https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/script.template"
|
TEMPLATESOURCE="https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/script.template"
|
||||||
curl -f -L -s -S "$TEMPLATESOURCE" --output "$CONFIGSOURCE" || true
|
curl -f -L -s -S "$TEMPLATESOURCE" --output "$CONFIGSOURCE" || true
|
||||||
exit 0
|
exit 0
|
||||||
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"
|
||||||
|
|
||||||
sed -i "1s|^.*|#!$shebang|" "$CONFIGSOURCE"
|
if grep -q 'bashio' "$CONFIGSOURCE"; then
|
||||||
|
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"
|
||||||
|
|||||||
Reference in New Issue
Block a user