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