=================================================================== RCS file: /cvs/openbsd/fw_update/fw_install.sh,v retrieving revision 1.110 retrieving revision 1.111 diff -u -r1.110 -r1.111 --- openbsd/fw_update/fw_install.sh 2021/12/23 19:48:55 1.110 +++ openbsd/fw_update/fw_install.sh 2021/12/23 20:25:40 1.111 @@ -1,5 +1,5 @@ #!/bin/ksh -# $OpenBSD: fw_install.sh,v 1.110 2021/12/23 19:48:55 afresh1 Exp $ +# $OpenBSD: fw_install.sh,v 1.111 2021/12/23 20:25:40 afresh1 Exp $ # # Copyright (c) 2021 Andrew Hewus Fresh # @@ -35,6 +35,7 @@ FWPUB_KEY=${DESTDIR}/etc/signify/openbsd-${VERSION}-fw.pub VERBOSE=false +DELETE=false DOWNLOAD=true INSTALL=true LOCALSRC= @@ -240,15 +241,16 @@ } usage() { - echo "usage: ${0##*/} [-D | -L] [-v] [driver | file ...]" + echo "usage: ${0##*/} [-d | -D | -L] [-v] [driver | file ...]" exit 2 } OPT_D= OPT_L= -while getopts :DLv name +while getopts :dDLv name do case "$name" in + d) DELETE=true ;; D) OPT_D=true ;; L) OPT_L=true ;; v) VERBOSE=true ;; @@ -273,12 +275,43 @@ CFILE="$LOCALSRC/$CFILE" -if "$INSTALL" && [ -x /usr/bin/id ] && [ "$(/usr/bin/id -u)" != 0 ]; then - echo "need root privileges" >&2 - exit 1 +if "$INSTALL" || "$DELETE"; then + if [ -x /usr/bin/id ] && [ "$(/usr/bin/id -u)" != 0 ]; then + echo "need root privileges" >&2 + exit 1 + fi fi set -A devices -- "$@" + +if "$DELETE"; then + [ "$OPT_D" ] || [ "$OPT_L" ] && usage 22 + + [ "${devices[*]:-}" ] || usage 22 + + deleted='' + for d in "${devices[@]}"; do + f="${d##*/}" # don't just uninstall from anywhere + f="${f%.tgz}" # allow specifying the package name + + set -A installed -- $( installed_firmware '' "$f" '*' ) + + if [ ! "${installed[*]:-}" ]; then + echo "No firmware found for '$d'" >&2 + continue + fi + + for fw in "${installed[@]}"; do + delete_firmware "$fw" || continue + deleted="$deleted,$fw" + done + done + + deleted="${deleted:+${deleted#,}}" + echo "${0:##*/}: deleted ${deleted:-none}"; + + exit +fi if [ ! "${devices[*]:-}" ]; then "$VERBOSE" && echo -n "Detecting firmware ..."