Skip to content

Commit

Permalink
Update code
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbelgium committed Nov 19, 2023
1 parent d7a1f26 commit 3100d33
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 7 additions & 4 deletions .templates/01-config_yaml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ if [ ! -d /config ]; then
exit 0
fi

# Define slug if
slug="${HOSTNAME#*-}"

# Check type of config folder
if [ ! -f /config/configuration.yaml ] && [ ! -f /config/configuration.json ]; then
# New config location
Expand All @@ -38,20 +41,20 @@ if bashio::config.has_value 'CONFIG_LOCATION'; then
fi
done
if [ -z "$LOCATIONOK" ]; then
CONFIGSOURCE="$CONFIGLOCATION/${HOSTNAME#*-}"
CONFIGSOURCE="$CONFIGLOCATION/${slug}"
bashio::log.red "Watch-out : your CONFIG_LOCATION values can only be set in /share, /config or /data (internal to addon). It will be reset to the default location : $CONFIGSOURCE"
fi

else
# Use default
CONFIGSOURCE="$CONFIGLOCATION/${HOSTNAME#*-}/config.yaml"
CONFIGSOURCE="$CONFIGLOCATION/${slug}/config.yaml"
fi

# Migrate if needed
if [ "$CONFIGLOCATION" == "/config" ]; then
if [ -f "/config/addons_config/${HOSTNAME#*-}/config.yaml" ]; then
if [ -f "/homeassistant/addons_config/${slug}/config.yaml" ]; then
echo "Migrating config.yaml to new config location"
mv /config/addons_config/${HOSTNAME#*-}/config.yaml /config/config.yaml
mv /homeassistant/addons_config/"${slug}"/config.yaml /config/config.yaml
fi
fi

Expand Down
6 changes: 4 additions & 2 deletions .templates/01-custom_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
# shellcheck shell=bash
set -e

# Define slug if needed
slug="${HOSTNAME#*-}"

# Check type of config folder
if [ ! -f /config/configuration.yaml ] && [ ! -f /config/configuration.json ]; then
# Migrate previous script
if [ -f /config/addons_autoscripts/"${slug}".sh ]; then
mv -f /config/addons_autoscripts/"${slug}".sh /config/"${slug}".sh
if [ -f /config/addons_autoscripts/"${slug}".sh ] && [ -d /homeassistant/addons_autoscripts ]; then
echo "Migrating scripts to new config location"
mv -f /homeassistant/addons_autoscripts/"${slug}".sh /config/"${slug}".sh
fi
# New config location
CONFIGLOCATION="/config"
Expand Down

0 comments on commit 3100d33

Please sign in to comment.