=================================================================== RCS file: /cvs/openbsd/fw_update/fw_install.sh,v retrieving revision 1.100 retrieving revision 1.106 diff -u -r1.100 -r1.106 --- openbsd/fw_update/fw_install.sh 2021/12/22 04:29:18 1.100 +++ openbsd/fw_update/fw_install.sh 2021/12/23 01:25:29 1.106 @@ -1,5 +1,5 @@ #!/bin/ksh -# $OpenBSD: fw_install.sh,v 1.100 2021/12/22 04:29:18 afresh1 Exp $ +# $OpenBSD: fw_install.sh,v 1.106 2021/12/23 01:25:29 afresh1 Exp $ # # Copyright (c) 2021 Andrew Hewus Fresh # @@ -62,12 +62,14 @@ # we have su(1) and doas(1) is unlikely to be configured. set -o monitor # make sure ftp gets its own process group ( + flags=-VM + "$VERBOSE" && flags=-vm if [ -x /usr/bin/su ]; then exec /usr/bin/su -s /bin/ksh "$_user" -c \ - "/usr/bin/ftp -D 'Get/Verify' -Vm -o- '$_src'" > "$_dst" + "/usr/bin/ftp -D 'Get/Verify' $flags -o- '$_src'" > "$_dst" else exec /usr/bin/doas -u "$_user" \ - /usr/bin/ftp -D 'Get/Verify' -Vm -o- "$_src" > "$_dst" + /usr/bin/ftp -D 'Get/Verify' $flags -o- "$_src" > "$_dst" fi ) & _pid=$! set +o monitor @@ -158,15 +160,24 @@ } add_firmware () { - local _f="${1##*/}" - local _pkgdir="${DESTDIR}/var/db/pkg/${_f%.tgz}" - ftp -D "Install" -Vmo- "file:${1}" | - tar -s ",^\+,${_pkgdir}/+," \ + local _f="${1##*/}" _pkgname + local _tmpdir="$( tmpdir "${DESTDIR}/var/db/pkg/.firmware" )" + local flags=-VM + "$VERBOSE" && flags=-vm + ftp -D "Install" "$flags" -o- "file:${1}" | + tar -s ",^\+,${_tmpdir}/+," \ -s ",^firmware,${DESTDIR}/etc/firmware," \ -C / -zxphf - "+*" "firmware/*" + _pkgname="$( sed -n '/^@name /{s///p;q;}' "${_tmpdir}/+CONTENTS" )" + if [ ! "$_pkgname" ]; then + echo "Failed to extract name from $1, partial install" 2>&1 + rm -rf "$_tmpdir" + return 1 + fi + # TODO: Should we mark these so real fw_update can -Drepair? - ed -s "${_pkgdir}/+CONTENTS" <&2 exit 1 fi @@ -253,9 +267,10 @@ set -A devices -- "$@" if [ ! "${devices[*]:-}" ]; then - echo -n "Detecting firmware ..." + "$VERBOSE" && echo -n "Detecting firmware ..." set -A devices -- $( devices_needing_firmware ) - [ "${devices[*]:-}" ] && echo " found." || echo " done." + "$VERBOSE" && + { [ "${devices[*]:-}" ] && echo " found." || echo " done." ; } fi [ "${devices[*]:-}" ] || exit @@ -266,6 +281,8 @@ echo "Signature check of SHA256.sig failed" >&2 && exit 1 fi +added='' +updated='' for f in "${devices[@]}"; do d="$( firmware_devicename "$f" )" @@ -283,7 +300,7 @@ if "$INSTALL" && [ "${installed[*]:-}" ]; then for i in "${installed[@]}"; do if [ "${f##*/}" = "$i.tgz" ]; then - echo "$i already installed" + "$VERBOSE" && echo "$i already installed" continue 2 fi done @@ -291,7 +308,7 @@ if [ -e "$f" ]; then if "$DOWNLOAD"; then - echo "Verify existing ${f##*/}" + "$VERBOSE" && echo "Verify existing ${f##*/}" verify "$f" || continue # else assume it was verified when downloaded fi @@ -305,12 +322,29 @@ "$INSTALL" || continue + removed=false if [ "${installed[*]:-}" ]; then for i in "${installed[@]}"; do delete_firmware "$i" + removed=true done fi add_firmware "$f" + + if "$removed"; then + [ "$updated" ] && updated="$updated," + updated="$updated$d" + else + [ "$added" ] && added="$added," + added="$added$d" + fi done +if ! $VERBOSE && { [ "$added" ] || [ "$updated" ]; }; then + echo "${0##*/}: $( + [ "$added" ] && echo -n "added ${added}" + [ "$added" ] && [ "$updated" ] && echo -n "; " + [ "$updated" ] && echo -n "updated ${updated}" + )" +fi