diff --git a/fireflyiii_data_importer/CHANGELOG.md b/fireflyiii_data_importer/CHANGELOG.md index f762207ab..99d1c2fd3 100644 --- a/fireflyiii_data_importer/CHANGELOG.md +++ b/fireflyiii_data_importer/CHANGELOG.md @@ -1,13 +1,19 @@ +- Add auto import of csv files periodically (see readme) +- Add auto import of configurations (see readme) - Add config.yaml configurable options (see readme) ## version-0.7.0 (22-01-2022) + - Update to latest version from fireflyiii/data-importer ## version-0.6.5 (21-01-2022) + - Update to latest version from fireflyiii/data-importer ## 0.7.0 (21-01-2022) + - Update to latest version from firefly-iii/data-importer + ## 0.6.5 (15-01-2022) - Update to latest version from firefly-iii/data-importer diff --git a/fireflyiii_data_importer/Dockerfile b/fireflyiii_data_importer/Dockerfile index 47dfeac3f..874c28649 100644 --- a/fireflyiii_data_importer/Dockerfile +++ b/fireflyiii_data_importer/Dockerfile @@ -47,7 +47,7 @@ RUN if ! command -v bash >/dev/null 2>/dev/null; then (apt-get update && apt-get && chmod -R 755 /etc/cont-init.d || printf '%s\n' "${MODULES}" >/MODULESFILE # Manual apps -ENV PACKAGES="" +ENV PACKAGES="cron" # Automatic apps & bashio RUN if ! command -v bash >/dev/null 2>/dev/null; then (apt-get update && apt-get install -yqq --no-install-recommends bash || apk add --no-cache bash) >/dev/null; fi \ diff --git a/fireflyiii_data_importer/Readme.md b/fireflyiii_data_importer/Readme.md index a65a8fd23..0c9ee8a58 100644 --- a/fireflyiii_data_importer/Readme.md +++ b/fireflyiii_data_importer/Readme.md @@ -20,7 +20,9 @@ This addon is based on the docker image https://hub.docker.com/r/fireflyiii/data ## Configuration -Read official documentation for information how to set the variables: https://docs.firefly-iii.org/data-importer +Read official documentation for information how to set the variables: https://docs.firefly-iii.org/data-importer. +Configurations can be added in the /config/addons_config/fireflyiii_data_importer/configurations folder according to :https://docs.firefly-iii.org/data-importer/help/config/ +An auto import can be made by adding files in /config/addons_config/fireflyiii_data_importer/import_files according to : https://docs.firefly-iii.org/data-importer/usage/command_line/ Options can be configured through two ways : @@ -35,6 +37,8 @@ Options can be configured through two ways : "NORDIGEN_KEY": your Nordigen Client Secret "SPECTRE_APP_ID": your Spectre / Salt Edge Client ID "SPECTRE_SECRET": your Spectre / Salt Edge Client secret +"Updates": hourly|daily|weekly # Sets an automatic upload of files set in /config/addons_config/fireflyiii_data_importer/import_files +"silent": true # suppresses debug messages ``` - Config.yaml diff --git a/fireflyiii_data_importer/config.json b/fireflyiii_data_importer/config.json index 5d7c2d7d1..a58ecb8ed 100644 --- a/fireflyiii_data_importer/config.json +++ b/fireflyiii_data_importer/config.json @@ -1,21 +1,13 @@ { "apparmor": true, - "arch": [ - "aarch64", - "amd64", - "armv7" - ], + "arch": ["aarch64", "amd64", "armv7"], "boot": "auto", "description": "Data importer for Firefly III (separate addon)", "devices": [], "environment": { "TRUSTED_PROXIES": "**" }, - "map": [ - "config:rw", - "share:rw", - "ssl" - ], + "map": ["config:rw", "share:rw", "ssl"], "name": "Firefly iii Data Importer", "options": { "CONFIG_LOCATION": "/config/addons_config/fireflyiii_data_importer/config.yaml" @@ -34,11 +26,13 @@ "NORDIGEN_KEY": "str?", "SPECTRE_APP_ID": "str?", "SPECTRE_SECRET": "str?", - "CONFIG_LOCATION": "str" + "CONFIG_LOCATION": "str", + "Updates": "list(|hourly|daily|weekly)?", + "silent": "bool?" }, "slug": "fireflyiii_data_importer", "upstream": "version-0.7.0", "url": "https://github.com/alexbelgium/hassio-addons", - "version": "version-0.7.0-2", + "version": "version-0.7.0-3", "webui": "[PROTO:ssl]://[HOST]:[PORT:8080]" } diff --git a/fireflyiii_data_importer/rootfs/etc/cont-init.d/20-folders.sh b/fireflyiii_data_importer/rootfs/etc/cont-init.d/20-folders.sh index 1a5a3a4c8..fdefa15e4 100644 --- a/fireflyiii_data_importer/rootfs/etc/cont-init.d/20-folders.sh +++ b/fireflyiii_data_importer/rootfs/etc/cont-init.d/20-folders.sh @@ -4,6 +4,8 @@ CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION") # Create directory mkdir -p "$(dirname "${CONFIGSOURCE}")" +mkdir -p "$(dirname "${CONFIGSOURCE}/import_files")" +mkdir -p "$(dirname "${CONFIGSOURCE}/configurations")" # Make sure permissions are right chown -R $(id -u):$(id -g) "$(dirname "${CONFIGSOURCE}")" diff --git a/fireflyiii_data_importer/rootfs/etc/cont-init.d/99-run.sh b/fireflyiii_data_importer/rootfs/etc/cont-init.d/99-run.sh index 1b5515714..24ba5e9d3 100644 --- a/fireflyiii_data_importer/rootfs/etc/cont-init.d/99-run.sh +++ b/fireflyiii_data_importer/rootfs/etc/cont-init.d/99-run.sh @@ -1,5 +1,109 @@ #!/usr/bin/env bashio +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 + +################ +# CRON OPTIONS # +################ + +if bashio::config.has_value 'Updates'; then + + CONFIGSOURCE="$(dirname "${CONFIGSOURCE}/import_files")" + + if [ "$(ls -A $CONFIGSOURCE)" ]; 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 777 /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" + export IMPORT_DIR_WHITELIST + + bashio::log.info "Automatic updates were requested. The files in $CONFIGSOURCE will be imported $FREQUENCY." + + else + bashio::log.fatal "Automatic updates were requested, but there are no configuration files in $CONFIGSOURCE. There will therefore be be no automatic updates." + fi + +else + + bashio::log.info "Automatic updates not set in addon config. If you add configuration files in $CONFIGSOURCE, they won't be automatically updated." + +fi + +############## +# LAUNCH APP # +############## + +bashio::log.info "Please wait while the app is loading !" + +/./usr/local/bin/entrypoint.sh + export JSON_CONFIGURATION_DIR +fi + +################ +# CRON OPTIONS # +################ + +if bashio::config.has_value 'Updates'; then + + CONFIGSOURCE="$(dirname "${CONFIGSOURCE}/import_files")" + + if [ "$(ls -A $CONFIGSOURCE)" ]; 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 777 /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" + export IMPORT_DIR_WHITELIST + + bashio::log.info "Automatic updates were requested. The files in $CONFIGSOURCE will be imported $FREQUENCY." + + else + bashio::log.fatal "Automatic updates were requested, but there are no configuration files in $CONFIGSOURCE. There will therefore be be no automatic updates." + fi + +else + + bashio::log.info "Automatic updates not set in addon config. If you add configuration files in $CONFIGSOURCE, they won't be automatically updated." + +fi + ############## # LAUNCH APP # ############## diff --git a/fireflyiii_data_importer/rootfs/templates/cronupdate b/fireflyiii_data_importer/rootfs/templates/cronupdate new file mode 100644 index 000000000..c74499c82 --- /dev/null +++ b/fireflyiii_data_importer/rootfs/templates/cronupdate @@ -0,0 +1,13 @@ +#!/usr/bin/env bashio + +PATHTOFILES="$(bashio::config "CONFIG_LOCATION")" +PATHTOFILES="$(dirname "${PATHTOFILES}")" + +bashio::log.info "Running update according to defined schedule. Files located in $PATHTOFILES will be imported" +if bashio::config.true 'silent'; then + bashio::log.warning "Silent mode activated. Only errors will be shown. Please disable in addon options if you need to debug" + /usr/local/bin/php /var/www/html/artisan importer:auto-import >/dev/null +else + /usr/local/bin/php /var/www/html/artisan importer:auto-import "$PATHTOFILES"/import_files +fi +fi