Last active
February 24, 2016 19:45
-
-
Save sagax/39b9ba7c1ccea96fc0d5 to your computer and use it in GitHub Desktop.
excellent script of preservation and installation of a sound
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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