=================================================================== RCS file: /cvs/openbsd/fw_update/fw_install.sh,v retrieving revision 1.138 retrieving revision 1.142 diff -u -r1.138 -r1.142 --- openbsd/fw_update/fw_install.sh 2021/12/26 18:58:54 1.138 +++ openbsd/fw_update/fw_install.sh 2022/01/07 00:38:06 1.142 @@ -1,5 +1,5 @@ #!/bin/ksh -# $OpenBSD: fw_install.sh,v 1.138 2021/12/26 18:58:54 afresh1 Exp $ +# $OpenBSD: fw_install.sh,v 1.142 2022/01/07 00:38:06 afresh1 Exp $ # # Copyright (c) 2021 Andrew Hewus Fresh # @@ -199,7 +199,7 @@ } add_firmware () { - local _f="${1##*/}" _pkgname + local _f="${1##*/}" _m="${2:-Install}" _pkgname FWPKGTMP="$( tmpdir "${DESTDIR}/var/db/pkg/.firmware" )" local _flags=-vm case "$VERBOSE" in @@ -207,9 +207,7 @@ 2|3) _flags=-Vm ;; esac - [ "$VERBOSE" -eq 1 ] && echo -n "Install ${_f} ..." - - ftp -N "${0##/}" -D "Install" "$_flags" -o- "file:${1}" | + ftp -N "${0##/}" -D "$_m" "$_flags" -o- "file:${1}" | tar -s ",^\+,${FWPKGTMP}/+," \ -s ",^firmware,${DESTDIR}/etc/firmware," \ -C / -zxphf - "+*" "firmware/*" @@ -235,15 +233,13 @@ chmod 755 "$FWPKGTMP" mv "$FWPKGTMP" "${DESTDIR}/var/db/pkg/${_pkgname}" unset FWPKGTMP - - [ "$VERBOSE" -eq 1 ] && echo " done." } delete_firmware() { local _cwd _pkg="$1" _pkgdir="${DESTDIR}/var/db/pkg" # TODO: Check hash for files before deleting - [ "$VERBOSE" -gt 0 ] && echo -n "Uninstall $_pkg ..." + [ "$VERBOSE" -gt 2 ] && echo -n "Uninstall $_pkg ..." _cwd="${_pkgdir}/$_pkg" if [ ! -e "$_cwd/+CONTENTS" ] || @@ -279,7 +275,9 @@ fi done - [ "$VERBOSE" -gt 0 ] && echo " done." + [ "$VERBOSE" -gt 2 ] && echo " done." + + return 0 } usage() { @@ -288,13 +286,13 @@ } ALL=false -OPT_D= -while getopts :adDnp:v name +OPT_F= +while getopts :adFnp:v name do case "$name" in a) ALL=true ;; d) DELETE=true ;; - D) OPT_D=true ;; + F) OPT_F=true ;; n) DRYRUN=true ;; p) LOCALSRC="$OPTARG" ;; v) VERBOSE=$(( VERBOSE + 1 )) ;; @@ -323,7 +321,7 @@ fi # "Download only" means local dir and don't install -if [ "$OPT_D" ]; then +if [ "$OPT_F" ]; then INSTALL=false LOCALSRC="${LOCALSRC:-.}" elif [ "$LOCALSRC" ]; then @@ -338,8 +336,11 @@ set -sA devices -- "$@" if "$DELETE"; then - [ "$OPT_D" ] && usage 22 + [ "$OPT_F" ] && usage 22 + # Show the "Uninstalling" message when just deleting not upgrading + [ "$VERBOSE" -gt 0 ] && VERBOSE=3 + set -A installed if [ "${devices[*]:-}" ]; then "$ALL" && usage 22 @@ -375,7 +376,7 @@ done fi - deleted="${deleted:+${deleted#,}}" + deleted="${deleted#,}" echo "${0:##*/}: deleted ${deleted:-none}"; exit @@ -391,9 +392,9 @@ if [ "${devices[*]:-}" ]; then "$ALL" && usage 22 else - [ "$VERBOSE" -gt 0 ] && echo -n "Detect firmware ..." + [ "$VERBOSE" -gt 1 ] && echo -n "Detect firmware ..." set -sA devices -- $( detect_firmware ) - [ "$VERBOSE" -gt 0 ] && + [ "$VERBOSE" -gt 1 ] && { [ "${devices[*]:-}" ] && echo " found." || echo " done." ; } fi @@ -431,7 +432,7 @@ if "$INSTALL" && [ "${installed[*]:-}" ]; then for i in "${installed[@]}"; do if [ "${f##*/}" = "$i.tgz" ]; then - [ "$VERBOSE" -gt 0 ] && echo "Keep $i" + [ "$VERBOSE" -gt 2 ] && echo "Keep $i" kept="$kept,$d" continue 2 fi @@ -440,7 +441,7 @@ if [ -e "$f" ]; then if "$DOWNLOAD"; then - [ "$VERBOSE" -gt 0 ] && ! "$INSTALL" && + [ "$VERBOSE" -gt 1 ] && ! "$INSTALL" && echo "Keep/Verify ${f##*/}" "$DRYRUN" || verify "$f" || continue "$INSTALL" || kept="$kept,$d" @@ -454,7 +455,7 @@ fetch "$f" && verify "$f" || { [ "$VERBOSE" -eq 1 ] && echo " failed."; continue; } - [ "$VERBOSE" -eq 1 ] && echo " done." + [ "$VERBOSE" -eq 1 ] && ! "$INSTALL" && echo " done." fi "$INSTALL" || added="$added,$d" elif "$INSTALL"; then @@ -464,23 +465,35 @@ "$INSTALL" || continue - removed=false + update='' if [ "${installed[*]:-}" ]; then for i in "${installed[@]}"; do "$DRYRUN" || delete_firmware "$i" - removed=true + update="Update" done fi - "$DRYRUN" || add_firmware "$f" + "$DRYRUN" || add_firmware "$f" "$update" f="${f##*/}" f="${f%.tgz}" - if "$removed"; then - "$DRYRUN" && [ "$VERBOSE" -gt 0 ] && echo "Update $f" + if [ "$update" ]; then + if [ "$VERBOSE" -eq 1 ] && "$DOWNLOAD" && ! "$DRYRUN"; then + echo " updated." + elif [ "$VERBOSE" -eq 1 ]; then + echo "Update $f" + elif [ "$VERBOSE" -gt 0 ] && "$DRYRUN"; then + echo "Update $f" + fi updated="$updated,$d" else - "$DRYRUN" && [ "$VERBOSE" -gt 0 ] && echo "Install $f" + if [ "$VERBOSE" -eq 1 ] && "$DOWNLOAD" && ! "$DRYRUN"; then + echo " installed." + elif [ "$VERBOSE" -eq 1 ]; then + echo "Install $f" + elif [ "$VERBOSE" -gt 0 ] && "$DRYRUN"; then + echo "Install $f" + fi added="$added,$d" fi done