Adapt launcher for remaster

This commit is contained in:
Alexandre
2026-07-17 09:02:23 +02:00
parent 8eb51526a1
commit cc8b402942

View File

@@ -1,85 +1,139 @@
#!/usr/bin/env bashio #!/usr/bin/env bashio
# shellcheck shell=bash # shellcheck shell=bash
set -e set -euo pipefail
############## CONFIG_FILE="$(bashio::config 'CONFIG_LOCATION')"
# Initialize # CONFIG_DIR="$(dirname "${CONFIG_FILE}")"
############## RUNTIME_CONFIG="/data/config.env"
CONFIG_HOME="$(bashio::config "CONFIG_LOCATION")" mkdir -p "${CONFIG_DIR}" /data
CONFIG_HOME="$(dirname "$CONFIG_HOME")"
# Use new config file # Recover from an old add-on bug that could create config.env as a directory.
if [ ! -f "$CONFIG_HOME/config.env" ]; then if [ -d "${CONFIG_FILE}" ]; then
# Copy default config.env bashio::log.warning "Found a directory at ${CONFIG_FILE}; replacing it with a configuration file"
cp /templates/config.env "$CONFIG_HOME/" rm -rf "${CONFIG_FILE}"
chmod 755 "$CONFIG_HOME/config.env" fi
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"
if [ ! -f "${CONFIG_FILE}" ]; then
install -m 0600 /templates/config.env "${CONFIG_FILE}"
bashio::log.warning \
"Created ${CONFIG_FILE}. Add account credentials there and restart the add-on if automatic login is required."
else else
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" bashio::log.info "Using configuration from ${CONFIG_FILE}"
fi fi
# Remove erroneous folder named config.env (bug fix for looping issue) # The remaster reads /fgc/data/config.env. /fgc/data is linked to Home
if [ -d "$CONFIG_HOME/config.env" ]; then # Assistant's persistent /data volume by the Dockerfile.
bashio::log.warning "Found directory named config.env, deleting it..." install -m 0600 "${CONFIG_FILE}" "${RUNTIME_CONFIG}"
rm -rf "$CONFIG_HOME/config.env" # Fix: Ensures directory removal even if it exists sed -i 's/\r$//' "${RUNTIME_CONFIG}"
cp /templates/config.env "$CONFIG_HOME/config.env" # Recreate as a valid file
chmod 755 "$CONFIG_HOME/config.env"
fi
# Copy new file # Export values needed by the VNC entrypoint as well as by the Python app.
mkdir -p /data/data
cp "$CONFIG_HOME/config.env" /data/data/
# Permissions
chmod -R 755 "$CONFIG_HOME"
# Export variables
set -a set -a
echo ""
bashio::log.info "Sourcing variables from $CONFIG_HOME/config.env"
cp "$CONFIG_HOME"/config.env /config.env
# Remove previous instance
sed -i "s|export ||g" /config.env
# Add export for non empty lines
sed -i '/\S/s/^/export /' /config.env
# Delete lines starting with #
sed -i '/export #/d' /config.env
# Get variables
# shellcheck source=/dev/null # shellcheck source=/dev/null
source /config.env source "${RUNTIME_CONFIG}"
rm /config.env
set +a set +a
############## # The Home Assistant port mapping is intentionally kept at 6080 for a seamless
# Launch App # # upgrade from the previous add-on, even though the new upstream defaults to 7080.
############## if [ -n "${NOVNC_PORT:-}" ] && [ "${NOVNC_PORT}" != "6080" ]; then
bashio::log.warning "NOVNC_PORT=${NOVNC_PORT} is not supported by the add-on port mapping; using 6080"
fi
export NOVNC_PORT="6080"
export VNC_PORT="5900"
# Go to folder # Absolute paths from the former image pointed to its Firefox profile. The
cd /data || true # replacement uses Chromium profiles and must start with a separate directory.
if [ "${BROWSER_DIR:-}" = "/data/data/browser" ]; then
bashio::log.warning "Remapping legacy Firefox BROWSER_DIR to the remaster Chromium profile directory"
export BROWSER_DIR="/fgc/data/browser"
fi
if [ "${SCREENSHOTS_DIR:-}" = "/data/data/screenshots" ]; then
export SCREENSHOTS_DIR="/fgc/data/screenshots"
fi
# Fetch commands append_store() {
CMD_ARGUMENTS="$(bashio::config "CMD_ARGUMENTS")" local store="${1}"
IFS=';' local current="${2}"
read -ar strarr <<< "$CMD_ARGUMENTS"
# Sanitizes commands if [[ ",${current}," == *",${store},"* ]]; then
trim() { printf '%s' "${current}"
local var="$*" elif [ -n "${current}" ]; then
var="${var#"${var%%[![:space:]]*}"}" printf '%s,%s' "${current}" "${store}"
var="${var%"${var##*[![:space:]]}"}" else
printf '%s' "$var" printf '%s' "${store}"
fi
} }
# Add docker-entrypoint command legacy_commands_to_stores() {
for val in "${strarr[@]}"; do local commands="${1}"
val="$(trim "$val")" local selected=""
echo " " local command=""
bashio::log.info "Starting the app with arguments \"$val\"" local normalized=""
echo " " local command_list=()
echo "$val" | xargs docker-entrypoint.sh || true
done
bashio::log.info "All actions concluded. Stopping in 10 seconds." IFS=';' read -ra command_list <<< "${commands}"
sleep 10 for command in "${command_list[@]}"; do
bashio::addon.stop normalized="${command,,}"
case "${normalized}" in
*epic-games*|*epicgames*|*" epic "*)
selected="$(append_store "epic" "${selected}")"
;;
*prime-gaming*|*primegaming*|*" prime "*|*" amazon "*)
selected="$(append_store "prime" "${selected}")"
;;
*steam-games*|*" steam "*)
selected="$(append_store "steam" "${selected}")"
;;
*gamerpower*)
selected="$(append_store "gamerpower" "${selected}")"
;;
*" gog"*|gog*)
selected="$(append_store "gog" "${selected}")"
;;
esac
done
printf '%s' "${selected}"
}
# A non-empty STORES add-on option takes priority. Otherwise retain a STORES
# value from config.env, then fall back to translating the legacy commands.
STORES_OPTION="$(bashio::config 'STORES')"
if [ -n "${STORES_OPTION}" ]; then
export STORES="${STORES_OPTION}"
elif [ -z "${STORES:-}" ]; then
CMD_ARGUMENTS="$(bashio::config 'CMD_ARGUMENTS')"
STORES="$(legacy_commands_to_stores "${CMD_ARGUMENTS}")"
export STORES="${STORES:-epic,prime,gog}"
fi
bashio::log.info "Enabled stores: ${STORES:-epic,prime,gog}"
# Import claim history from vogler/free-games-claimer once. Legacy files and
# browser data are retained under /data/data for rollback and manual recovery.
/usr/local/bin/migrate_vogler_data.py
APP_COMMAND=(python3 /fgc/main.py)
if bashio::config.true 'RUN_ONCE'; then
APP_COMMAND+=(--once)
bashio::log.info "Starting a single claiming run (legacy-compatible mode)"
set +e
/usr/local/bin/docker-entrypoint.sh "${APP_COMMAND[@]}"
exit_code=$?
set -e
if [ "${exit_code}" -ne 0 ]; then
bashio::log.error "Free Games Claimer exited with status ${exit_code}"
else
bashio::log.info "Claiming run completed"
fi
bashio::log.info "Stopping the add-on"
sleep 2
bashio::addon.stop
exit "${exit_code}"
fi
bashio::log.info "Starting the built-in scheduler"
exec /usr/local/bin/docker-entrypoint.sh "${APP_COMMAND[@]}"