=================================================================== RCS file: /cvs/openbsd/fw_update/fw_install.sh,v retrieving revision 1.69 retrieving revision 1.74 diff -u -r1.69 -r1.74 --- openbsd/fw_update/fw_install.sh 2021/12/11 05:08:38 1.69 +++ openbsd/fw_update/fw_install.sh 2021/12/11 20:57:51 1.74 @@ -1,5 +1,5 @@ #!/bin/ksh -# $OpenBSD: fw_install.sh,v 1.69 2021/12/11 05:08:38 afresh1 Exp $ +# $OpenBSD: fw_install.sh,v 1.74 2021/12/11 20:57:51 afresh1 Exp $ # # Copyright (c) 2021 Andrew Hewus Fresh # @@ -50,16 +50,6 @@ echo "$_dir" } -realpath () { - if [ -x /usr/bin/realpath ]; then - /usr/bin/realpath "$1" - elif [ "$1" = "${1%/*}" ]; then - echo "${PWD}/$1" - else - echo "$( cd "${1%/*}" && pwd )/${1##*/}" - fi -} - fetch() { local _src="${FWURL}/${1##*/}" _dst=$1 _user=_file _exit @@ -131,14 +121,15 @@ } add_firmware () { - local _f="${1##*/}" _pkgdir="${DESTDIR}/var/db/pkg" + local _f="${1##*/}" + local _pkgdir="${DESTDIR}/var/db/pkg/${_f%.tgz}" ftp -D "Install" -Vmo- "file:${1}" | - tar -s ",^\+,${_pkgdir}/${_f%.tgz}/+," \ + tar -s ",^\+,${_pkgdir}/+," \ -s ",^firmware,${DESTDIR}/etc/firmware," \ -C / -zxphf - "+*" "firmware/*" # TODO: Should we mark these so real fw_update can -Drepair? - ed -s "${_pkgdir}/${_f%.tgz}/+CONTENTS" <&2 - exit 2 - fi - devices[$i]="$d:$( realpath "$f" )" - fi - i=$((i + 1)) -done - -if "$DOWNLOAD" && ! [[ -e "$CFILE" ]]; then +if "$DOWNLOAD"; then fetch "$CFILE" ! signify -qVep "$FWPUB_KEY" -x "$CFILE" -m "$CFILE" && echo "Signature check of SHA256.sig failed" >&2 && exit 1 fi -for d in "${devices[@]}"; do - f="${d##*:}" +for f in "${devices[@]}"; do + d="$( firmware_devicename "$f" )" + if [ "$f" = "$d" ]; then f=$( firmware_filename "$d" || true ) [ "$f" ] || continue f="$LOCALSRC/$f" - else - d="${d%:*}" + elif ! "$INSTALL" && ! grep -q "($f)" "$CFILE" ; then + echo "Cannot download local file $f" >&2 + exit 2 fi set -A installed -- $( installed_firmware "$d" ) @@ -258,13 +235,17 @@ done fi - if [ ! -e "$f" ]; then - "$INSTALL" && ! "$DOWNLOAD" && - echo "Cannot install ${f##*/}, not found" >&2 && continue + if [ -e "$f" ]; then + if "$DOWNLOAD"; then + echo "Verify existing ${f##*/}" + verify "$f" || continue + # else assume it was verified when downloaded + fi + elif "$INSTALL" && ! "$DOWNLOAD"; then + echo "Cannot install ${f##*/}, not found" >&2 + continue + else fetch "$f" || continue - verify "$f" || continue - elif $DOWNLOAD; then - echo "Already have $f" verify "$f" || continue fi