config yaml improve

This commit is contained in:
Alexandre
2021-12-03 21:30:35 +01:00
parent f3d08df1fe
commit 654b43c344
4 changed files with 52 additions and 76 deletions

View File

@@ -73,7 +73,7 @@ while IFS= read -r line; do
secret=${line#*secret } secret=${line#*secret }
# Check if single match # Check if single match
secretnum=$(sed -n "/$secret:/=" /config/secrets.yaml) secretnum=$(sed -n "/$secret:/=" /config/secrets.yaml)
[[ $(echo $secretnum) == *' '* ]] && bashio::log.fatal "There are multiple matches for your password name. Please check your secrets.yaml file" && bashio::exit.nok [[ $(echo $secretnum) == *' '* ]] && bashio::exit.nok "There are multiple matches for your password name. Please check your secrets.yaml file"
# Get text # Get text
secret=$(sed -n "/$secret:/p" /config/secrets.yaml) secret=$(sed -n "/$secret:/p" /config/secrets.yaml)
secret=${secret#*: } secret=${secret#*: }
@@ -81,20 +81,14 @@ while IFS= read -r line; do
fi fi
# Data validation # Data validation
if [[ $line =~ ^.+[=].+$ ]]; then if [[ $line =~ ^.+[=].+$ ]]; then
export $line # Export the variable export $line
logmsg="Variable set : $line" # Export the variable
if [ -f /etc/services.d/*/*run* ]; then [ -f /etc/services.d/*/*run* ] && sed -i "1a export $line" /etc/services.d/*/*run*
sed -i "1a export $line" /etc/services.d/*/run # Export the variable [ -f /scripts/*run* ] && sed -i "1a export $line" /scripts/*run*
sed -i "1a bashio::log.blue \"$logmsg\" || echo \"$logmsg\"" /etc/services.d/*/run # Show text in colour # Show in log
fi
if [ -f /scripts/*run* ]; then
sed -i "1a export $line" /scripts/*run* # Export the variable
sed -i "1a bashio::log.blue \"$logmsg\" || echo \"$logmsg\"" /scripts/*run* # Show text in colour
fi
bashio::log.blue "$line" bashio::log.blue "$line"
else else
bashio::log.fatal "$line does not follow the structure KEY=text" bashio::exit.nok "$line does not follow the correct structure. Please check your yaml file."
bashio::exit.nok
fi fi
done <"/tmpfile" done <"/tmpfile"

View File

@@ -45,10 +45,10 @@ function parse_yaml {
local prefix=$2 || local prefix="" local prefix=$2 || local prefix=""
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @ | tr @ '\034') local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @ | tr @ '\034')
sed -ne "s|^\($s\):|\1|" \ sed -ne "s|^\($s\):|\1|" \
-e "s| #.*$||g" \ -e "s| #.*$||g" \
-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" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 | -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{ awk -F$fs '{
indent = length($1)/2; indent = length($1)/2;
vname[indent] = $2; vname[indent] = $2;
@@ -73,7 +73,7 @@ while IFS= read -r line; do
secret=${line#*secret } secret=${line#*secret }
# Check if single match # Check if single match
secretnum=$(sed -n "/$secret:/=" /config/secrets.yaml) secretnum=$(sed -n "/$secret:/=" /config/secrets.yaml)
[[ $(echo $secretnum) == *' '* ]] && bashio::log.fatal "There are multiple matches for your password name. Please check your secrets.yaml file" && bashio::exit.nok [[ $(echo $secretnum) == *' '* ]] && bashio::exit.nok "There are multiple matches for your password name. Please check your secrets.yaml file"
# Get text # Get text
secret=$(sed -n "/$secret:/p" /config/secrets.yaml) secret=$(sed -n "/$secret:/p" /config/secrets.yaml)
secret=${secret#*: } secret=${secret#*: }
@@ -81,28 +81,22 @@ while IFS= read -r line; do
fi fi
# Data validation # Data validation
if [[ $line =~ ^.+[=].+$ ]]; then if [[ $line =~ ^.+[=].+$ ]]; then
export $line # Export the variable export $line
logmsg="Variable set : $line" # Export the variable
if [ -f /etc/services.d/*/*run* ]; then [ -f /etc/services.d/*/*run* ] && sed -i "1a export $line" /etc/services.d/*/*run*
sed -i "1a export $line" /etc/services.d/*/run # Export the variable [ -f /scripts/*run* ] && sed -i "1a export $line" /scripts/*run*
sed -i "1a bashio::log.blue $logmsg 2>/dev/null || echo \$(tput -T xterm setaf 2)$logmsg\$(tput -T xterm setaf 0) 2>/dev/null" /etc/services.d/*/run # Show text in colour # Show in log
fi
if [ -f /scripts/*run* ]; then
sed -i "1a export $line" /scripts/*run* # Export the variable
sed -i "1a bashio::log.blue $logmsg 2>/dev/null || echo \$(tput -T xterm setaf 2)$logmsg\$(tput -T xterm setaf 0) 2>/dev/null" /scripts/*run* # Show text in colour
fi
bashio::log.blue "$line" bashio::log.blue "$line"
else else
bashio::log.fatal "$line does not follow the structure KEY=text" bashio::exit.nok "$line does not follow the correct structure. Please check your yaml file."
bashio::exit.nok
fi fi
done <"/tmpfile" done <"/tmpfile"
# Test mode # Test mode
TZ=$(bashio::config "TZ") TZ=$(bashio::config "TZ")
if [ $TZ = "test" ]; then if [ $TZ = "test" ]; then
echo "secret mode found, launching script in /config/test.sh" echo "secret mode found, launching script in /config/test.sh"
cd /config cd /config
chmod 777 test.sh chmod 777 test.sh
./test.sh ./test.sh
fi fi

View File

@@ -45,10 +45,10 @@ function parse_yaml {
local prefix=$2 || local prefix="" local prefix=$2 || local prefix=""
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @ | tr @ '\034') local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @ | tr @ '\034')
sed -ne "s|^\($s\):|\1|" \ sed -ne "s|^\($s\):|\1|" \
-e "s| #.*$||g" \ -e "s| #.*$||g" \
-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" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 | -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{ awk -F$fs '{
indent = length($1)/2; indent = length($1)/2;
vname[indent] = $2; vname[indent] = $2;
@@ -73,7 +73,7 @@ while IFS= read -r line; do
secret=${line#*secret } secret=${line#*secret }
# Check if single match # Check if single match
secretnum=$(sed -n "/$secret:/=" /config/secrets.yaml) secretnum=$(sed -n "/$secret:/=" /config/secrets.yaml)
[[ $(echo $secretnum) == *' '* ]] && bashio::log.fatal "There are multiple matches for your password name. Please check your secrets.yaml file" && bashio::exit.nok [[ $(echo $secretnum) == *' '* ]] && bashio::exit.nok "There are multiple matches for your password name. Please check your secrets.yaml file"
# Get text # Get text
secret=$(sed -n "/$secret:/p" /config/secrets.yaml) secret=$(sed -n "/$secret:/p" /config/secrets.yaml)
secret=${secret#*: } secret=${secret#*: }
@@ -81,28 +81,22 @@ while IFS= read -r line; do
fi fi
# Data validation # Data validation
if [[ $line =~ ^.+[=].+$ ]]; then if [[ $line =~ ^.+[=].+$ ]]; then
export $line # Export the variable export $line
logmsg="Variable set : $line" # Export the variable
if [ -f /etc/services.d/*/*run* ]; then [ -f /etc/services.d/*/*run* ] && sed -i "1a export $line" /etc/services.d/*/*run*
sed -i "1a export $line" /etc/services.d/*/run # Export the variable [ -f /scripts/*run* ] && sed -i "1a export $line" /scripts/*run*
sed -i "1a bashio::log.blue $logmsg 2>/dev/null || echo \$(tput -T xterm setaf 2)$logmsg\$(tput -T xterm setaf 0) 2>/dev/null" /etc/services.d/*/run # Show text in colour # Show in log
fi
if [ -f /scripts/*run* ]; then
sed -i "1a export $line" /scripts/*run* # Export the variable
sed -i "1a bashio::log.blue $logmsg 2>/dev/null || echo \$(tput -T xterm setaf 2)$logmsg\$(tput -T xterm setaf 0) 2>/dev/null" /scripts/*run* # Show text in colour
fi
bashio::log.blue "$line" bashio::log.blue "$line"
else else
bashio::log.fatal "$line does not follow the structure KEY=text" bashio::exit.nok "$line does not follow the correct structure. Please check your yaml file."
bashio::exit.nok
fi fi
done <"/tmpfile" done <"/tmpfile"
# Test mode # Test mode
TZ=$(bashio::config "TZ") TZ=$(bashio::config "TZ")
if [ $TZ = "test" ]; then if [ $TZ = "test" ]; then
echo "secret mode found, launching script in /config/test.sh" echo "secret mode found, launching script in /config/test.sh"
cd /config cd /config
chmod 777 test.sh chmod 777 test.sh
./test.sh ./test.sh
fi fi

View File

@@ -45,10 +45,10 @@ function parse_yaml {
local prefix=$2 || local prefix="" local prefix=$2 || local prefix=""
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @ | tr @ '\034') local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @ | tr @ '\034')
sed -ne "s|^\($s\):|\1|" \ sed -ne "s|^\($s\):|\1|" \
-e "s| #.*$||g" \ -e "s| #.*$||g" \
-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" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 | -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{ awk -F$fs '{
indent = length($1)/2; indent = length($1)/2;
vname[indent] = $2; vname[indent] = $2;
@@ -73,7 +73,7 @@ while IFS= read -r line; do
secret=${line#*secret } secret=${line#*secret }
# Check if single match # Check if single match
secretnum=$(sed -n "/$secret:/=" /config/secrets.yaml) secretnum=$(sed -n "/$secret:/=" /config/secrets.yaml)
[[ $(echo $secretnum) == *' '* ]] && bashio::log.fatal "There are multiple matches for your password name. Please check your secrets.yaml file" && bashio::exit.nok [[ $(echo $secretnum) == *' '* ]] && bashio::exit.nok "There are multiple matches for your password name. Please check your secrets.yaml file"
# Get text # Get text
secret=$(sed -n "/$secret:/p" /config/secrets.yaml) secret=$(sed -n "/$secret:/p" /config/secrets.yaml)
secret=${secret#*: } secret=${secret#*: }
@@ -81,28 +81,22 @@ while IFS= read -r line; do
fi fi
# Data validation # Data validation
if [[ $line =~ ^.+[=].+$ ]]; then if [[ $line =~ ^.+[=].+$ ]]; then
export $line # Export the variable export $line
logmsg="Variable set : $line" # Export the variable
if [ -f /etc/services.d/*/*run* ]; then [ -f /etc/services.d/*/*run* ] && sed -i "1a export $line" /etc/services.d/*/*run*
sed -i "1a export $line" /etc/services.d/*/run # Export the variable [ -f /scripts/*run* ] && sed -i "1a export $line" /scripts/*run*
sed -i "1a bashio::log.blue $logmsg || echo \$(tput -T xterm setaf 2)$logmsg\$(tput -T xterm setaf 0) || echo $logmsg" /etc/services.d/*/run # Show text in colour # Show in log
fi
if [ -f /scripts/*run* ]; then
sed -i "1a export $line" /scripts/*run* # Export the variable
sed -i "1a bashio::log.blue $logmsg || echo \$(tput -T xterm setaf 2)$logmsg\$(tput -T xterm setaf 0) || echo $logmsg" /scripts/*run* # Show text in colour
fi
bashio::log.blue "$line" bashio::log.blue "$line"
else else
bashio::log.fatal "$line does not follow the structure KEY=text" bashio::exit.nok "$line does not follow the correct structure. Please check your yaml file."
bashio::exit.nok
fi fi
done <"/tmpfile" done <"/tmpfile"
# Test mode # Test mode
TZ=$(bashio::config "TZ") TZ=$(bashio::config "TZ")
if [ $TZ = "test" ]; then if [ $TZ = "test" ]; then
echo "secret mode found, launching script in /config/test.sh" echo "secret mode found, launching script in /config/test.sh"
cd /config cd /config
chmod 777 test.sh chmod 777 test.sh
./test.sh ./test.sh
fi fi