From 7f3c0ebae33e3d13e2b124ff6cd600e2bd0197bb Mon Sep 17 00:00:00 2001 From: Alexandre Date: Fri, 19 Nov 2021 10:47:33 +0100 Subject: [PATCH] Improvement --- cloudcommander/rootfs/entrypoint.sh | 35 ++++++++++++++++++++++++- enedisgateway2mqtt/rootfs/entrypoint.sh | 18 ++++++------- filebrowser/rootfs/entrypoint.sh | 35 ++++++++++++++++++++++++- gazpar2mqtt/rootfs/entrypoint.sh | 20 +++++++------- gazpar2mqtt/rootfs/scripts/99-run.sh | 6 ++--- 5 files changed, 89 insertions(+), 25 deletions(-) diff --git a/cloudcommander/rootfs/entrypoint.sh b/cloudcommander/rootfs/entrypoint.sh index 0e11bd2bb..8c723434b 100644 --- a/cloudcommander/rootfs/entrypoint.sh +++ b/cloudcommander/rootfs/entrypoint.sh @@ -1,6 +1,39 @@ #!/bin/bash -echo "Starting scripts :" +echo "Starting..." + +################################### +# Export all addon options as env # +################################### + +# For all keys in options.json +JSONSOURCE="/data/options.json" + +# Export keys as env variables +echo "All addon options were exported as variables" +mapfile -t arr < <(jq -r 'keys[]' ${JSONSOURCE}) +for KEYS in ${arr[@]}; do + # export key + VALUE=$(jq .$KEYS ${JSONSOURCE}) + export ${KEYS}=${VALUE//[\"\']/} +done + +################ +# Set timezone # +################ +if [ ! -z "TZ" ]; then + if [ -f /usr/share/zoneinfo/$TZ ]; then + echo "Timezone set from $(cat /etc/timezone) to $TZ" + ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ >/etc/timezone + else + echo "WARNING : Timezone $TZ is invalid, it will be kept to default value of $(cat /etc/timezone)" + fi +fi + +#################### +# Starting scripts # +#################### + for SCRIPTS in scripts/*; do [ -e "$SCRIPTS" ] || continue echo "$SCRIPTS: executing" diff --git a/enedisgateway2mqtt/rootfs/entrypoint.sh b/enedisgateway2mqtt/rootfs/entrypoint.sh index 914a2c6b7..8c723434b 100644 --- a/enedisgateway2mqtt/rootfs/entrypoint.sh +++ b/enedisgateway2mqtt/rootfs/entrypoint.sh @@ -13,21 +13,21 @@ JSONSOURCE="/data/options.json" echo "All addon options were exported as variables" mapfile -t arr < <(jq -r 'keys[]' ${JSONSOURCE}) for KEYS in ${arr[@]}; do - # export key - VALUE=$(jq .$KEYS ${JSONSOURCE}) - export ${KEYS}=${VALUE:1:-1} -done + # export key + VALUE=$(jq .$KEYS ${JSONSOURCE}) + export ${KEYS}=${VALUE//[\"\']/} +done ################ # Set timezone # ################ if [ ! -z "TZ" ]; then - if [ -f /usr/share/zoneinfo/$TZ ]; then - echo "Timezone set from $(cat /etc/timezone) to $TZ" - ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone - else + if [ -f /usr/share/zoneinfo/$TZ ]; then + echo "Timezone set from $(cat /etc/timezone) to $TZ" + ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ >/etc/timezone + else echo "WARNING : Timezone $TZ is invalid, it will be kept to default value of $(cat /etc/timezone)" - fi + fi fi #################### diff --git a/filebrowser/rootfs/entrypoint.sh b/filebrowser/rootfs/entrypoint.sh index 0e11bd2bb..8c723434b 100644 --- a/filebrowser/rootfs/entrypoint.sh +++ b/filebrowser/rootfs/entrypoint.sh @@ -1,6 +1,39 @@ #!/bin/bash -echo "Starting scripts :" +echo "Starting..." + +################################### +# Export all addon options as env # +################################### + +# For all keys in options.json +JSONSOURCE="/data/options.json" + +# Export keys as env variables +echo "All addon options were exported as variables" +mapfile -t arr < <(jq -r 'keys[]' ${JSONSOURCE}) +for KEYS in ${arr[@]}; do + # export key + VALUE=$(jq .$KEYS ${JSONSOURCE}) + export ${KEYS}=${VALUE//[\"\']/} +done + +################ +# Set timezone # +################ +if [ ! -z "TZ" ]; then + if [ -f /usr/share/zoneinfo/$TZ ]; then + echo "Timezone set from $(cat /etc/timezone) to $TZ" + ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ >/etc/timezone + else + echo "WARNING : Timezone $TZ is invalid, it will be kept to default value of $(cat /etc/timezone)" + fi +fi + +#################### +# Starting scripts # +#################### + for SCRIPTS in scripts/*; do [ -e "$SCRIPTS" ] || continue echo "$SCRIPTS: executing" diff --git a/gazpar2mqtt/rootfs/entrypoint.sh b/gazpar2mqtt/rootfs/entrypoint.sh index 2f4713acd..8c723434b 100644 --- a/gazpar2mqtt/rootfs/entrypoint.sh +++ b/gazpar2mqtt/rootfs/entrypoint.sh @@ -9,27 +9,25 @@ echo "Starting..." # For all keys in options.json JSONSOURCE="/data/options.json" - # Export keys as env variables echo "All addon options were exported as variables" mapfile -t arr < <(jq -r 'keys[]' ${JSONSOURCE}) for KEYS in ${arr[@]}; do - # export key - VALUE=$(jq .$KEYS ${JSONSOURCE}) - export ${KEYS}=${VALUE:1:-1} -done - + # export key + VALUE=$(jq .$KEYS ${JSONSOURCE}) + export ${KEYS}=${VALUE//[\"\']/} +done ################ # Set timezone # ################ if [ ! -z "TZ" ]; then - if [ -f /usr/share/zoneinfo/$TZ ]; then - echo "Timezone set from $(cat /etc/timezone) to $TZ" - ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone - else + if [ -f /usr/share/zoneinfo/$TZ ]; then + echo "Timezone set from $(cat /etc/timezone) to $TZ" + ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ >/etc/timezone + else echo "WARNING : Timezone $TZ is invalid, it will be kept to default value of $(cat /etc/timezone)" - fi + fi fi #################### diff --git a/gazpar2mqtt/rootfs/scripts/99-run.sh b/gazpar2mqtt/rootfs/scripts/99-run.sh index adde0a41b..0f6590df7 100644 --- a/gazpar2mqtt/rootfs/scripts/99-run.sh +++ b/gazpar2mqtt/rootfs/scripts/99-run.sh @@ -26,11 +26,11 @@ fi # Check if yaml is valid EXIT_CODE=0 -yamllint -d relaxed --no-warnings $CONFIGSOURCE &> ERROR || EXIT_CODE=$? +yamllint -d relaxed --no-warnings $CONFIGSOURCE &>ERROR || EXIT_CODE=$? if [ $EXIT_CODE = 0 ]; then echo "Config file is a valid yaml" else - cat ERROR + 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 @@ -66,7 +66,7 @@ bashio::log.info "Starting the app with the variables in /config/gazpar2mqtt" for word in $(parse_yaml "$CONFIGSOURCE" ""); do # Data validation if [[ $word =~ ^.+[=].+$ ]]; then - $word=${word//\"} + $word=${word//[\"\']/} export $word # Export the variable bashio::log.blue "$word" else