Download firmware to LOCALSRC when using filenames
authorafresh1 <afresh1@openbsd.org>
Thu, 28 Sep 2023 00:45:22 +0000 (00:45 +0000)
committerafresh1 <afresh1@openbsd.org>
Thu, 28 Sep 2023 00:45:22 +0000 (00:45 +0000)
Previously if you did: fw_update otus-firmware-1.0p1.tgz
and that firmware didn't exist in the current directory,
we would download that firmware into the current directory.
Which is not the expected outcome.

usr.sbin/fw_update/fw_update.sh

index 02261dd..0a773cd 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/ksh
-#      $OpenBSD: fw_update.sh,v 1.47 2023/08/31 21:29:53 afresh1 Exp $
+#      $OpenBSD: fw_update.sh,v 1.48 2023/09/28 00:45:22 afresh1 Exp $
 #
 # Copyright (c) 2021,2023 Andrew Hewus Fresh <afresh1@openbsd.org>
 #
@@ -600,7 +600,6 @@ if [ "${devices[*]:-}" ]; then
                                fi
                                continue
                        fi
-                       f="$LOCALSRC/$f"
                elif ! "$INSTALL" && ! grep -Fq "($f)" "$CFILE" ; then
                        warn "Cannot download local file $f"
                        exit 1
@@ -626,6 +625,12 @@ if [ "${devices[*]:-}" ]; then
                        fi
                fi
 
+               # Fetch an unqualified file into LOCALSRC
+               # if it doesn't exist in the current directory.
+               if [ "$f" = "${f##/}" ] && [ ! -e "$f" ]; then
+                       f="$LOCALSRC/$f"
+               fi
+
                if "$verify_existing" && [ -e "$f" ]; then
                        pending_status=false
                        if ((VERBOSE == 1)); then