From d453d964e1e0827dad217e1dd424dbaf82e434fc Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Mon, 20 Jul 2020 11:21:06 +0200 Subject: [PATCH] [type/__uci_section] Fix in section matching --- cdist/conf/type/__uci_section/explorer/match | 23 +++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/cdist/conf/type/__uci_section/explorer/match b/cdist/conf/type/__uci_section/explorer/match index a3832bff..a5619d4e 100644 --- a/cdist/conf/type/__uci_section/explorer/match +++ b/cdist/conf/type/__uci_section/explorer/match @@ -17,7 +17,8 @@ # You should have received a copy of the GNU General Public License # along with cdist. If not, see . # -# This explorer the "prefix" of the section matching --match. +# This explorer determines the "prefix" of the --type section matching --match +# if set, or __object_id otherwise. squote_values() { sed -e '/=".*"$/{s/="/='\''/;s/"$/'\''/}' \ @@ -28,7 +29,7 @@ RS=$(printf '\036') if ! test -e "${__object:?}/parameter/match" then - if echo "${__object_id:?}" | grep -qvE '^[^.]+\.[^.]+$' + if ! echo "${__object_id:?}" | grep -q -e '^[^.]\{1,\}\.[^.]\{1,\}$' then echo 'Section identifiers are a package and section name separated by a "." (period).' >&2 exit 1 @@ -47,16 +48,28 @@ test -s "${__object:?}/parameter/match" && test -s "${__object:?}/parameter/type } # Find by match -match=$(cat "${__object:?}/parameter/match") -sect_type_filter=$(cat "${__object:?}/parameter/type") +# NOTE: Apart from section types all values are printed in single quotes by UCI. +match=$(head -n 1 "${__object:?}/parameter/match" | squote_values) +if ! grep -q -e '^[^.]\{1,\}\.[^.]\{1,\}$' "${__object:?}/parameter/type" +then + echo 'Section types are a package name and section type separated by a "." (period).' >&2 + exit 1 +fi + +sect_type_filter=$(cat "${__object:?}/parameter/type") package_filter=${sect_type_filter%%.*} -section_filter=${sect_type_filter##*.} +section_filter=${sect_type_filter#*.} +# FIXME: Does not work with named sections regex="^${package_filter}\.@${section_filter}\[[0-9]\{1,\}\]\.${match%%=*}=" matched_sections=$( uci -s -N -d "${RS}" show "${package_filter}" 2>/dev/null \ | grep -e "${regex}" \ + | while read -r _line + do + if test "${_line#*=}" = "${match#*=}"; then echo "${_line}"; fi + done \ | sed -e 's/\.[^.]*=.*$//') if test "$(echo "${matched_sections}" | wc -l)" -gt 1