From 0365520a4a039b3a4a3fe297acb413a47309b439 Mon Sep 17 00:00:00 2001 From: Alexandre Date: Mon, 29 Nov 2021 09:44:54 +0100 Subject: [PATCH] ENV injector --- .../rootfs/etc/cont-init.d/90-config_yaml.sh | 26 +++++++++++-------- paperless_ng/rootfs/templates/config.yaml | 11 +++++++- zzz_templates/config.yaml | 10 +++++++ 3 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 zzz_templates/config.yaml diff --git a/paperless_ng/rootfs/etc/cont-init.d/90-config_yaml.sh b/paperless_ng/rootfs/etc/cont-init.d/90-config_yaml.sh index b839761fe..603db8daa 100644 --- a/paperless_ng/rootfs/etc/cont-init.d/90-config_yaml.sh +++ b/paperless_ng/rootfs/etc/cont-init.d/90-config_yaml.sh @@ -14,11 +14,15 @@ else echo "No config file, creating one from template" # Create folder mkdir -p "$(dirname "${CONFIGSOURCE}")" - # Downloading template - #TEMPLATESOURCE="/templates/config.yaml" - #curl -L -f -s $TEMPLATESOURCE --output $CONFIGSOURCE # Placing template in config - cp /templates/config.yaml "$(dirname "${CONFIGSOURCE}")" + if [ -f /templates/config.yaml ]; then + # Use available template + cp /templates/config.yaml "$(dirname "${CONFIGSOURCE}")" + else + # Download template + TEMPLATESOURCE="https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/zzz_templates/config.yaml" + curl -L -f -s $TEMPLATESOURCE --output $CONFIGSOURCE + fi # Need to restart bashio::log.fatal "Config file not found, creating a new one. Please customize the file in $CONFIGSOURCE before restarting." # bashio::exit.nok @@ -41,10 +45,10 @@ function parse_yaml { local prefix=$2 || local prefix="" local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @ | tr @ '\034') sed -ne "s|^\($s\):|\1|" \ - -e "s| #.*$||g" \ - -e "s|#.*$||g" \ - -e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \ - -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 | + -e "s| #.*$||g" \ + -e "s|#.*$||g" \ + -e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \ + -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 | awk -F$fs '{ indent = length($1)/2; vname[indent] = $2; @@ -63,9 +67,9 @@ for word in $(parse_yaml "$CONFIGSOURCE" ""); do word=${word//[\"\']/} # Data validation if [[ $word =~ ^.+[=].+$ ]]; then - sed -i "1a export $word" /etc/services.d/*/run # Export the variable - #sed -i "1a echo "... ENV exported : $word" /etc/services.d/*/run # Show text in colour - sed -i "1a echo \"\$(tput setaf 2)... ENV exported : $word \$(tput sgr0)\"" /etc/services.d/*/run # Show text in colour + sed -i "1a export $word" /etc/services.d/*/run # Export the variable + sed -i "1a echo \"\$(tput sgr0)\"" /etc/services.d/*/run # Revert normal color + sed -i "1a echo \"\$(tput setaf 2)... ENV exported : $word" /etc/services.d/*/run # Show text in colour bashio::log.blue "$word" else bashio::log.fatal "$word does not follow the structure KEY=text, it will be ignored and removed from the config" diff --git a/paperless_ng/rootfs/templates/config.yaml b/paperless_ng/rootfs/templates/config.yaml index 25b5b7d06..fe5e2b4b5 100644 --- a/paperless_ng/rootfs/templates/config.yaml +++ b/paperless_ng/rootfs/templates/config.yaml @@ -1,3 +1,12 @@ -# All env variables that you want to enable, full list in +#============================# +# ALEXBELGIUM'S ENV INJECTOR # +#============================# +# +# All env variables set in this file will be enabled in the app +# This allows enabling more options that normally available in the addon options +# This file must be filled according to the yaml format. If the format is invalid, the addon will note an error. To validate your yaml, you can use the free online tool http://www.yamllint.com/ + +# EXAMPLE of the format (you need to remove the # for it to become active) +# TZ: Europe/Paris PAPERLESS_OCR_LANGUAGE: eng PAPERLESS_OCR_MODE: skip diff --git a/zzz_templates/config.yaml b/zzz_templates/config.yaml new file mode 100644 index 000000000..98ef33149 --- /dev/null +++ b/zzz_templates/config.yaml @@ -0,0 +1,10 @@ +#============================# +# ALEXBELGIUM'S ENV INJECTOR # +#============================# +# +# All env variables set in this file will be enabled in the app +# This allows enabling more options that normally available in the addon options +# This file must be filled according to the yaml format. If the format is invalid, the addon will note an error. To validate your yaml, you can use the free online tool http://www.yamllint.com/ + +# EXAMPLE of the format (you need to remove the # for it to become active) +# TZ: Europe/Paris