mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-06-07 08:05:57 +02:00
Update 01-custom_script.sh
This commit is contained in:
@@ -2,39 +2,46 @@
|
|||||||
# shellcheck shell=bash
|
# shellcheck shell=bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Define slug if needed
|
##################
|
||||||
slug="${HOSTNAME#*-}"
|
# INITIALIZATION #
|
||||||
|
##################
|
||||||
|
|
||||||
|
# Exit if /config is not mounted
|
||||||
|
if [ ! -d /config ]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Define slug
|
||||||
|
slug="${HOSTNAME}"
|
||||||
|
|
||||||
# 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
|
||||||
# Migrate previous script
|
|
||||||
if [ -f /homeassistant/addons_autoscripts/"${slug}".sh ]; then
|
|
||||||
echo "Migrating scripts to new config location"
|
|
||||||
mv -f /homeassistant/addons_autoscripts/"${slug}".sh /config/"${slug}".sh
|
|
||||||
fi
|
|
||||||
# New config location
|
# New config location
|
||||||
CONFIGLOCATION="/config"
|
CONFIGLOCATION="/config"
|
||||||
CONFIGFILEBROWSER="/config/*-$slug"
|
CONFIGFILEBROWSER="/addon_configs/$slug/${HOSTNAME#*-}.sh"
|
||||||
else
|
else
|
||||||
# Legacy config location
|
# Legacy config location
|
||||||
|
slug="${HOSTNAME#*-}"
|
||||||
CONFIGLOCATION="/config/addons_autoscripts"
|
CONFIGLOCATION="/config/addons_autoscripts"
|
||||||
CONFIGFILEBROWSER="/config/addons_autoscripts"
|
CONFIGFILEBROWSER="/homeassistant/addons_config/${slug}/${slug}.sh"
|
||||||
mkdir -p /config/addons_autoscripts
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
bashio::log.green "Execute $CONFIGFILEBROWSER/${slug}.sh if existing"
|
# Default location
|
||||||
|
CONFIGSOURCE="$CONFIGLOCATION/${HOSTNAME#*-}.sh"
|
||||||
|
|
||||||
|
bashio::log.green "Execute $CONFIGFILEBROWSER if existing"
|
||||||
bashio::log.green "Wiki here : github.com/alexbelgium/hassio-addons/wiki/Add-ons-feature-:-customisation"
|
bashio::log.green "Wiki here : github.com/alexbelgium/hassio-addons/wiki/Add-ons-feature-:-customisation"
|
||||||
|
|
||||||
# Download template if no script found and exit
|
# Download template if no script found and exit
|
||||||
if [ ! -f "$CONFIGLOCATION/${slug}".sh ]; 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 "$CONFIGLOCATION/${slug}".sh || 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 "$CONFIGLOCATION/${slug}".sh &>/dev/null || true
|
dos2unix "$CONFIGSOURCE" &>/dev/null || true
|
||||||
chmod +x "$CONFIGLOCATION/${slug}".sh
|
chmod +x "$CONFIGSOURCE"
|
||||||
|
|
||||||
# Check if there is actual commands
|
# Check if there is actual commands
|
||||||
while IFS= read -r line
|
while IFS= read -r line
|
||||||
@@ -45,7 +52,7 @@ do
|
|||||||
# Check if line is not empty and does not start with #
|
# 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"
|
||||||
/."$CONFIGLOCATION/${slug}".sh
|
/."$CONFIGSOURCE"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
done < "$CONFIGLOCATION/${slug}".sh
|
done < "$CONFIGSOURCE"
|
||||||
|
|||||||
Reference in New Issue
Block a user