=================================================================== RCS file: /cvs/openbsd/fw_update/fw_install.sh,v retrieving revision 1.99 retrieving revision 1.105 diff -u -r1.99 -r1.105 --- openbsd/fw_update/fw_install.sh 2021/12/22 04:10:22 1.99 +++ openbsd/fw_update/fw_install.sh 2021/12/22 17:53:53 1.105 @@ -1,5 +1,5 @@ #!/bin/ksh -# $OpenBSD: fw_install.sh,v 1.99 2021/12/22 04:10:22 afresh1 Exp $ +# $OpenBSD: fw_install.sh,v 1.105 2021/12/22 17:53:53 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 @@ -160,7 +162,9 @@ add_firmware () { local _f="${1##*/}" local _pkgdir="${DESTDIR}/var/db/pkg/${_f%.tgz}" - ftp -D "Install" -Vmo- "file:${1}" | + local flags=-VM + "$VERBOSE" && flags=-vm + ftp -D "Install" "$flags" -o- "file:${1}" | tar -s ",^\+,${_pkgdir}/+," \ -s ",^firmware,${DESTDIR}/etc/firmware," \ -C / -zxphf - "+*" "firmware/*" @@ -180,7 +184,7 @@ local _cwd _pkg="$1" _pkgdir="${DESTDIR}/var/db/pkg" # TODO: Check hash for files before deleting - echo "Uninstalling $_pkg" + "$VERBOSE" && echo "Uninstalling $_pkg" _cwd="${_pkgdir}/$_pkg" set -A _remove -- "${_cwd}/+CONTENTS" "${_cwd}" @@ -212,13 +216,13 @@ } usage() { - echo "usage: ${0##*/} [-D | -L] [driver | file ...]" + echo "usage: ${0##*/} [-v] [-D | -L] [driver | file ...]" exit 2 } OPT_D= OPT_L= -while getopts :DL name +while getopts :DLv name do case "$name" in D) OPT_D=true ;; @@ -240,12 +244,12 @@ DOWNLOAD=false LOCALSRC=. else - LOCALSRC="$( tmpdir "${DESTDIR}/tmp/fw_install" )" + LOCALSRC="$( tmpdir "${DESTDIR}/tmp/${0##*/}" )" fi CFILE="$LOCALSRC/$CFILE" -if "$INSTALL" && [ -x /usr/bin/id ] && [ $(/usr/bin/id -u) != 0 ]; then +if "$INSTALL" && [ -x /usr/bin/id ] && [ "$(/usr/bin/id -u)" != 0 ]; then echo "need root privileges" >&2 exit 1 fi @@ -253,9 +257,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 +271,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 +290,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 +298,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 +312,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