This commit is contained in:
Hans Karlinius
2024-11-27 11:33:54 +01:00
parent 7b6c903eda
commit 595b433d9d
4 changed files with 39 additions and 8 deletions

View File

@@ -1,3 +0,0 @@
#!/bin/bash
echo "All done!" > /share/example_addon_output.txt

View File

@@ -0,0 +1,29 @@
#!/command/with-contenv bashio
# Changed code from https://gist.github.com/thomedes/6201620#file-ini-sed
file="/config/vhclient.ini"
awkconfig_update_value(){
local section="$1"
local key="$2"
local value="$3"
awk -v RS="(^|\n)[:blank:]*\\\\[" -v setFound=0 -v sec="$section"\
-v kv="$key=$value" -v secPat="$section" -v subPat="$key"\
'$1~"^[[:blank:]\[]*" secPat "[:blank:]*\]"{ \
s = sub("[:blank:]*" subPat "[:blank:]*=[^#^;^\n]*", kv);\
$0 = $0 ((0 == s)? "\n" kv "\n" : ""); # adding kv to $0;\
secFound=1;\
}\
$1~"^[^;^#^\n^=]*\]"{\
$0 = "[" $0; # adding the record separator "[" back in\
}\
NF{sub(/\n$/, ""); print $0}\
END{ if (secFound == 0){\
print "[" sec "]";\
print kv;\
}\
}' $file > /tmp/vhclient_config_tmp
}
awkconfig_update_value $1 $2 $3
mv /tmp/vhclient_config_tmp $file