#!/bin/bash # DRIVER="hp-be2net-2.102.435.0.tar.gz" INITRDOUT="initrd.gz-$(date +%Y%m%d)" #KVER="2.6.32-5-amd64" set -e # Make sure we can create devices and preserve permissions. if [ "$(whoami)" != "root" ]; then which fakeroot >/dev/null 2>&1 if [ $? -ne 0 ]; then echo "You must install the fakeroot package to build as a user." exit 1 fi echo "Re-executing under fakeroot..." exec fakeroot $0 echo "exec fakeroot failed with return code: $?" exit 1 fi # Check for a linux-headers package to use. if [ $KVER ]; then KPATH="/usr/src/linux-headers-$KVER" else KPATH=$(dpkg -l 'linux-headers-*' | egrep '^ii' | egrep -v 'common|meta' | awk 'END { print $2 }') if [ $KPATH ]; then KVER=$(echo $KPATH | sed 's/linux-headers-//') KPATH="/usr/src/$KPATH" else echo "Unable to discover an installed linux-headers package." echo "You must install one to proceed (hint: apt-get install linux-headers)" exit 1 fi fi # Make sure the user provided an initrd to work on. if [ ! -f ./initrd.gz ]; then echo "You must put the target initrd.gz file in the same directory as this script." exit 1 fi echo -e "DRIVER=$DRIVER\nINITRDOUT=$INITRDOUT\nKVER=$KVER\nKPATH=$KPATH" # Might need to make these. mkdir -p initrd module # Rebuild the HP driver for the current kernel... echo -e "\nBUILD MODULE" tar xzf hp-be2net-*.tar.gz -C module --strip-components=1 ( cd module make -C "$KPATH" modules M="$PWD" CONFIG_BE2NET=m ) # Rebuild the initd image with this be2net driver. echo -e "\nREBUILD INITRD" ( cd initrd gzip -dc ../initrd.gz | cpio -id mkdir -p "lib/modules/$KVER/kernel/drivers/net/benet" cp ../module/be2net.ko "lib/modules/$KVER/kernel/drivers/net/benet/" fgrep 'be2net.ko:' "lib/modules/$KVER/modules.dep" >/dev/null 2>&1 && { sed -r -i -e 's#^(kernel/drivers/net/benet/be2net.ko:)\s*$#\1 kernel/net/ipv4/inet_lro.ko#' "lib/modules/$KVER/modules.dep" } || { fgrep 'be2net.ko:' "lib/modules/$KVER/modules.dep" || echo "kernel/drivers/net/benet/be2net.ko: kernel/net/ipv4/inet_lro.ko" >> "lib/modules/$KVER/modules.dep" } ls -l "lib/modules/$KVER/kernel/drivers/net/benet/" fgrep 'be2net.ko:' "lib/modules/$KVER/modules.dep" find ./ | cpio -H newc -o > "../$INITRDOUT" ) echo -e "\nNew initrd.gz is: $(pwd)/$INITRDOUT" # Clean up after ourselves. rm -rf module/.[a-z]* module/* initrd/*