Skip to content

Instantly share code, notes, and snippets.

@sagax
Last active February 24, 2016 19:45
Show Gist options
  • Save sagax/39b9ba7c1ccea96fc0d5 to your computer and use it in GitHub Desktop.
Save sagax/39b9ba7c1ccea96fc0d5 to your computer and use it in GitHub Desktop.
excellent script of preservation and installation of a sound
#!/bin/bash -
FILE_SAVE_TEMPLATE="alsa_"
read_params() {
local number_card=$1
local numidlist=$(amixer -D hw:"$number_card" controls | awk --re-interval 'BEGIN{FS=","}{print $1}')
local numarray=($numidlist)
local params=()
for key in "${numarray[@]}"
do
value=$(amixer -D hw:"$number_card" cget $key | awk --re-interval 'BEGIN {FS=": values="}/: values/ {print $2}')
if [[ $value =~ ^[0-9]{1,3},[0-9]{1,3}|^[0-9]{1,3}|on,on|off,off|on|off ]]
then
params[$key]="$value"
fi
done
if [[ -f "$FILE_SAVE_TEMPLATE""$number_card" ]]
then
rm "$FILE_SAVE_TEMPLATE""$number_card"
fi
for i in ${!params[@]}
do
printf "$i:${params[$i]}\n" >> "$FILE_SAVE_TEMPLATE""$number_card"
done
}
set_params () {
local number_card=$1
local params=($(cat "$FILE_SAVE_TEMPLATE""$number_card"))
for i in "${params[@]}"
do
key=$(printf "$i" | awk --re-interval 'BEGIN { FS=":" } { print $1 }')
value=$(printf "$i" | awk --re-interval 'BEGIN { FS=":" } { print $2 }')
if [[ $value =~ ^[0-9]{1,3},[0-9]{1,3}|^[0-9]{1,3}|on,on|off,off|on|off ]]
then
amixer -D hw:"$number_card" cset numid=$key $value 1>/dev/null 2>/dev/null
fi
done
}
case "$1" in
read)
for i in $(awk --re-interval "/^.[0-9]{1,2}/"'{print $1}' /proc/asound/cards | xargs)
do
read_params $i
done
;;
set)
for i in $(awk --re-interval "/^.[0-9]{1,2}/"'{print $1}' /proc/asound/cards | xargs)
do
set_params $i
done
;;
*)
echo "read set"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment