bash script to automate compiling alsa in Ubuntu

Most of the laptops I’ve owned have had trouble with sound to some degree. The only solution is to compile the latest version of alsa manually, as most GNU/Linux distros have an out of date alsa (even the recently released Ubuntu 7.10 – Gutsy Gibbon)

This wouldn’t be a big deal, but every time you get a kernel update, you have to compile alsa again. This can become a bit of a pain, so I wrote a bash script that would do it all for me.
First the script will download all alsa’s dependencies. Then it will download:
alsa-driver-1.0.15.tar.bz2
alsa-lib-1.0.15.tar.bz2
alsa-utils-1.0.15.tar.bz2

it will then extract them (whilst deleting the .bz2), move them to /usr/src/alsa and compile them each.

just copy the first block of text to a text file and save as alsa_1.sh, and then the second block to alsa_2.sh and then cd to it in a terminal and type “sudo sh alsa_1.sh”
then reboot, and then type “sudo sh alsa_2.sh”
(make sure the scripts have execute privileges. (by typing “chmod a+x alsa_1.sh”)

alsa_1.sh
————————

!/bin/sh

#

install necessary stuff

apt-get install build-essential ncurses-dev gettext
apt-get install linux-headers-`uname -r`

echo “downloading alsa packages…”
wget ftp://ftp.alsa-project.org/pub/driver/alsa-driver-1.0.15.tar.bz2
wget ftp://ftp.alsa-project.org/pub/lib/alsa-lib-1.0.15.tar.bz2
wget ftp://ftp.alsa-project.org/pub/utils/alsa-utils-1.0.15.tar.bz2

echo “extracting alsa packages…”
tar -xjf alsa-driver.tar.bz2
tar -xjf alsa-lib
.tar.bz2
tar -xjf alsa-utils.tar.bz2
rm alsa
.tar.bz2

echo “setting up alsa for compilation”
mkdir -p /usr/src/alsa
mv alsa-* /usr/src/alsa

alsa-driver

cd /usr/src/alsa/alsa-driver*
./configure –with-cards=hda-intel
make
make install

alsa-lib

cd /usr/src/alsa/alsa-lib*
./configure
make
make install

alsa-utils

cd /usr/src/alsa/alsa-utils*
./configure
make
make install

echo “now reboot your machine, and run alsa_2”

end of alsa_1

alsa_2.sh
————————

!/bin/sh

for after reboot

cp -v /lib/modules/`uname -r`/kernel/sound/pci/hda/snd-hda-intel.ko /lib/modules/`uname -r`/ubuntu/media/snd-hda-intel/snd-hda-intel.ko
cp -v /usr/src/alsa/alsa-driver*/modules/* /lib/modules/`uname -r`/kernel/sound/
depmod -a

end of alsa_2

note, in its bare form, this will work in any distro, but my script installs the dependencies using APT (so this will only work for debian based distros – Debian, Ubuntu, LinuxMint, Mepis etc..)

also, alsa_2 is assuming kernel 2.6.22. If you have a different kernel, or several .22 kernels, you’ll need to specify. Also, my script compiles the alsa-driver for intel-hda sound cards. This is the most common card for laptops (if you have an intel processor, chances are you have it). If not, replace with your sound cards name