#/bin/sh
# Small script to download,patch,build the alsa module for Thinkpad T61/R61/X61.
# t61-build-alsa-module.sh v0.41 (C) Franklin Piat 2007. released under GPL.
# thanks to 
#	Alsa teams
#	http://www.thinkwiki.org/wiki/AD1984
# 	http://www.linuxquestions.org/questions//showthread.php?s=0b8d3760255e43abaecdfc8e0e4cba12&t=564079&page=3
#
apt-get install module-assistant
m-a prepare || exit
m-a clean alsa || exit
m-a get alsa-source || exit
m-a unpack alsa || exit
cd /usr/src/modules/alsa-driver/alsa-kernel/ || exit
## kernel alsa 1.0.14 don't need the first three patch
case "$(cat ../version)" in 
	1.0.13*)
		wget -O - http://hg.alsa-project.org/alsa-kernel/raw-diff/ed48e4edc677/pci/hda/patch_analog.c | patch -p1 || exit
		wget -O - http://hg.alsa-project.org/alsa-kernel/raw-diff/45179b325c8e/pci/hda/patch_analog.c | patch -p1 || exit
		wget -O - http://www.klabs.be/~fpiat/linux/debian/Etch_on_Thinkpad_T61/t61-alsa-1.0.13-backport-patch.diff | patch -p1 || exit
	 ;;
esac
wget -O - http://hg.alsa-project.org/alsa-kernel/raw-diff/958b39f3e8dd/pci/hda/patch_analog.c | patch -p1 || exit
wget -O - http://hg.alsa-project.org/alsa-kernel/raw-diff/47ca87407c84/pci/hda/patch_analog.c | patch -p1 || exit
wget -O - http://hg.alsa-project.org/alsa-kernel/raw-diff/ca37aeeeb0ea/pci/hda/patch_analog.c | patch -p1 || exit
m-a --not-unpack build alsa || exit
#Install with : dpkg -i /usr/src/alsa-modules-$(uname -r)_1.0.14-1+$(uname -r).deb
#You might have to enable "speaker" (in the gnome mixer's "switch" tab ; Or in "alsamixer").
#You might need to add "options snd-hda-intel model=thinkpad" at the end of /etc/modprobe.d/alsa-base
