#!/bin/sh
#
# Add non-free firmware to the chroot used by ltsp to enable certain
# network cards (Intel, Broadcom, ...). Takes package name as param,
# or add all firmware packages if no package name is given.

set -e

# usage 
if [ "$1" = "-h" ] 
then 
    cat <<EOF

Usage information:
Execute: apt-get update && apt-cache search ^firmware-.*
Decide which package has to be installed for the network card.
Then call this script with the package name as parameter.  Or do not
use any parameter and get all firmware packages installed in the LTSP
chroot.

EOF
    exit 0
fi
if [ "$1" ] ; then
    debnames="$*"
else
    # Find files.  This require non-free to be enabled as APT
    # repository.
    # Skip installer debs, to avoid the b43 installers that conflict
    # with each other.  FIXME review if this is needed after squeeze.
    debnames="$(apt-cache search ^firmware-.* | grep -v installer | cut -d" " -f1)"
fi

# do things in the ltsp chroot for arch i386
arch=i386
TMP= TMPDIR= ltsp-chroot -a $arch apt-get update
TMP= TMPDIR= ltsp-chroot -d -a $arch apt-get -y -q install $debnames

# copy new initrd from chroot to the server tftpboot dir
ltsp-update-kernels

cat <<EOF
Done - if no error about an unlocateable package was reported.
Booting a machine as thin client or diskless workstation should now be
possible.  If this is not the case, the installation of other or
additional firmware is likely to be required.

EOF
