While testing some other stuff, job@ noticed that fw_update(8) kept
reinstalling the bwfm firmware.  After some research it turns out that
fw_update ignores installed packages that aren't marked "@option
firmware" and it does that too hard.  I'll likely commit the below patch
to at least warn folks that something is wrong, but I don't think I want
to start ignoring that @option.  Installing firmware from the ports tree
with `make install` is one way for this to happen.

One side effect of this is fw_update will move a temporary directory
full of package registration into the existing directory, which the
below patch will also fix.  Unfortunately if that has happened, neither
fw_update or pkg_delete will happily clean up that package and cleanup
requires rm -r.  Should I try to work up a patch to clean that up
automatically?

Should packaging firmware add that option to the +CONTENTS, instead of
relying on fw_update at install time?

$ cd /usr/ports/sysutils/firmware/bwfm
$ make install
===>  Installing bwfm-firmware-20200316.1.3p3 from 
/usr/ports/packages/sparc64/all/
bwfm-firmware-20200316.1.3p3: ok
$ grep @option /var/db/pkg/bwfm-firmware-20200316.1.3p3/+CONTENTS  
@option manual-installation
$ doas pkg_delete bwfm-firmware-20200316.1.3p3                     
bwfm-firmware-20200316.1.3p3: ok
$ doas fw_update 
/usr/ports/packages/sparc64/all/bwfm-firmware-20200316.1.3p3.tgz
fw_update: added bwfm; updated none; kept none
$ grep @option /var/db/pkg/bwfm-firmware-20200316.1.3p3/+CONTENTS               
   
@option manual-installation
@option firmware
$ 


Comments or suggestions before I commit this?


diff --git a/fw_update.sh b/fw_update.sh
index 02261dd..11eae49 100644
--- a/fw_update.sh
+++ b/fw_update.sh
@@ -320,7 +320,8 @@ detect_firmware() {
 }
 
 add_firmware () {
-       local _f="${1##*/}" _m="${2:-Install}" _pkgname
+       local _f="${1##*/}" _m="${2:-Install}"
+       local _pkgdir="${DESTDIR}/var/db/pkg" _pkg
        FWPKGTMP="$( tmpdir "${DESTDIR}/var/db/pkg/.firmware" )"
        local _flags=-vm
        case "$VERBOSE" in
@@ -333,9 +334,16 @@ add_firmware () {
                    -s ",^firmware,${DESTDIR}/etc/firmware," \
                    -C / -zxphf - "+*" "firmware/*"
 
-       _pkgname="$( sed -n '/^@name /{s///p;q;}' "${FWPKGTMP}/+CONTENTS" )"
-       if [ ! "$_pkgname" ]; then
-               echo "Failed to extract name from $1, partial install" 2>&1
+       _pkg="$( sed -n '/^@name /{s///p;q;}' "${FWPKGTMP}/+CONTENTS" )"
+       if [ ! "$_pkg" ]; then
+               warn "Failed to extract name from $1, partial install"
+               rm -rf "$FWPKGTMP"
+               unset FWPKGTMP
+               return 1
+       fi
+
+       if [ -e "$_pkgdir/$_pkg" ]; then
+               warn "Failed to register: $_pkgdir/$_pkg is not firmware"
                rm -rf "$FWPKGTMP"
                unset FWPKGTMP
                return 1
@@ -351,7 +359,7 @@ w
 EOL
 
        chmod 755 "$FWPKGTMP"
-       mv "$FWPKGTMP" "${DESTDIR}/var/db/pkg/${_pkgname}"
+       mv "$FWPKGTMP" "$_pkgdir/$_pkg"
        unset FWPKGTMP
 }
 

Reply via email to