[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Automatically install required firmware packages (please test)



I've been looking at how to improve the laptop experience, and one
common problem is the need for extra firmware for the wireless cards.

The process of finding and installing required firmware packages can
be automated, and the following is a draft script to do so.  I hope
eventually to have something similar integrated into the hw-detect
udeb used by debian-installer

Please test it and let me know if it worked on your laptop.  It is
slightly tested, but I have a limited set of test hardware. :)


#!/bin/sh
#
# Find missing firmware files requested by the kernel, and install the
# binary packages with the files from the non-free section.

tmpdir=$(mktemp -d)
cd $tmpdir || exit 1

dist=$(lsb_release -cs)
arch=$(dpkg --print-architecture)
mirror=http://cdn.debian.net/debian

# Find firmware files requested by kernel drivers
fwfiles=$(dmesg |grep "firmware: requesting"|rev|awk '{print $1}'|rev|sort -u)

if [ -z "$fwfiles" ] ; then
    echo "info: did not find any firmware files requested by the kernel in dmesg.  exiting"
    exit
fi

GET $mirror/dists/$dist/Contents-$arch.gz | gunzip | grep ^lib/firmware > Fw-Contents-$arch 

binpkginfos=""
binpkgs=""
for fwfile in $fwfiles ; do
    fwfilere=$(echo $fwfile | sed -e 's%/%\\/%g' -e 's/\./\\./g')
    binpkginfo="$(awk "/^lib\/firmware\/$fwfilere/ {print \$2}" Fw-Contents-$arch)"
    if [ -z "$binpkginfo" ] ; then
	# Special case for b43 where the firmware is undistributable
	# by Debian.
	# FIXME verify that this is the correct of the three firmware
	# packages for b43.
	if echo $fwfile |grep -q b43-open ; then
	    binpkgs="firmware-b43-installer $binpkgs"
	fi
    else
	binpkginfos="$binpkginfos $binpkginfo"
    fi
done

binpkgs="$(
for binpkginfo in $binpkginfos ; do
    echo $binpkginfo |  while IFS=/ read section srcpkg binpkg ; do
        echo $binpkg
# Enable the non-free section if it is needed
	if [ non-free = "$section" ] ; then 
	    cat <<EOF > /etc/apt/sources.list.d/auto-addfirmware.list
deb $mirror $dist non-free
deb-src $mirror $dist non-free
EOF
	fi
    done
done) $binpkgs"

# Fetch updated package lists
apt-get update

# Install firmware packages
apt-get install $binpkgs

cd /
rm -rf $tmpdir
-- 
Happy hacking
Petter Reinholdtsen


Reply to: