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:

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, and then the second block to and then cd to it in a terminal and type “sudo sh”
then reboot, and then type “sudo sh”
(make sure the scripts have execute privileges. (by typing “chmod a+x”)



install necessary stuff

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

echo “downloading alsa packages…”

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

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


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


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


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

echo “now reboot your machine, and run alsa_2”

end of alsa_1


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