version 1.25, 2021/11/11 02:38:32 |
version 1.41, 2021/12/01 02:30:43 |
|
|
#!/bin/ksh |
#!/bin/ksh |
|
# $OpenBSD$ |
set -e |
set -e |
|
|
scan_dmesg() { |
# Copyright (c) 2021 Andrew Hewus Fresh <afresh1@openbsd.org> |
# no bsort for now |
# |
sed -n "$1" /var/run/dmesg.boot |
# Permission to use, copy, modify, and distribute this software for any |
} |
# purpose with or without fee is hereby granted, provided that the above |
|
# copyright notice and this permission notice appear in all copies. |
|
# |
|
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
|
# Fake up some things from install.sub that we don't need to actually do |
# Fake up some things from install.sub that we don't need to actually do |
prefetcharea_fs_list() { |
prefetcharea_fs_list() { |
echo "/mnt/tmp" |
echo "${DESTDIR}/tmp" |
} |
} |
reset_watchdog() { |
|
} |
|
|
|
# tmpdir, do_as, unpriv, and unpriv2 are from install.sub |
# tmpdir, do_as, unpriv, and unpriv2 are from install.sub |
|
|
|
|
do_as _file "$@" |
do_as _file "$@" |
} |
} |
|
|
# "fail" needs to be replaced with the "ask_yn" loop like in the installer. |
VNAME=${VNAME:-$(sysctl -n kern.osrelease)} |
_issue= |
VERSION=${VERSION:-"${VNAME%.*}${VNAME#*.}"} |
fail() { |
FWDIR=${FWDIR:-$VNAME} |
echo $_issue >&2 |
|
exit 1 |
|
} |
|
|
|
VNAME=$(sysctl -n kern.osrelease) |
|
VERSION="${VNAME%.*}${VNAME#*.}" |
|
FWDIR="$VNAME" |
|
|
|
# TODO: We need the firmware for the system we just installed |
# TODO: We need the firmware for the system we just installed |
# not the one we booted from. For example: |
# not the one we booted from. For example: |
# * booting from a snapshot bsd.rd that thinks it is the 7.0 release |
# * booting from a snapshot bsd.rd that thinks it is the 7.0 release |
|
|
# Otherwise, the fw_update after first boot will fix it up for us. |
# Otherwise, the fw_update after first boot will fix it up for us. |
|
|
HTTP_FWDIR=$FWDIR |
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 |
[[ $1 == -!(stable) ]] && HTTP_FWDIR=snapshots |
|
|
FWURL=http://firmware.openbsd.org/firmware/${HTTP_FWDIR} |
FWURL=http://firmware.openbsd.org/firmware/${HTTP_FWDIR} |
FWPUB_KEY=${DESTDIR}/etc/signify/openbsd-${VERSION}-fw.pub |
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 |
# TODO: support srclocal installation of firmware somehow |
fw_update() { |
fw_install() { |
local _src=$1 _tmpfs_list _tmpfs _tmpsrc \ |
local _src=$1 _tmpfs_list _tmpfs _tmpsrc \ |
_t=Get _cfile="/tmp/SHA256" _pkgdir=/mnt/var/db/pkg \ |
_t=Get _cfile="/tmp/SHA256" _pkgdir=${DESTDIR}/var/db/pkg \ |
_f _r _remove _i _installed |
_f _r _remove _i _installed |
local _srclocal=false _unpriv=unpriv |
local _srclocal=false _unpriv=unpriv |
|
|
local _d _drivers=$( |
local _d _drivers=$( |
last='' |
last='' |
$_unpriv ftp -D "Detecting" -Vmo- $FWPATTERNS | |
|
while read _d _m; do |
while read _d _m; do |
grep=grep |
grep=grep |
[ "$last" = "$_d" ] && continue |
[ "$last" = "$_d" ] && continue |
|
|
$grep -q "$_m" /var/run/dmesg.boot || continue |
$grep -q "$_m" /var/run/dmesg.boot || continue |
echo $_d |
echo $_d |
last=$_d |
last=$_d |
done |
done < $FWPATTERNS |
) |
) |
|
|
if [ -z "$_drivers" ]; then |
if [ -z "$_drivers" ]; then |
|
|
echo "Signature check of SHA256.sig failed" >&2 && return 1 |
echo "Signature check of SHA256.sig failed" >&2 && return 1 |
|
|
for _d in $_drivers; do |
for _d in $_drivers; do |
$UU && reset_watchdog |
_f=$( sed -n "s/.*(\($_d-firmware-.*\.tgz\)).*/\1/p" "$_cfile" | sed '$!d' ) |
_f=$( sed -n "s/.*(\($_d-firmware-.*\.tgz\)).*/\1/p" "$_cfile" ) |
|
_installed=$( |
_installed=$( |
for fw in "${_pkgdir}/$_d-firmware"*; do |
for fw in "${_pkgdir}/$_d-firmware"*; do |
[ -e "$fw" ] || continue |
[ -e "$fw" ] || continue |
|
|
|
|
while read c g; do |
while read c g; do |
case $c in |
case $c in |
@cwd) cwd="/mnt/$g" |
@cwd) cwd="${DESTDIR}/$g" |
;; |
;; |
@*) continue |
@*) continue |
;; |
;; |
|
|
# TODO: Should we mark these so real fw_update can -Drepair? |
# TODO: Should we mark these so real fw_update can -Drepair? |
ftp -D "Install" -Vmo- "file:$_tmpsrc/$_f" | |
ftp -D "Install" -Vmo- "file:$_tmpsrc/$_f" | |
tar -s ",^\+,${_pkgdir}/${_f%.tgz}/+," \ |
tar -s ",^\+,${_pkgdir}/${_f%.tgz}/+," \ |
-s ",^firmware,mnt/etc/firmware," \ |
-s ",^firmware,${DESTDIR}/etc/firmware," \ |
-C / -zxphf - "+*" "firmware/*" |
-C / -zxphf - "+*" "firmware/*" |
|
|
ed -s "${_pkgdir}/${_f%.tgz}/+CONTENTS" <<EOL |
ed -s "${_pkgdir}/${_f%.tgz}/+CONTENTS" <<EOL |
|
|
done |
done |
} |
} |
|
|
fw_update "$FWURL" |
fw_install "$FWURL" |