mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-01-11 18:31:02 +01:00
Anticipate partial migration
https://github.com/alexbelgium/hassio-addons/issues/600
This commit is contained in:
@@ -19,6 +19,44 @@ if [ -f /data/config.yaml ] && [ ! -L /data/config.yaml ]; then
|
||||
mv /data/config.yaml "$CONFIGSOURCE".bak
|
||||
fi
|
||||
|
||||
############
|
||||
# DATABASE #
|
||||
############
|
||||
|
||||
# If migration was performed, save file in config folder
|
||||
if [ -f /data/enedisgateway.db.migrate ]; then
|
||||
bashio::log.warning "Migration performed, enedisgateway.db.migrate copied in $(dirname "${CONFIGSOURCE}")"
|
||||
mv /data/enedisgateway.db.migrate "$(dirname "${CONFIGSOURCE}")"
|
||||
fi
|
||||
|
||||
# If migration was performed, save file in config folder
|
||||
if [ -f /data/cache.db ]; then
|
||||
if [ -f "$DATABASESOURCE" ]; then cp "$DATABASESOURCE" "$DATABASESOURCE".bak2; fi
|
||||
if [ -f "$(dirname "${CONFIGSOURCE}")"/enedisgateway.db ]; then mv "$(dirname "${CONFIGSOURCE}")"/enedisgateway.db "$(dirname "${CONFIGSOURCE}")"/enedisgateway.db.bak2; fi
|
||||
mv /data/cache.db "$(dirname "${CONFIGSOURCE}")"
|
||||
fi
|
||||
|
||||
# If migration was not performed, enable migration
|
||||
if [ -f "$(dirname "${CONFIGSOURCE}")"/enedisgateway.db ]; then
|
||||
mv "$(dirname "${CONFIGSOURCE}")"/enedisgateway.db /data
|
||||
fi
|
||||
|
||||
# Check if database is here or create symlink
|
||||
if [ -f "$DATABASESOURCE" ]; then
|
||||
# Create symlink if not existing yet
|
||||
ln -sf "${DATABASESOURCE}" /data && echo "creating symlink"
|
||||
bashio::log.info "Using database file found in $(dirname "${CONFIGSOURCE}")"
|
||||
else
|
||||
# Create symlink for addon to create database
|
||||
touch "${DATABASESOURCE}"
|
||||
ln -sf "$DATABASESOURCE" /data
|
||||
rm "$DATABASESOURCE"
|
||||
fi
|
||||
|
||||
##########
|
||||
# CONFIG #
|
||||
##########
|
||||
|
||||
# Check if config file is there, or create one from template
|
||||
if [ -f "$CONFIGSOURCE" ]; then
|
||||
# Create symlink if not existing yet
|
||||
@@ -44,25 +82,6 @@ else
|
||||
bashio::log.fatal "Config file not found. The addon will create a new one, then stop. Please customize the file in $CONFIGSOURCE before restarting."
|
||||
fi
|
||||
|
||||
# Fetch the migrated versions and copy it in the new database location
|
||||
if [ -f /data/enedisgateway.db.migrate ]; then
|
||||
bashio::log.warning "Migration performed, enedisgateway.db.migrate copied in $(dirname "${CONFIGSOURCE}")"
|
||||
mv /data/enedisgateway.db.migrate "$(dirname "${CONFIGSOURCE}")"
|
||||
mv /data/cache.db "$(dirname "${CONFIGSOURCE}")"
|
||||
fi
|
||||
|
||||
# Check if database is here or create symlink
|
||||
if [ -f "$DATABASESOURCE" ]; then
|
||||
# Create symlink if not existing yet
|
||||
ln -sf "${DATABASESOURCE}" /data && echo "creating symlink"
|
||||
bashio::log.info "Using database file found in $(dirname "${CONFIGSOURCE}")"
|
||||
else
|
||||
# Create symlink for addon to create database
|
||||
touch "${DATABASESOURCE}"
|
||||
ln -sf "$DATABASESOURCE" /data
|
||||
rm "$DATABASESOURCE"
|
||||
fi
|
||||
|
||||
##############
|
||||
# Launch App #
|
||||
##############
|
||||
|
||||
Reference in New Issue
Block a user