From 1c702c4a4395025332d4340f326500c590811dc8 Mon Sep 17 00:00:00 2001 From: afresh1 Date: Fri, 5 Aug 2022 18:01:40 +0000 Subject: [PATCH] Support wildcards in fw_update patterns Up to two wildcards, since we have to work around the way ksh does things. Tweaks and suggestions from kn@ and halex@ --- usr.sbin/fw_update/fw_update.sh | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/usr.sbin/fw_update/fw_update.sh b/usr.sbin/fw_update/fw_update.sh index 238eb9c20f4..4b77d4c7bd7 100644 --- a/usr.sbin/fw_update/fw_update.sh +++ b/usr.sbin/fw_update/fw_update.sh @@ -1,5 +1,5 @@ #!/bin/ksh -# $OpenBSD: fw_update.sh,v 1.42 2022/02/20 21:53:04 afresh1 Exp $ +# $OpenBSD: fw_update.sh,v 1.43 2022/08/05 18:01:40 afresh1 Exp $ # # Copyright (c) 2021 Andrew Hewus Fresh # @@ -168,21 +168,30 @@ verify() { } firmware_in_dmesg() { - local _d _m _line _dmesgtail _last='' _nl=$( echo ) + local IFS + local _d _m _dmesgtail _last='' _nl=' +' # The dmesg can contain multiple boots, only look in the last one _dmesgtail="$( echo ; sed -n 'H;/^OpenBSD/h;${g;p;}' /var/run/dmesg.boot )" grep -v '^[[:space:]]*#' "$FWPATTERNS" | while read -r _d _m; do - [ "$_d" = "$_last" ] && continue + [ "$_d" = "$_last" ] && continue [ "$_m" ] || _m="${_nl}${_d}[0-9] at " [ "$_m" = "${_m#^}" ] || _m="${_nl}${_m#^}" - if [[ $_dmesgtail = *$_m* ]]; then - echo "$_d" - _last="$_d" - fi + IFS='*' + set -- $_m + unset IFS + + case $# in + 1|2|3) [[ $_dmesgtail = *$1*([!$_nl])${2-}*([!$_nl])${3-}* ]] || continue;; + *) echo "${0##*/}: Bad pattern '${_m#$_nl}' in $FWPATTERNS" >&2; exit 1 ;; + esac + + echo "$_d" + _last="$_d" done } -- 2.20.1