forked from ungleich-public/cdist
		
	[type/__uci_section] Fix in section matching
This commit is contained in:
		
					parent
					
						
							
								179815b5e9
							
						
					
				
			
			
				commit
				
					
						d453d964e1
					
				
			
		
					 1 changed files with 18 additions and 5 deletions
				
			
		| 
						 | 
					@ -17,7 +17,8 @@
 | 
				
			||||||
# You should have received a copy of the GNU General Public License
 | 
					# You should have received a copy of the GNU General Public License
 | 
				
			||||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
 | 
					# along with cdist. If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
# 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() {
 | 
					squote_values() {
 | 
				
			||||||
	sed -e '/=".*"$/{s/="/='\''/;s/"$/'\''/}' \
 | 
						sed -e '/=".*"$/{s/="/='\''/;s/"$/'\''/}' \
 | 
				
			||||||
| 
						 | 
					@ -28,7 +29,7 @@ RS=$(printf '\036')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if ! test -e "${__object:?}/parameter/match"
 | 
					if ! test -e "${__object:?}/parameter/match"
 | 
				
			||||||
then
 | 
					then
 | 
				
			||||||
	if echo "${__object_id:?}" | grep -qvE '^[^.]+\.[^.]+$'
 | 
						if ! echo "${__object_id:?}" | grep -q -e '^[^.]\{1,\}\.[^.]\{1,\}$'
 | 
				
			||||||
	then
 | 
						then
 | 
				
			||||||
		echo 'Section identifiers are a package and section name separated by a "." (period).' >&2
 | 
							echo 'Section identifiers are a package and section name separated by a "." (period).' >&2
 | 
				
			||||||
		exit 1
 | 
							exit 1
 | 
				
			||||||
| 
						 | 
					@ -47,16 +48,28 @@ test -s "${__object:?}/parameter/match" && test -s "${__object:?}/parameter/type
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Find by match
 | 
					# Find by match
 | 
				
			||||||
match=$(cat "${__object:?}/parameter/match")
 | 
					# NOTE: Apart from section types all values are printed in single quotes by UCI.
 | 
				
			||||||
sect_type_filter=$(cat "${__object:?}/parameter/type")
 | 
					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%%.*}
 | 
					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%%=*}="
 | 
					regex="^${package_filter}\.@${section_filter}\[[0-9]\{1,\}\]\.${match%%=*}="
 | 
				
			||||||
 | 
					
 | 
				
			||||||
matched_sections=$(
 | 
					matched_sections=$(
 | 
				
			||||||
	uci -s -N -d "${RS}" show "${package_filter}" 2>/dev/null \
 | 
						uci -s -N -d "${RS}" show "${package_filter}" 2>/dev/null \
 | 
				
			||||||
	| grep -e "${regex}" \
 | 
						| grep -e "${regex}" \
 | 
				
			||||||
 | 
						| while read -r _line
 | 
				
			||||||
 | 
						  do
 | 
				
			||||||
 | 
							  if test "${_line#*=}" = "${match#*=}"; then echo "${_line}"; fi
 | 
				
			||||||
 | 
						  done \
 | 
				
			||||||
	| sed -e 's/\.[^.]*=.*$//')
 | 
						| sed -e 's/\.[^.]*=.*$//')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if test "$(echo "${matched_sections}" | wc -l)" -gt 1
 | 
					if test "$(echo "${matched_sections}" | wc -l)" -gt 1
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue