=================================================================== RCS file: /cvs/openbsd/fw_update/fw_install.sh,v retrieving revision 1.95 retrieving revision 1.101 diff -u -r1.95 -r1.101 --- openbsd/fw_update/fw_install.sh 2021/12/21 02:16:47 1.95 +++ openbsd/fw_update/fw_install.sh 2021/12/22 04:30:07 1.101 @@ -1,5 +1,5 @@ #!/bin/ksh -# $OpenBSD: fw_install.sh,v 1.95 2021/12/21 02:16:47 afresh1 Exp $ +# $OpenBSD: fw_install.sh,v 1.101 2021/12/22 04:30:07 afresh1 Exp $ # # Copyright (c) 2021 Andrew Hewus Fresh # @@ -34,6 +34,7 @@ FWURL=http://firmware.openbsd.org/firmware/${HTTP_FWDIR} FWPUB_KEY=${DESTDIR}/etc/signify/openbsd-${VERSION}-fw.pub +VERBOSE=false DOWNLOAD=true INSTALL=true LOCALSRC= @@ -61,17 +62,19 @@ # 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 - trap "kill -TERM '-$_pid'; exit 1" EXIT INT QUIT ABRT TERM + trap "kill -TERM '-$_pid' 2>/dev/null; exit 1" EXIT INT QUIT ABRT TERM SECONDS=0 _last=0 @@ -150,7 +153,7 @@ installed_firmware() { set +o noglob for fw in "${DESTDIR}/var/db/pkg/$1-firmware"*; do - [ -e "$fw" ] || continue + [ -e "$fw/+CONTENTS" ] || continue echo "${fw##*/}" done set -o noglob @@ -159,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/*" @@ -179,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}" @@ -217,12 +222,13 @@ OPT_D= OPT_L= -while getopts DL name +while getopts :DLv name do case "$name" in D) OPT_D=true ;; L) OPT_L=true ;; - ?) usage 2 ;; + v) VERBOSE=true ;; + ?) echo "${0##*/}: unknown option -- -$OPTARG"; usage 2 ;; esac done shift $((OPTIND - 1)) @@ -251,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 @@ -281,7 +288,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 @@ -289,7 +296,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