mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-01-11 02:11:01 +01:00
Update 01-config_yaml.sh
This commit is contained in:
@@ -135,28 +135,26 @@ fi
|
|||||||
# Export all yaml entries as env variables
|
# Export all yaml entries as env variables
|
||||||
# Helper function
|
# Helper function
|
||||||
function parse_yaml {
|
function parse_yaml {
|
||||||
local input_file=$1
|
local prefix=$2 || local prefix=""
|
||||||
local output_file=$2
|
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @ | tr @ '\034')
|
||||||
|
sed -ne "s|^\($s\):|\1|" \
|
||||||
# Process each line to escape special characters and format as needed
|
-e "s| #.*$||g" \
|
||||||
while IFS= read -r line; do
|
-e "s|#.*$||g" \
|
||||||
# Skip lines that are empty or only contain whitespace
|
-e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
|
||||||
[[ -z "$line" ]] && continue
|
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
|
||||||
|
awk -F$fs '{
|
||||||
# Replace the first occurrence of ": " with "="
|
indent = length($1)/2;
|
||||||
line=${line/: /=}
|
vname[indent] = $2;
|
||||||
|
for (i in vname) {if (i > indent) {delete vname[i]}}
|
||||||
# Escape special characters not within single quotes
|
if (length($3) > 0) {
|
||||||
line=$(sed -E "s/([^'])([][\$\`\"\\!&;|<>])/\1\\\\\\2/g" <<<"$line")
|
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
|
||||||
|
printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
|
||||||
# Write to output file
|
}
|
||||||
echo "$line" >>"$output_file"
|
}'
|
||||||
done <"$input_file"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get list of parameters in a file
|
# Get list of parameters in a file
|
||||||
parse_yaml "$CONFIGSOURCE" /tmpfile
|
parse_yaml "$CONFIGSOURCE" "" >/tmpfile
|
||||||
|
|
||||||
# Escape dollars
|
# Escape dollars
|
||||||
sed -i 's|$.|\$|g' /tmpfile
|
sed -i 's|$.|\$|g' /tmpfile
|
||||||
|
|
||||||
@@ -165,6 +163,8 @@ SECRETSFILE="/config/secrets.yaml"
|
|||||||
if [ -f "$SECRETSFILE" ]; then SECRETSFILE="/homeassistant/secrets.yaml"; fi
|
if [ -f "$SECRETSFILE" ]; then SECRETSFILE="/homeassistant/secrets.yaml"; fi
|
||||||
|
|
||||||
while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
|
# Clean output
|
||||||
|
line="${line//[\"\']/}"
|
||||||
# Check if secret
|
# Check if secret
|
||||||
if [[ "${line}" == *'!secret '* ]]; then
|
if [[ "${line}" == *'!secret '* ]]; then
|
||||||
echo "secret detected"
|
echo "secret detected"
|
||||||
|
|||||||
Reference in New Issue
Block a user