Annotation of openbsd/fw_update/fw_install.sh, Revision 1.2
1.1 afresh1 1: #!/bin/ksh
2: set -e
3:
4: scan_dmesg() {
5: # no bsort for now
6: sed -n "$1" /var/run/dmesg.boot
7: }
8:
9: installed_firmware() {
10: for fw in ${PKGDIR}/$1-firmware*; do
11: [ -e "$fw" ] || continue
12: echo ${fw##*/}
13: done
14: }
15:
16: set -A _KERNV -- $( scan_dmesg '/^OpenBSD \([1-9][0-9]*\.[0-9]\)\([^ ]*\) .*/ { s//\1 \2/p; q; }' )
17: VNAME=${_KERNV[0]}
18: OSDIR=$VNAME
19: if ((${#_KERNV[*]} > 1)) && [ "$_KERNV[1]" = "-current" -o "$_KERNV[1]" = "-beta" ]; then
20: OSDIR=snapshots
21: fi
22:
23: FWURL=http://firmware.openbsd.org/firmware/${OSDIR}
24: PKGDIR=${DESTDIR}/var/db/pkg
25: PATTERNS="file:${0%/*}/firmware_patterns"
26:
27: drivers=$(
28: last=''
29: ftp -D "Detecting" -Vmo- $PATTERNS |
30: while read d m; do
31: [ "$last" = "$d" ] && continue
32: [ "$m" ] || m="^$d[0-9][0-9]* at "
1.2 ! afresh1 33: grep -q "$m" /var/run/dmesg.boot || continue
1.1 afresh1 34: echo $d
35: last=$d
36: done
37: )
38:
39: if [ -z "$drivers" ]; then
40: echo "No devices found which need firmware files to be downloaded." >&2
41: exit 0
42: fi
43:
44: tmpdir=${DESTDIR}/tmp/fw_update
45: [ -e "$tmpdir" ] && rm -rf "$tmpdir"
46: mkdir -p "$tmpdir"
47: cd "$tmpdir"
48:
49: # TODO: Drop privs during fetch and verify
50: ftp -D Get -Vm "$FWURL/SHA256.sig"
51:
52: # Probably should bundle the firmware sigfile on the installer,
53: # although we can just get it from the recently installed system.
54: if [ "$DESTDIR" ]; then
55: sigfile=$( sed -n '/^untrusted comment: verify with \(.*\)$/ { s//\1/p; q; }' SHA256.sig )
56: if [ ! -e "/etc/signify/$sigfile" ] \
57: && [ -e "${DESTDIR}/etc/signify/$sigfile" ]; then
58: cp -a "${DESTDIR}/etc/signify/$sigfile" "/etc/signify/$sigfile"
59: fi
60: fi
61:
62: signify -Ve -x SHA256.sig -m - < SHA256.sig > SHA256
63:
64: for d in $drivers; do
65: firmware=$( sed -n "s/.*(\($d-firmware-.*\.tgz\)).*/\1/p" SHA256 )
66: installed=$( installed_firmware $d )
67:
68: for i in $installed; do
69: if [ "$firmware" = "$i.tgz" ]; then
70: echo "Firmware for $d already installed ($installed)"
71: continue 2
72: fi
73: done
74:
75: mkdir $d
76:
77: # TODO: Drop privs during fetch and verify
78: ftp -D "Get/Verify" -Vmo- "$FWURL/$firmware" | sha256 -bph "$d/h" > "$firmware"
79: fgrep -qx "SHA256 ($firmware) = $(<$d/h)" SHA256
80:
81: # TODO: Check hash for files before deleting
82: if [ "$installed" ] && [ -e "${PKGDIR}/$installed/+CONTENTS" ]; then
83: echo "Uninstalling $installed"
84: cwd=${PKGDIR}/$installed
85:
86: remove="${cwd}/+CONTENTS ${cwd}"
87:
88: while read c g; do
89: case $c in
90: @cwd) cwd=$g
91: ;;
92: @*) continue
93: ;;
94: *) remove="$cwd/$c $remove"
95: ;;
96: esac
97: done < "${PKGDIR}/$installed/+CONTENTS"
98:
99: for r in $remove ; do
100: if [ -d "$r" ]; then
101: # Try hard not to actually remove recursively
102: # without rmdir on the install media.
103: [ "$r/*" = $( echo "$r"/* ) ] && rm -rf "$r"
104: else
105: rm -f "$r"
106: fi
107: done
108: fi
109:
110: # TODO: Add some details about the install to +CONTENTS like pkg_add
111: # TODO: Or, maybe we save the firmware someplace and make pkg_add reinstall
112: echo "Installing $firmware"
113: tar -zxphf "$firmware" -C /etc "firmware/*"
114: mkdir -p ${PKGDIR}/${firmware%.tgz}/
115: tar -zxphf "$firmware" -C "${PKGDIR}/${firmware%.tgz}" "+*"
116: ed -s "${PKGDIR}/${firmware%.tgz}/+CONTENTS" <<EOL
117: /^@comment pkgpath/ -1a
118: @option manual-installation
119: @option firmware
120: @comment install-script
121: .
122: w
123: EOL
124: done
125:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>