#!/bin/bash # alsatest-ihda.sh # useful variables MODELS_PATH="/tmp/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" CTLS_REGEX="[Mm](aster|ASTER)|[Pp][Cc][Mm]|[Oo][Uu][Tt]|[Ll][Ff][Ee]" # unmutes and sets volume for all controls function amixer_ctls { IFS=$'\n' # changes the bash Internal Field Separator to only accept /n-ewline for AMIXCTL in $(amixer scontrols | egrep $CTLS_REGEX | sed 's/Simple mixer control //') do amixer -c 0 sset $AMIXCTL 95% unmute done } # reloads alsa, sets volume function reload_alsa { modules-update /etc/init.d/alsasound restart amixer_ctls } # our update / test commands four channels are used for (hopeful) completeness function test_alsaconf { reload_alsa 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 reload_alsa 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."