From 32d6a8d18c4598e9ac11862a9d27733766075b05 Mon Sep 17 00:00:00 2001 From: Alexandre Date: Tue, 30 Nov 2021 13:36:23 +0100 Subject: [PATCH] allow config yaml --- webtrees/config.json | 10 +-- webtrees/rootfs/scripts/90-config_yaml.sh | 79 +++++++++++++++++++++++ 2 files changed, 82 insertions(+), 7 deletions(-) create mode 100644 webtrees/rootfs/scripts/90-config_yaml.sh diff --git a/webtrees/config.json b/webtrees/config.json index af6a0826c..28f36fe2f 100644 --- a/webtrees/config.json +++ b/webtrees/config.json @@ -21,10 +21,8 @@ "map": ["share:rw", "ssl"], "name": "Webtrees", "options": { - "ssl_not_working": false, - "certfile": "fullchain.pem", - "keyfile": "privkey.pem", - "BASE_URL": "http://192.168.178.69", + "CONFIG_LOCATION": "/config/addons_config/webtrees/config.yaml", + "BASE_URL": "http://192.168.178.23", "DB_TYPE": "sqlite" }, "ports": { @@ -36,9 +34,7 @@ "443/tcp": "Https web interface" }, "schema": { - "ssl_not_working": "bool", - "certfile": "str", - "keyfile": "str", + "CONFIG_LOCATION": "str", "BASE_URL": "url", "DB_TYPE": "list(sqlite|external)" }, diff --git a/webtrees/rootfs/scripts/90-config_yaml.sh b/webtrees/rootfs/scripts/90-config_yaml.sh new file mode 100644 index 000000000..a3e2b4ec9 --- /dev/null +++ b/webtrees/rootfs/scripts/90-config_yaml.sh @@ -0,0 +1,79 @@ +#!/usr/bin/env bashio + +################## +# INITIALIZATION # +################## + +# Where is the config +CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION") + +# Check if config file is there, or create one from template +if [ -f $CONFIGSOURCE ]; then + echo "Using config file found in $CONFIGSOURCE" +else + echo "No config file, creating one from template" + # Create folder + mkdir -p "$(dirname "${CONFIGSOURCE}")" + # Placing template in config + 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.template" + 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 +fi + +# Check if yaml is valid +EXIT_CODE=0 +yamllint -d relaxed --no-warnings $CONFIGSOURCE &>ERROR || EXIT_CODE=$? +if [ $EXIT_CODE = 0 ]; then + echo "Config file is a valid yaml" +else + cat ERROR + bashio::log.fatal "Config file has an invalid yaml format. Please check the file in $CONFIGSOURCE. Errors list above." + # bashio::exit.nok +fi + +# Export all yaml entries as env variables +# Helper function +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 | + awk -F$fs '{ + indent = length($1)/2; + vname[indent] = $2; + for (i in vname) {if (i > indent) {delete vname[i]}} + if (length($3) > 0) { + vn=""; for (i=0; i