Commit 6ffb9edf authored by ssrq's avatar ssrq

[type/__uci_section] Create only necessary __uci objects

parent 0840afce
Pipeline #2487 failed with stage
in 58 seconds
......@@ -24,5 +24,5 @@ RS=$(printf '\036')
section=$("${__type_explorer:?}/match")
test -n "${section}" || exit 0
uci -s -N -d "${RS}" show "${section}" 2>/dev/null \
| grep -v -e "^${section}=" || true
# uci(1) returns 1 if the section does not exist
uci -s -N -d "${RS}" show "${section}" 2>/dev/null || true
......@@ -74,6 +74,10 @@ in
type_is=$(cat "${__object:?}/explorer/type")
type_should=$(cat "${__object:?}/parameter/type")
optnames_is=$(
sed -n -e 's/=.*$//' \
-e 's/^[^.]*\.[^.]*\.//p' "${__object:?}/explorer/options")
if test -f "${__object:?}/parameter/option"
then
optnames_should=$(
......@@ -106,33 +110,51 @@ in
fi
# Make sure the section itself is present
__uci "${section}" --state present --transaction "${transaction_name}" \
--value "${sect_type}"
export require=__uci/"${section}"
if ! grep -qxF "${section}=${sect_type}" "${__object}/explorer/options"
then
__uci "${section}" --state present --transaction "${transaction_name}" \
--value "${sect_type}"
export require=__uci/"${section}"
fi
# Delete options not in "should"
sed -e 's/=.*$//;s/^.*\.//' "${__object:?}/explorer/options" \
| while read -r optname
echo "${optnames_is}" \
| while read -r _optname
do
if ! grep_line "${optname}" "${optnames_should}"
if ! grep_line "${_optname}" "${optnames_should}"
then
__uci "${section}.${optname}" --state absent \
__uci "${section}.${_optname}" --state absent \
--transaction "${transaction_name}" </dev/null
fi
done
# Set "should" options
echo "${optnames_should}" \
| while read -r optname
| grep -e . \
| while read -r _optname
do
test -n "${optname}" || continue # ignore empty lines
grep "^${optname}=" <"${__object:?}/parameter/option" \
| sed -e 's/^.*=//' \
| unquote_lines \
| append_values \
__uci "${section}.${optname}" --state present \
--transaction "${transaction_name}"
values_is=$(
sed -n -e 's/^[^.]*\.[^.]*\.//;T' \
-e "/^${_optname}=/p" \
-e 's/^.*=//' "${__object}/explorer/options" \
| tr '\036' '\n' \
| unquote_lines)
values_should=$(
grep -e "^${_optname}=" "${__object:?}/parameter/option" \
| sed -e 's/^.*=//' \
| unquote_lines)
# Compare "is" and "should" and only generate __uci object
# if they differ
if test "${values_is}" != "${values_should}"
then
# NOTE: Do not use dash's echo, as it evaluates escape
# sequences.
printf '%s\n' "${values_should}" | append_values \
__uci "${section}.${_optname}" --state present \
--transaction "${transaction_name}"
fi
done
;;
(absent)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment