Improvement

This commit is contained in:
Alexandre
2021-11-19 10:47:33 +01:00
parent 49f70cdd69
commit 7f3c0ebae3
5 changed files with 89 additions and 25 deletions

View File

@@ -1,6 +1,39 @@
#!/bin/bash #!/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 for SCRIPTS in scripts/*; do
[ -e "$SCRIPTS" ] || continue [ -e "$SCRIPTS" ] || continue
echo "$SCRIPTS: executing" echo "$SCRIPTS: executing"

View File

@@ -13,21 +13,21 @@ JSONSOURCE="/data/options.json"
echo "All addon options were exported as variables" echo "All addon options were exported as variables"
mapfile -t arr < <(jq -r 'keys[]' ${JSONSOURCE}) mapfile -t arr < <(jq -r 'keys[]' ${JSONSOURCE})
for KEYS in ${arr[@]}; do for KEYS in ${arr[@]}; do
# export key # export key
VALUE=$(jq .$KEYS ${JSONSOURCE}) VALUE=$(jq .$KEYS ${JSONSOURCE})
export ${KEYS}=${VALUE:1:-1} export ${KEYS}=${VALUE//[\"\']/}
done done
################ ################
# Set timezone # # Set timezone #
################ ################
if [ ! -z "TZ" ]; then if [ ! -z "TZ" ]; then
if [ -f /usr/share/zoneinfo/$TZ ]; then if [ -f /usr/share/zoneinfo/$TZ ]; then
echo "Timezone set from $(cat /etc/timezone) to $TZ" echo "Timezone set from $(cat /etc/timezone) to $TZ"
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ >/etc/timezone
else else
echo "WARNING : Timezone $TZ is invalid, it will be kept to default value of $(cat /etc/timezone)" echo "WARNING : Timezone $TZ is invalid, it will be kept to default value of $(cat /etc/timezone)"
fi fi
fi fi
#################### ####################

View File

@@ -1,6 +1,39 @@
#!/bin/bash #!/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 for SCRIPTS in scripts/*; do
[ -e "$SCRIPTS" ] || continue [ -e "$SCRIPTS" ] || continue
echo "$SCRIPTS: executing" echo "$SCRIPTS: executing"

View File

@@ -9,27 +9,25 @@ echo "Starting..."
# For all keys in options.json # For all keys in options.json
JSONSOURCE="/data/options.json" JSONSOURCE="/data/options.json"
# Export keys as env variables # Export keys as env variables
echo "All addon options were exported as variables" echo "All addon options were exported as variables"
mapfile -t arr < <(jq -r 'keys[]' ${JSONSOURCE}) mapfile -t arr < <(jq -r 'keys[]' ${JSONSOURCE})
for KEYS in ${arr[@]}; do for KEYS in ${arr[@]}; do
# export key # export key
VALUE=$(jq .$KEYS ${JSONSOURCE}) VALUE=$(jq .$KEYS ${JSONSOURCE})
export ${KEYS}=${VALUE:1:-1} export ${KEYS}=${VALUE//[\"\']/}
done done
################ ################
# Set timezone # # Set timezone #
################ ################
if [ ! -z "TZ" ]; then if [ ! -z "TZ" ]; then
if [ -f /usr/share/zoneinfo/$TZ ]; then if [ -f /usr/share/zoneinfo/$TZ ]; then
echo "Timezone set from $(cat /etc/timezone) to $TZ" echo "Timezone set from $(cat /etc/timezone) to $TZ"
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ >/etc/timezone
else else
echo "WARNING : Timezone $TZ is invalid, it will be kept to default value of $(cat /etc/timezone)" echo "WARNING : Timezone $TZ is invalid, it will be kept to default value of $(cat /etc/timezone)"
fi fi
fi fi
#################### ####################

View File

@@ -26,11 +26,11 @@ fi
# Check if yaml is valid # Check if yaml is valid
EXIT_CODE=0 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 if [ $EXIT_CODE = 0 ]; then
echo "Config file is a valid yaml" echo "Config file is a valid yaml"
else 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::log.fatal "Config file has an invalid yaml format. Please check the file in $CONFIGSOURCE. Errors list above."
bashio::exit.nok bashio::exit.nok
fi fi
@@ -66,7 +66,7 @@ bashio::log.info "Starting the app with the variables in /config/gazpar2mqtt"
for word in $(parse_yaml "$CONFIGSOURCE" ""); do for word in $(parse_yaml "$CONFIGSOURCE" ""); do
# Data validation # Data validation
if [[ $word =~ ^.+[=].+$ ]]; then if [[ $word =~ ^.+[=].+$ ]]; then
$word=${word//\"} $word=${word//[\"\']/}
export $word # Export the variable export $word # Export the variable
bashio::log.blue "$word" bashio::log.blue "$word"
else else