#!/bin/bash # alsatest-ihda.sh # useful variables MODELS_PATH="${0%/*}/ihda-models.dat" OPTION_IHDA="options snd-hda-intel model=" ALSACONF_PATH="/etc/modules.d/alsa" BKUP_PATH="/var/tmp/alsatest-ihda-models.alsa.bkup" TMP_ALSACONF_PATH="/var/tmp/tmp.alsatest-ihda-models" # our update / test commands # four channels are used for (hopeful) completeness function test_alsaconf { modules-update /etc/init.d/alsasound restart speaker-test -c4 -l2 } # first we save our existing configuration in case of crash of failure if [ -f $BKUP_PATH ] then echo "alsatest: Backup already exists at ${BKUP_PATH}!" echo "alsatest: Skipping backup..." else echo "alsatest: Backing up your existing alsaconf to ${BKUP_PATH}..." cp $ALSACONF_PATH $BKUP_PATH fi # the guts of it exec < $MODELS_PATH # reads in our models from file while read line # loops do MODEL=$line # reads current model in echo "alsatest: Changing ALSA snd-hda-intel model to: ${MODEL}" sed "/${OPTION_IHDA}*/c${OPTION_IHDA}${MODEL}" $ALSACONF_PATH >> $TMP_ALSACONF_PATH # replaces options line in alsa conf mv $TMP_ALSACONF_PATH $ALSACONF_PATH echo "alsatest: Restarting ALSA and testing new model..." test_alsaconf # runs the update and test done if [ -f $BKUP_PATH ] then echo "alsatest: Restoring the model to original before alsatest-ihda-models.sh..." mv $BKUP_PATH $ALSACONF_PATH modules-update /etc/init.d/alsasound restart else echo "alsatest: Oh no! You've lost your backup!" echo "alsatest: For now you're stuck with what you've got." fi echo "alsatest: Script finished."