=================================================================== RCS file: /cvs/openbsd/fw_update/fw_install.sh,v retrieving revision 1.139 retrieving revision 1.143 diff -u -r1.139 -r1.143 --- openbsd/fw_update/fw_install.sh 2022/01/05 23:34:11 1.139 +++ openbsd/fw_update/fw_install.sh 2022/01/07 01:47:24 1.143 @@ -1,5 +1,5 @@ #!/bin/ksh -# $OpenBSD: fw_install.sh,v 1.139 2022/01/05 23:34:11 afresh1 Exp $ +# $OpenBSD: fw_install.sh,v 1.143 2022/01/07 01:47:24 afresh1 Exp $ # # Copyright (c) 2021 Andrew Hewus Fresh # @@ -37,7 +37,7 @@ DRYRUN=false VERBOSE=0 DELETE=false -DOWNLOAD=true +DOWNLOAD= INSTALL=true LOCALSRC= @@ -239,7 +239,7 @@ local _cwd _pkg="$1" _pkgdir="${DESTDIR}/var/db/pkg" # TODO: Check hash for files before deleting - [ "$VERBOSE" -gt 1 ] && echo -n "Uninstall $_pkg ..." + [ "$VERBOSE" -gt 2 ] && echo -n "Uninstall $_pkg ..." _cwd="${_pkgdir}/$_pkg" if [ ! -e "$_cwd/+CONTENTS" ] || @@ -275,7 +275,7 @@ fi done - [ "$VERBOSE" -gt 1 ] && echo " done." + [ "$VERBOSE" -gt 2 ] && echo " done." return 0 } @@ -286,13 +286,13 @@ } ALL=false -OPT_D= -while getopts :adDnp:v name +OPT_F= +while getopts :adFnp:v name do case "$name" in a) ALL=true ;; d) DELETE=true ;; - D) OPT_D=true ;; + F) OPT_F=true ;; n) DRYRUN=true ;; p) LOCALSRC="$OPTARG" ;; v) VERBOSE=$(( VERBOSE + 1 )) ;; @@ -321,7 +321,8 @@ fi # "Download only" means local dir and don't install -if [ "$OPT_D" ]; then +if [ "$OPT_F" ]; then + DOWNLOAD=true INSTALL=false LOCALSRC="${LOCALSRC:-.}" elif [ "$LOCALSRC" ]; then @@ -336,10 +337,10 @@ set -sA devices -- "$@" if "$DELETE"; then - [ "$OPT_D" ] && usage 22 + [ "$OPT_F" ] && usage 22 # Show the "Uninstalling" message when just deleting not upgrading - [ "$VERBOSE" -eq 1 ] && VEROBOSE=2 + [ "$VERBOSE" -gt 0 ] && VERBOSE=3 set -A installed if [ "${devices[*]:-}" ]; then @@ -387,8 +388,6 @@ REMOVE_LOCALSRC=true fi -CFILE="$LOCALSRC/$CFILE" - if [ "${devices[*]:-}" ]; then "$ALL" && usage 22 else @@ -400,18 +399,37 @@ [ "${devices[*]:-}" ] || exit -if "$DOWNLOAD"; then - set +o noclobber # we want to get the latest CFILE - fetch "$CFILE" - set -o noclobber - ! signify -qVep "$FWPUB_KEY" -x "$CFILE" -m "$CFILE" && - echo "Signature check of SHA256.sig failed" >&2 && exit 1 -elif [ ! -e "$CFILE" ]; then - # TODO: We shouldn't need a CFILE if all arguments are files. - echo "${0##*/}: $CFILE: No such file or directory" >&2 - exit 2 +# Only need the CFILE to verify what has been downloaded +# or to convert a device to a filename. +NEED_CFILE="${DOWNLOAD:-false}" +if ! "$NEED_CFILE"; then + for f in "${devices[@]}"; do + if [ "$( firmware_devicename "$f" )" = "$f" ]; then + NEED_CFILE=true + break + fi + done fi +# Only need to download if we already decided we did, +# or the same decision as if we NEED_CFILE. +DOWNLOAD="${DOWNLOAD:-$NEED_CFILE}" + +if "$NEED_CFILE"; then + CFILE="$LOCALSRC/$CFILE" + + if "$DOWNLOAD"; then + set +o noclobber # we want to get the latest CFILE + fetch "$CFILE" + set -o noclobber + ! signify -qVep "$FWPUB_KEY" -x "$CFILE" -m "$CFILE" && + echo "Signature check of SHA256.sig failed" >&2 && exit 1 + elif [ ! -e "$CFILE" ]; then + echo "${0##*/}: $CFILE: No such file or directory" >&2 + exit 2 + fi +fi + added='' updated='' kept='' @@ -441,7 +459,7 @@ if [ -e "$f" ]; then if "$DOWNLOAD"; then - [ "$VERBOSE" -gt 0 ] && ! "$INSTALL" && + [ "$VERBOSE" -gt 1 ] && ! "$INSTALL" && echo "Keep/Verify ${f##*/}" "$DRYRUN" || verify "$f" || continue "$INSTALL" || kept="$kept,$d" @@ -478,17 +496,21 @@ f="${f##*/}" f="${f%.tgz}" if [ "$update" ]; then - if [ "$VERBOSE" -gt 0 ] && "$DRYRUN"; then - echo "Update $f" + if [ "$VERBOSE" -eq 1 ] && "$DOWNLOAD" && ! "$DRYRUN"; then + echo " updated." elif [ "$VERBOSE" -eq 1 ]; then - echo " updated." + echo "Update $f" + elif [ "$VERBOSE" -gt 0 ] && "$DRYRUN"; then + echo "Update $f" fi updated="$updated,$d" else - if [ "$VERBOSE" -gt 0 ] && "$DRYRUN"; then - echo "Install $f" + if [ "$VERBOSE" -eq 1 ] && "$DOWNLOAD" && ! "$DRYRUN"; then + echo " installed." elif [ "$VERBOSE" -eq 1 ]; then - echo " installed." + echo "Install $f" + elif [ "$VERBOSE" -gt 0 ] && "$DRYRUN"; then + echo "Install $f" fi added="$added,$d" fi