mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-06-10 01:25:58 +02:00
Update config.yaml handling
This commit is contained in:
@@ -72,8 +72,8 @@ if [[ "$CONFIGSOURCE" != *".yaml" ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Permissions
|
# Permissions only if the config file already exists
|
||||||
if [[ "$CONFIGSOURCE" == *".yaml" ]]; then
|
if [[ "$CONFIGSOURCE" == *".yaml" ]] && [ -f "$CONFIGSOURCE" ]; then
|
||||||
echo "Setting permissions for the config.yaml directory"
|
echo "Setting permissions for the config.yaml directory"
|
||||||
mkdir -p "$(dirname "${CONFIGSOURCE}")"
|
mkdir -p "$(dirname "${CONFIGSOURCE}")"
|
||||||
chmod -R 755 "$(dirname "${CONFIGSOURCE}")" 2> /dev/null
|
chmod -R 755 "$(dirname "${CONFIGSOURCE}")" 2> /dev/null
|
||||||
@@ -83,6 +83,24 @@ fi
|
|||||||
# LOAD CONFIG.YAML #
|
# LOAD CONFIG.YAML #
|
||||||
####################
|
####################
|
||||||
|
|
||||||
|
# Exit if the config file is absent
|
||||||
|
if [ ! -f "$CONFIGSOURCE" ]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if there are lines to read
|
||||||
|
cp "$CONFIGSOURCE" /tempenv
|
||||||
|
sed -i '/^#/d' /tempenv
|
||||||
|
sed -i '/^[[:space:]]*$/d' /tempenv
|
||||||
|
sed -i '/^$/d' /tempenv
|
||||||
|
echo "" >> /tempenv
|
||||||
|
|
||||||
|
# Exit if empty
|
||||||
|
if [ ! -s /tempenv ]; then
|
||||||
|
rm /tempenv
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
bashio::log.green "Load environment variables from $CONFIGSOURCE if existing"
|
bashio::log.green "Load environment variables from $CONFIGSOURCE if existing"
|
||||||
if [[ "$CONFIGSOURCE" == "/config"* ]]; then
|
if [[ "$CONFIGSOURCE" == "/config"* ]]; then
|
||||||
@@ -95,35 +113,6 @@ bashio::log.notice "This script is used to export custom environment variables a
|
|||||||
bashio::log.warning "This methodology is deprecated, please convert your Environment variables to the addon options env_vars. Instructions can be found here : https://github.com/alexbelgium/hassio-addons/wiki/Add-Environment-variables-to-your-Addon-2"
|
bashio::log.warning "This methodology is deprecated, please convert your Environment variables to the addon options env_vars. Instructions can be found here : https://github.com/alexbelgium/hassio-addons/wiki/Add-Environment-variables-to-your-Addon-2"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# Check if config file is there, or create one from template
|
|
||||||
if [ ! -f "$CONFIGSOURCE" ]; then
|
|
||||||
echo "... no config file, creating one from template. Please customize the file in $CONFIGSOURCE before restarting."
|
|
||||||
# Create folder
|
|
||||||
mkdir -p "$(dirname "${CONFIGSOURCE}")"
|
|
||||||
# Placing template in config
|
|
||||||
if [ -f /templates/config.yaml ]; then
|
|
||||||
# Use available template
|
|
||||||
cp /templates/config.yaml "$(dirname "${CONFIGSOURCE}")"
|
|
||||||
else
|
|
||||||
# Download template
|
|
||||||
TEMPLATESOURCE="https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/config.template"
|
|
||||||
curl -f -L -s -S "$TEMPLATESOURCE" --output "$CONFIGSOURCE"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if there are lines to read
|
|
||||||
cp "$CONFIGSOURCE" /tempenv
|
|
||||||
sed -i '/^#/d' /tempenv
|
|
||||||
sed -i '/^[[:space:]]*$/d' /tempenv
|
|
||||||
sed -i '/^$/d' /tempenv
|
|
||||||
echo "" >> /tempenv
|
|
||||||
|
|
||||||
# Exit if empty
|
|
||||||
if [ ! -s /tempenv ]; then
|
|
||||||
bashio::log.green "... no env variables found, exiting"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if yaml is valid
|
# Check if yaml is valid
|
||||||
EXIT_CODE=0
|
EXIT_CODE=0
|
||||||
yamllint -d relaxed /tempenv &> ERROR || EXIT_CODE=$?
|
yamllint -d relaxed /tempenv &> ERROR || EXIT_CODE=$?
|
||||||
|
|||||||
Reference in New Issue
Block a user