1#!/bin/sh 2 3# $OpenBSD: fw_update.sh,v 1.8 2011/08/02 15:52:26 deraadt Exp $ 4# Copyright (c) 2011 Alexander Hall <alexander@beard.se> 5# 6# Permission to use, copy, modify, and distribute this software for any 7# purpose with or without fee is hereby granted, provided that the above 8# copyright notice and this permission notice appear in all copies. 9# 10# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 18# This is the list of drivers we should look for 19DRIVERS="acx athn bwi ipw iwi iwn malo otus pgt rsu uath ueagle upgt urtwn 20 uvideo wpi" 21 22PKG_ADD="pkg_add -D repair" 23 24usage() { 25 echo "usage: ${0##*/} [-nv]" >&2 26 exit 1 27} 28 29verbose() { 30 [ "$verbose" ] && echo "${0##*/}: $@" 31} 32 33verbose= 34nop= 35while getopts 'nv' s "$@" 2>&-; do 36 case "$s" in 37 v) verbose=${verbose:--}v ;; 38 n) nop=-n ;; 39 *) usage ;; 40 esac 41done 42 43# No additional arguments allowed 44[ $# = $(($OPTIND-1)) ] || usage 45 46set -- $(sysctl -n kern.version | sed 's/^OpenBSD \([0-9]\.[0-9]\)\([^ ]*\).*/\1 \2/;q') 47 48version=$1 49tag=$2 50 51[ -n "$tag" -a X"$tag" != X"-stable" ] && version=snapshots 52export PKG_PATH=http://firmware.openbsd.org/firmware/$version/ 53 54installed=$(pkg_info -q) 55dmesg=$(cat /var/run/dmesg.boot; echo; dmesg) 56 57install= 58update= 59 60for driver in $DRIVERS; do 61 if print -r -- "$installed" | grep -q "^${driver}-firmware-"; then 62 update="$update ${driver}-firmware" 63 elif print -r -- "$dmesg" | grep -q "^${driver}[0-9][0-9]* at "; then 64 install="$install ${driver}-firmware" 65 fi 66done 67 68if [ -z "$install$update" ]; then 69 verbose "No devices found which need firmware files to be downloaded." 70 exit 0 71fi 72 73[ "$nop" ] || [ 0 = $(id -u) ] || 74 { echo "${0##*/} must be run as root" >&2; exit 1; } 75 76# Install missing firmware 77if [ "$install" ]; then 78 verbose "Installing firmware files:$install." 79 $PKG_ADD $nop $verbose $install 80fi 81 82# Update installed firmware 83if [ "$update" ]; then 84 verbose "Updating firmware files:$update." 85 $PKG_ADD $nop $verbose -u $update 86fi 87