Improve config.env handling, remove erroneous folder

https://github.com/alexbelgium/hassio-addons/issues/1655
This commit is contained in:
Alexandre
2024-12-05 16:58:22 +01:00
committed by GitHub
parent 890cc2f477
commit 756347580c

View File

@@ -6,29 +6,35 @@ set -e
# Initialize # # Initialize #
############## ##############
# Use new config file
CONFIG_HOME="$(bashio::config "CONFIG_LOCATION")" CONFIG_HOME="$(bashio::config "CONFIG_LOCATION")"
CONFIG_HOME="$(dirname "$CONFIG_HOME")" CONFIG_HOME="$(dirname "$CONFIG_HOME")"
if [ ! -f "$CONFIG_HOME"/config.env ]; then
# Use new config file
if [ ! -f "$CONFIG_HOME/config.env" ]; then
# Copy default config.env # Copy default config.env
cp /templates/config.env "$CONFIG_HOME"/config.env cp /templates/config.env "$CONFIG_HOME/"
chmod 777 "$CONFIG_HOME"/config.env chmod 755 "$CONFIG_HOME/config.env"
bashio::log.warning "A default config.env file was copied in $CONFIG_HOME. Please customize according to https://github.com/vogler/free-games-claimer/tree/main#configuration--options and restart the add-on" bashio::log.warning "A default config.env file was copied to $CONFIG_HOME. Please customize according to https://github.com/vogler/free-games-claimer/tree/main#configuration--options and restart the add-on"
else else
bashio::log.warning "The config.env file found in $CONFIG_HOME will be used. Please customize according to https://github.com/vogler/free-games-claimer/tree/main#configuration--options and restart the add-on" bashio::log.info "Using existing config.env file in $CONFIG_HOME. Please customize according to https://github.com/vogler/free-games-claimer/tree/main#configuration--options and restart the add-on"
fi
# Remove erroneous folder named config.env
if [ -d "$CONFIG_HOME/config.env" ]; then
rm -r "$CONFIG_HOME/config.env"
fi fi
# Copy new file # Copy new file
mkdir -p /data/data mkdir -p /data/data
\cp "$CONFIG_HOME"/config.env /data/data/ cp "$CONFIG_HOME/config.env" /data/data/
# Permissions # Permissions
chmod -R 777 "$CONFIG_HOME" chmod -R 755 "$CONFIG_HOME"
# Export variables # Export variables
set -a set -a
echo "" echo ""
bashio::log.info "Getting variables from $CONFIG_HOME/config.env" bashio::log.info "Sourcing variables from $CONFIG_HOME/config.env"
cp "$CONFIG_HOME"/config.env /config.env cp "$CONFIG_HOME"/config.env /config.env
# Remove previous instance # Remove previous instance
sed -i "s|export ||g" /config.env sed -i "s|export ||g" /config.env
@@ -67,8 +73,7 @@ trim() {
# Add docker-entrypoint command # Add docker-entrypoint command
# Print each value of the array by using the loop # Print each value of the array by using the loop
for val in "${strarr[@]}"; for val in "${strarr[@]}"; do
do
#Removes whitespaces #Removes whitespaces
val="$(trim "$val")" val="$(trim "$val")"
echo " " echo " "
@@ -78,6 +83,6 @@ do
echo "$val" | xargs docker-entrypoint.sh || true echo "$val" | xargs docker-entrypoint.sh || true
done done
bashio::log.info "All actions concluded, addon will stop in 10 seconds" bashio::log.info "All actions concluded. Stopping in 10 seconds."
sleep 10 sleep 10
bashio::addon.stop bashio::addon.stop