One of the things on my TODO list has been to improve the "kept"
messaging from fw_update.
For example, deleting a firmware doesn't list what was kept and if you
specified a firmware to install on the command-line the "kept" list only
included the specified firmware.
Instead, we only keep track of the firmware that was modified and use
that to remove from the full list of installed firmware. That works not
only in the above case, but in the "autodetect" case that included the
installed firmware in what we attempt to update.
The one difference is when we are downloading firmware to a local
directory, in which case the "kept" list is the list of firmware that
would have been downloaded but was already there, as it was previously.
Comments? Suggestions on something better? OK?
I only just learned the "${foo[@]:+${foo[@]}}" trick to avoid the
"parameter not set" error from "set -o nounset" when I need to iterate
an empty list. I can get rid of so many unnecessary levels of
indentation now!
Index: fw_update.sh
===================================================================
RCS file: /cvs/src/usr.sbin/fw_update/fw_update.sh,v
retrieving revision 1.42
diff -u -p -r1.42 fw_update.sh
--- fw_update.sh 20 Feb 2022 21:53:04 -0000 1.42
+++ fw_update.sh 20 Feb 2022 23:45:13 -0000
@@ -241,6 +241,24 @@ installed_firmware() {
done
}
+_tokenize() {
+ local IFS=,
+ echo $*
+}
+
+kept_firmware() {
+ local _modified _m _i _d
+ set -A _modified -- $( _tokenize "$@" )
+
+ for _i in $( installed_firmware '*' '-firmware-' '*' ); do
+ _d="$( firmware_devicename "$_i" )"
+ for _m in "${_modified[@]:+${_modified[@]}}"; do
+ [ "$_d" = "$_m" ] && continue 2
+ done
+ echo "$_d"
+ done
+}
+
detect_firmware() {
local _devices _last='' _d
@@ -471,8 +489,14 @@ if "$DELETE"; then
done
fi
+ kept=''
+ for k in $( kept_firmware ); do
+ kept="$kept,$k"
+ done
+
deleted="${deleted#,}"
- echo "${0:##*/}: deleted ${deleted:-none}";
+ kept="${kept#,}"
+ echo "${0:##*/}: deleted ${deleted:-none}; kept ${kept:-none}";
exit
fi
@@ -529,7 +553,6 @@ if [ "${devices[*]:-}" ]; then
for i in "${installed[@]}"; do
if [ "${f##*/}" = "$i.tgz" ]; then
((VERBOSE > 2)) && echo "Keep $i"
- kept="$kept,$d"
continue 2
fi
done
@@ -616,6 +639,11 @@ updated="${updated:#,}"
kept="${kept:#,}"
[ "${unregister:-}" ] && unregister="; unregistered ${unregister:#,}"
if "$INSTALL"; then
+ kept=''
+ for k in $( kept_firmware "$added" "$updated" "$unregister" ); do
+ kept="$kept,$k"
+ done
+ kept="${kept:#,}"
echo "${0##*/}: added ${added:-none}; updated ${updated:-none}; kept
${kept:-none}${unregister}"
else
echo "${0##*/}: downloaded ${added:-none}; kept
${kept:-none}${unregister}"