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
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"

View File

@@ -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
####################

View File

@@ -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"

View File

@@ -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
####################

View File

@@ -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