=================================================================== RCS file: /cvs/openbsd/fw_update/fw_install.sh,v retrieving revision 1.127 retrieving revision 1.138 diff -u -r1.127 -r1.138 --- openbsd/fw_update/fw_install.sh 2021/12/25 02:38:33 1.127 +++ openbsd/fw_update/fw_install.sh 2021/12/26 18:58:54 1.138 @@ -1,5 +1,5 @@ #!/bin/ksh -# $OpenBSD: fw_install.sh,v 1.127 2021/12/25 02:38:33 afresh1 Exp $ +# $OpenBSD: fw_install.sh,v 1.138 2021/12/26 18:58:54 afresh1 Exp $ # # Copyright (c) 2021 Andrew Hewus Fresh # @@ -34,17 +34,20 @@ FWURL=http://firmware.openbsd.org/firmware/${HTTP_FWDIR} FWPUB_KEY=${DESTDIR}/etc/signify/openbsd-${VERSION}-fw.pub -VERBOSE=false +DRYRUN=false +VERBOSE=0 DELETE=false DOWNLOAD=true INSTALL=true LOCALSRC= unset FTPPID +unset FWPKGTMP REMOVE_LOCALSRC=false cleanup() { set +o errexit # ignore errors from killing ftp - [ "${FTPPID:-}" ] && kill -TERM -"$FTPPID" #2>/dev/null + [ "${FTPPID:-}" ] && kill -TERM -"$FTPPID" 2>/dev/null + [ "${FWPKGTMP:-}" ] && rm -rf "$FWPKGTMP" "$REMOVE_LOCALSRC" && rm -rf "$LOCALSRC" } trap cleanup EXIT @@ -72,14 +75,17 @@ # 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 + _flags=-vm + case "$VERBOSE" in + 0|1) _flags=-VM ;; + 2) _flags=-Vm ;; + esac if [ -x /usr/bin/su ]; then exec /usr/bin/su -s /bin/ksh "$_user" -c \ - "/usr/bin/ftp -N '${0##/}' -D 'Get/Verify' $flags -o- '$_src'" > "$_dst" + "/usr/bin/ftp -N '${0##/}' -D 'Get/Verify' $_flags -o- '$_src'" > "$_dst" else exec /usr/bin/doas -u "$_user" \ - /usr/bin/ftp -N "${0##/}" -D 'Get/Verify' $flags -o- "$_src" > "$_dst" + /usr/bin/ftp -N "${0##/}" -D 'Get/Verify' $_flags -o- "$_src" > "$_dst" fi ) & FTPPID=$! set +o monitor @@ -94,7 +100,7 @@ SECONDS=0 sleep 1 else - kill -INT -"$FTPPID" + kill -INT -"$FTPPID" 2>/dev/null _error=" (timed out)" fi else @@ -129,8 +135,7 @@ # When we're not in the installer, the dmesg.boot can # contain multiple boots, so only look in the last one - _dmesgtail="$( echo ; sed -n 'H;/^OpenBSD/h;${g;p;}' /var/run/dmesg.boot | - grep -e "^[a-z][a-z]*[0-9]" -e " not configured " )" + _dmesgtail="$( echo ; sed -n 'H;/^OpenBSD/h;${g;p;}' /var/run/dmesg.boot )" grep -v '^[[:space:]]*#' "$FWPATTERNS" | while read -r _d _m; do @@ -181,37 +186,44 @@ set -sA _devices -- $( firmware_in_dmesg for _d in $( installed_firmware '*' '-firmware-' '*' ); do - echo "$( firmware_devicename "$_d" )" + firmware_devicename "$_d" done ) [ "${_devices[*]:-}" ] || return 0 for _d in "${_devices[@]}"; do - [[ $_last = $_d ]] && continue - echo $_d + [ "$_last" = "$_d" ] && continue + echo "$_d" _last="$_d" done } add_firmware () { local _f="${1##*/}" _pkgname - local _tmpdir="$( tmpdir "${DESTDIR}/var/db/pkg/.firmware" )" - local flags=-VM - "$VERBOSE" && flags=-vm - ftp -N "${0##/}" -D "Install" "$flags" -o- "file:${1}" | - tar -s ",^\+,${_tmpdir}/+," \ + FWPKGTMP="$( tmpdir "${DESTDIR}/var/db/pkg/.firmware" )" + local _flags=-vm + case "$VERBOSE" in + 0|1) _flags=-VM ;; + 2|3) _flags=-Vm ;; + esac + + [ "$VERBOSE" -eq 1 ] && echo -n "Install ${_f} ..." + + ftp -N "${0##/}" -D "Install" "$_flags" -o- "file:${1}" | + tar -s ",^\+,${FWPKGTMP}/+," \ -s ",^firmware,${DESTDIR}/etc/firmware," \ -C / -zxphf - "+*" "firmware/*" - _pkgname="$( sed -n '/^@name /{s///p;q;}' "${_tmpdir}/+CONTENTS" )" + _pkgname="$( sed -n '/^@name /{s///p;q;}' "${FWPKGTMP}/+CONTENTS" )" if [ ! "$_pkgname" ]; then echo "Failed to extract name from $1, partial install" 2>&1 - rm -rf "$_tmpdir" + rm -rf "$FWPKGTMP" + unset FWPKGTMP return 1 fi # TODO: Should we mark these so real fw_update can -Drepair? - ed -s "${_tmpdir}/+CONTENTS" <&2 usage 2 @@ -308,6 +326,8 @@ if [ "$OPT_D" ]; then INSTALL=false LOCALSRC="${LOCALSRC:-.}" +elif [ "$LOCALSRC" ]; then + DOWNLOAD=false fi if [ -x /usr/bin/id ] && [ "$(/usr/bin/id -u)" != 0 ]; then @@ -346,7 +366,11 @@ deleted='' if [ "${installed:-}" ]; then for fw in "${installed[@]}"; do - delete_firmware "$fw" || continue + if "$DRYRUN"; then + [ "$VERBOSE" -gt 0 ] && echo "Delete $fw" + else + delete_firmware "$fw" || continue + fi deleted="$deleted,$( firmware_devicename "$fw" )" done fi @@ -367,9 +391,9 @@ if [ "${devices[*]:-}" ]; then "$ALL" && usage 22 else - "$VERBOSE" && echo -n "Detecting firmware ..." + [ "$VERBOSE" -gt 0 ] && echo -n "Detect firmware ..." set -sA devices -- $( detect_firmware ) - "$VERBOSE" && + [ "$VERBOSE" -gt 0 ] && { [ "${devices[*]:-}" ] && echo " found." || echo " done." ; } fi @@ -407,7 +431,7 @@ if "$INSTALL" && [ "${installed[*]:-}" ]; then for i in "${installed[@]}"; do if [ "${f##*/}" = "$i.tgz" ]; then - "$VERBOSE" && echo "$i already installed" + [ "$VERBOSE" -gt 0 ] && echo "Keep $i" kept="$kept,$d" continue 2 fi @@ -416,15 +440,23 @@ if [ -e "$f" ]; then if "$DOWNLOAD"; then - "$VERBOSE" && echo "Verify existing ${f##*/}" - verify "$f" || continue - "$INSTALL" || kept="$kept,$d" + [ "$VERBOSE" -gt 0 ] && ! "$INSTALL" && + echo "Keep/Verify ${f##*/}" + "$DRYRUN" || verify "$f" || continue + "$INSTALL" || kept="$kept,$d" # else assume it was verified when downloaded fi elif "$DOWNLOAD"; then - fetch "$f" || continue - verify "$f" || continue - "$INSTALL" || added="$added,$d" + if "$DRYRUN"; then + [ "$VERBOSE" -gt 0 ] && echo "Get/Verify ${f##*/}" + else + [ "$VERBOSE" -eq 1 ] && echo -n "Get/Verify ${f##*/} ..." + fetch "$f" && + verify "$f" || + { [ "$VERBOSE" -eq 1 ] && echo " failed."; continue; } + [ "$VERBOSE" -eq 1 ] && echo " done." + fi + "$INSTALL" || added="$added,$d" elif "$INSTALL"; then echo "Cannot install ${f##*/}, not found" >&2 continue @@ -435,16 +467,20 @@ removed=false if [ "${installed[*]:-}" ]; then for i in "${installed[@]}"; do - delete_firmware "$i" + "$DRYRUN" || delete_firmware "$i" removed=true done fi - add_firmware "$f" + "$DRYRUN" || add_firmware "$f" + f="${f##*/}" + f="${f%.tgz}" if "$removed"; then + "$DRYRUN" && [ "$VERBOSE" -gt 0 ] && echo "Update $f" updated="$updated,$d" else + "$DRYRUN" && [ "$VERBOSE" -gt 0 ] && echo "Install $f" added="$added,$d" fi done