Fix ini functions to handle spaces in section names
This allows section names to look like:
[ default ]
OpenSSL is the primary offender for this usage.
Change-Id: If5c711107e73cebab9d4a26ca02a7ce572224377
diff --git a/functions b/functions
index 8ab3eef..cdb982d 100644
--- a/functions
+++ b/functions
@@ -370,7 +370,7 @@
local file=$1
local section=$2
local option=$3
- sed -i -e "/^\[$section\]/,/^\[.*\]/ s|^\($option[ \t]*=.*$\)|#\1|" $file
+ sed -ie "/^\[ *$section *\]/,/^\[.*\]/ s|^\($option[ \t]*=.*$\)|#\1|" $file
}
# Uncomment an option in an INI file
@@ -379,7 +379,7 @@
local file=$1
local section=$2
local option=$3
- sed -i -e "/^\[$section\]/,/^\[.*\]/ s|[^ \t]*#[ \t]*\($option[ \t]*=.*$\)|\1|" $file
+ sed -ie "/^\[ *$section *\]/,/^\[.*\]/ s|[^ \t]*#[ \t]*\($option[ \t]*=.*$\)|\1|" $file
}
@@ -390,7 +390,7 @@
local section=$2
local option=$3
local line
- line=$(sed -ne "/^\[$section\]/,/^\[.*\]/ { /^$option[ \t]*=/ p; }" $file)
+ line=$(sed -ne "/^\[ *$section *\]/,/^\[.*\]/ { /^$option[ \t]*=/ p; }" $file)
echo ${line#*=}
}
@@ -402,18 +402,18 @@
local section=$2
local option=$3
local value=$4
- if ! grep -q "^\[$section\]" $file; then
+ if ! grep -q "^\[ *$section *\]" $file; then
# Add section at the end
echo -e "\n[$section]" >>$file
fi
if [[ -z "$(iniget $file $section $option)" ]]; then
# Add it
- sed -i -e "/^\[$section\]/ a\\
+ sed -ie "/^\[ *$section *\]/ a\\
$option = $value
" $file
else
# Replace it
- sed -i -e "/^\[$section\]/,/^\[.*\]/ s|^\($option[ \t]*=[ \t]*\).*$|\1$value|" $file
+ sed -ie "/^\[ *$section *\]/,/^\[.*\]/ s|^\($option[ \t]*=[ \t]*\).*$|\1$value|" $file
fi
}