=================================================================== RCS file: /cvs/openbsd/fw_update/fw_install.sh,v retrieving revision 1.22 retrieving revision 1.37 diff -u -r1.22 -r1.37 --- openbsd/fw_update/fw_install.sh 2021/11/11 02:05:56 1.22 +++ openbsd/fw_update/fw_install.sh 2021/12/01 02:04:18 1.37 @@ -1,16 +1,11 @@ #!/bin/ksh +# $OpenBSD: fw_install.sh,v 1.37 2021/12/01 02:04:18 afresh1 Exp $ set -e -scan_dmesg() { - # no bsort for now - sed -n "$1" /var/run/dmesg.boot -} - +# Fake up some things from install.sub that we don't need to actually do prefetcharea_fs_list() { - echo "/mnt/tmp" + echo "${DESTDIR}/tmp" } -reset_watchdog() { -} # tmpdir, do_as, unpriv, and unpriv2 are from install.sub @@ -69,17 +64,11 @@ do_as _file "$@" } -# "fail" needs to be replaced with the "ask_yn" loop like in the installer. -_issue= -fail() { - echo $_issue >&2 - exit 1 -} +VNAME=${VNAME:-$(sysctl -n kern.osrelease)} +VERSION=${VERSION:-"${VNAME%.*}${VNAME#*.}"} +FWDIR=${FWDIR:-$VNAME} +MODE=${MODE:-install} -VNAME=$(sysctl -n kern.osrelease) -VERSION="${VNAME%.*}${VNAME#*.}" -FWDIR="$VNAME" - # TODO: We need the firmware for the system we just installed # not the one we booted from. For example: # * booting from a snapshot bsd.rd that thinks it is the 7.0 release @@ -91,22 +80,23 @@ # Otherwise, the fw_update after first boot will fix it up for us. HTTP_FWDIR=$FWDIR -set -- $(scan_dmesg "/^OpenBSD $VNAME\([^ ]*\).*$/s//\1/p") +set -- sed -n "/^OpenBSD $VNAME\([^ ]*\).*$/s//\1/p" /var/run/dmesg.boot [[ $1 == -!(stable) ]] && HTTP_FWDIR=snapshots FWURL=http://firmware.openbsd.org/firmware/${HTTP_FWDIR} FWPUB_KEY=${DESTDIR}/etc/signify/openbsd-${VERSION}-fw.pub -FWPATTERNS="file:${0%/*}/firmware_patterns" +FWPATTERNS="${DESTDIR}/usr/share/misc/firmware_patterns" # TODO: support srclocal installation of firmware somehow -fw_update() { - local _src=$FWURL _tmpfs_list _tmpfs _tmpsrc - local _t=Get _cfile="/tmp/SHA256" _srclocal=false - local _f _r _remove _i _installed - local _pkgdir=/mnt/var/db/pkg +fw_install() { + local _src=$1 _tmpfs_list _tmpfs _tmpsrc \ + _t=Get _cfile="/tmp/SHA256" _pkgdir=${DESTDIR}/var/db/pkg \ + _f _r _remove _i _installed + local _srclocal=false _unpriv=unpriv + + echo "Let's $MODE firmware!" local _d _drivers=$( last='' - ftp -D "Detecting" -Vmo- $FWPATTERNS | while read _d _m; do grep=grep [ "$last" = "$_d" ] && continue @@ -115,7 +105,7 @@ $grep -q "$_m" /var/run/dmesg.boot || continue echo $_d last=$_d - done + done < $FWPATTERNS ) if [ -z "$_drivers" ]; then @@ -158,12 +148,11 @@ echo "Cannot fetch SHA256.sig" >&2 && return 1 # Verify signature file with public keys. - ! unpriv -f "$_cfile" \ + ! $_unpriv -f "$_cfile" \ signify -Vep $FWPUB_KEY -x "$_cfile.sig" -m "$_cfile" && echo "Signature check of SHA256.sig failed" >&2 && return 1 for _d in $_drivers; do - $UU && reset_watchdog _f=$( sed -n "s/.*(\($_d-firmware-.*\.tgz\)).*/\1/p" "$_cfile" ) _installed=$( for fw in "${_pkgdir}/$_d-firmware"*; do @@ -174,7 +163,7 @@ for _i in $_installed; do if [ "$_f" = "$_i.tgz" ]; then - echo "Firmware for $_d already installed ($_installed)" + echo "$_i already installed" continue 2 fi done @@ -211,7 +200,7 @@ while read c g; do case $c in - @cwd) cwd="/mnt/$g" + @cwd) cwd="${DESTDIR}/$g" ;; @*) continue ;; @@ -234,10 +223,11 @@ fi # TODO: Should we mark these so real fw_update can -Drepair? - echo "Installing $_f" - tar -zxphf "$_tmpsrc/$_f" -C "/mnt/etc" "firmware/*" - mkdir -p ${_pkgdir}/${_f%.tgz}/ - tar -zxphf "$_tmpsrc/$_f" -C "${_pkgdir}/${_f%.tgz}" "+*" + ftp -D "Install" -Vmo- "file:$_tmpsrc/$_f" | + tar -s ",^\+,${_pkgdir}/${_f%.tgz}/+," \ + -s ",^firmware,${DESTDIR}/etc/firmware," \ + -C / -zxphf - "+*" "firmware/*" + ed -s "${_pkgdir}/${_f%.tgz}/+CONTENTS" <