Files
hassio-addons/fireflyiii_data_importer/rootfs/etc/cont-init.d/99-run.sh
copilot-swe-agent[bot] 9893ad41dc Fix cron auto-import env vars and health check log spam for Firefly III Data Importer
- Source /etc/environment in cronupdate to load addon env vars (FIREFLY_III_URL, etc.)
- Persist cron-needed vars (JSON_CONFIGURATION_DIR, IMPORT_DIR_WHITELIST, etc.) to /etc/environment
- Fix inverted nginx map values that caused health check logs to spam while suppressing real requests

Co-authored-by: alexbelgium <44178713+alexbelgium@users.noreply.github.com>
2026-02-23 12:33:50 +00:00

88 lines
2.7 KiB
Bash
Executable File

#!/usr/bin/env bashio
# shellcheck shell=bash
set -e
CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION")
#################
# CONFIG IMPORT #
#################
if [ "$(ls -A "$CONFIGSOURCE/configurations")" ]; then
bashio::log.info "Configurations were found in $CONFIGSOURCE/configurations, they will be loaded."
JSON_CONFIGURATION_DIR="$CONFIGSOURCE/configurations"
export JSON_CONFIGURATION_DIR
fi
# Allow config dir
export IMPORT_DIR_ALLOWLIST="$CONFIGSOURCE"
export IMPORT_DIR_WHITELIST="${CONFIGSOURCE}/import_files"
# shellcheck disable=SC2155
export AUTO_IMPORT_SECRET="$(bashio::config "AUTO_IMPORT_SECRET")"
# shellcheck disable=SC2155
export CAN_POST_FILES="$(bashio::config "CAN_POST_FILES")"
# shellcheck disable=SC2155
export CAN_POST_AUTOIMPORT="$(bashio::config "CAN_POST_AUTOIMPORT")"
# Persist variables to /etc/environment for cron jobs
{
[ -n "$JSON_CONFIGURATION_DIR" ] && echo "JSON_CONFIGURATION_DIR=\"$JSON_CONFIGURATION_DIR\""
echo "IMPORT_DIR_ALLOWLIST=\"$IMPORT_DIR_ALLOWLIST\""
echo "IMPORT_DIR_WHITELIST=\"$IMPORT_DIR_WHITELIST\""
echo "AUTO_IMPORT_SECRET=\"$AUTO_IMPORT_SECRET\""
echo "CAN_POST_FILES=\"$CAN_POST_FILES\""
echo "CAN_POST_AUTOIMPORT=\"$CAN_POST_AUTOIMPORT\""
} >> /etc/environment
chmod 600 /etc/environment
################
# CRON OPTIONS #
################
if bashio::config.has_value 'Updates'; then
# Align update with options
echo ""
FREQUENCY=$(bashio::config 'Updates')
bashio::log.info "$FREQUENCY updates"
echo ""
# Sets cron // do not delete this message
cp /templates/cronupdate /etc/cron."${FREQUENCY}"/
chmod 755 /etc/cron."${FREQUENCY}"/cronupdate
# Sets cron to run with www-data user
# sed -i 's|root|www-data|g' /etc/crontab
# Starts cron
service cron start
# Export variables
IMPORT_DIR_WHITELIST="${CONFIGSOURCE}/import_files"
export IMPORT_DIR_WHITELIST
bashio::log.info "Automatic updates were requested. The files in ${CONFIGSOURCE}/import_files will be imported $FREQUENCY."
if [ ! "$(ls -A "${CONFIGSOURCE}"/import_files)" ]; then
bashio::log.fatal "Automatic updates were requested, but there are no configuration files in ${CONFIGSOURCE}/import_files. There will therefore be be no automatic updates."
true
fi
else
bashio::log.info "Automatic updates not set in addon config. If you add configuration files in ${CONFIGSOURCE}/import_files, they won't be automatically updated."
fi
##############
# LAUNCH APP #
##############
bashio::log.info "Starting entrypoint scripts"
mkdir -p /storage
chown www-data:www-data /storage
sudo -Eu www-data bash -c 'cd /var/www/html && /scripts/11-execute-things.sh'