mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-05-19 23:31:50 +02:00
Update 99-run.sh
This commit is contained in:
@@ -1,37 +1,51 @@
|
|||||||
#!/usr/bin/env bashio
|
#!/usr/bin/env bashio
|
||||||
|
|
||||||
|
##################
|
||||||
|
# INITIALIZATION #
|
||||||
|
##################
|
||||||
|
|
||||||
# Where is the config
|
# Where is the config
|
||||||
CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION")
|
CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION")
|
||||||
|
DATABASESOURCE=$(dirname "${CONFIGSOURCE}")/database.sqlite
|
||||||
|
|
||||||
|
# Remoce config in data if existing
|
||||||
|
[ -f /data/config.yaml ] && rm /data/config.yaml
|
||||||
|
|
||||||
# Check if config file is there, or create one from template
|
# Check if config file is there, or create one from template
|
||||||
if [ -f $CONFIGSOURCE ]; then
|
if [ -f $CONFIGSOURCE ]; then
|
||||||
echo "Using config file found in $CONFIGSOURCE"
|
ln -s $CONFIGSOURCE /data
|
||||||
|
bashio::log.info "Using config file found in $CONFIGSOURCE"
|
||||||
|
|
||||||
|
# Check if yaml is valid
|
||||||
|
yamllint -d relaxed --no-warnings $CONFIGSOURCE &> ERROR || EXIT_CODE=$?
|
||||||
|
if [ $EXIT_CODE = 0 ]; then
|
||||||
|
echo "Config file is a valid yaml"
|
||||||
|
else
|
||||||
|
cat ERROR
|
||||||
|
bashio::log.fatal "Config file has an invalid yaml format. Please check the file in $CONFIGSOURCE. Errors list above."
|
||||||
|
bashio::exit.nok
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "No config file, creating one from template"
|
# Create symlink for addon to create config
|
||||||
# Create folder
|
|
||||||
mkdir -p "$(dirname "${CONFIGSOURCE}")"
|
mkdir -p "$(dirname "${CONFIGSOURCE}")"
|
||||||
# Placing template in config
|
touch ${CONFIGSOURCE}
|
||||||
cp /data/config.yaml "$(dirname "${CONFIGSOURCE}")" &>/dev/null \
|
ln -s $CONFIGSOURCE /data
|
||||||
|| cp /templates/config.yaml "$(dirname "${CONFIGSOURCE}")"
|
rm $CONFIGSOURCE
|
||||||
# Need to restart
|
# Need to restart
|
||||||
bashio::log.fatal "Config file not found, creating a new one. Please customize the file in $CONFIGSOURCE before restarting."
|
bashio::log.fatal "Config file not found. The addon will create a new one, then stop. Please customize the file in $CONFIGSOURCE before restarting."
|
||||||
bashio::exit.nok
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if yaml is valid
|
# Check if database is here or create symlink
|
||||||
#yamllint -d relaxed --no-warnings $CONFIGSOURCE &> ERROR || EXIT_CODE=$?
|
if [ -f $DATABASESOURCE ]; then
|
||||||
#if [ $EXIT_CODE = 0 ]; then
|
ln -s $CONFIGSOURCE /data
|
||||||
# echo "Config file is a valid yaml"
|
bashio::log.info "Using database file found in $DATABASESOURCE"
|
||||||
#else
|
else
|
||||||
# cat ERROR
|
# Create symlink for addon to create database
|
||||||
# bashio::log.fatal "Config file has an invalid yaml format. Please check the file in $CONFIGSOURCE. Errors list above."
|
mkdir -p "$(dirname "${DATABASESOURCE}")"
|
||||||
# bashio::exit.nok
|
touch ${DATABASESOURCE}
|
||||||
#fi
|
ln -s $DATABASESOURCE /data
|
||||||
|
rm $DATABASESOURCE
|
||||||
# Create symlink
|
fi
|
||||||
[ -f /data/config.yaml ] && rm /data/config.yaml
|
|
||||||
ln -s $CONFIGSOURCE /data
|
|
||||||
echo "Symlink created"
|
|
||||||
|
|
||||||
##############
|
##############
|
||||||
# Launch App #
|
# Launch App #
|
||||||
@@ -40,7 +54,7 @@ echo " "
|
|||||||
bashio::log.info "Starting the app"
|
bashio::log.info "Starting the app"
|
||||||
echo " "
|
echo " "
|
||||||
|
|
||||||
echo "TZ is $TZ"
|
# Test mode
|
||||||
if [ $(bashio::config "TZ") = "test" ]; then
|
if [ $(bashio::config "TZ") = "test" ]; then
|
||||||
echo "secret mode found"
|
echo "secret mode found"
|
||||||
cd /config
|
cd /config
|
||||||
|
|||||||
Reference in New Issue
Block a user