|
发表于 2005-5-16 20:21:19
|
显示全部楼层
下面是一个自动安装alsa的脚本。你也可以试试。use at your own risk.
用root用户执行。
[php]
# contributor : cornjump (cornjump@gmail.com)
#Thanks to gyo for his help
##################################################
# #
# install alsa automaticly,contains asoundrc #
# #
##################################################
#!/bin/bash
# colors
xC1='\e[0;37m' # white
xC2='\e[1;32m' # green
xC3='\e[1;34m' # blue
xC4='\e[1;31m' # red
NC='\e[0m' # end of color
# First we look if the sript is run as root
if [ $(whoami) = 'root' ]; then
# Choice of the language
lang=
while [ x$lang = x ]; do
echo "lease choose your language / Choisissez votre langue :"
echo "fr / en"
read lang
case $lang in
en | EN )
# Verifying kernel version (alsa-driver must be installed for kernel 2.4)
# If the kernel is nor a 2.4 nor a 2.6, the sript exit
kernel=$(uname -r)
echo "Noyau : $kernel"
if [ ${kernel:0:3} = '2.4' ]; then
echo -en "${xC3}[$NC ${xC2}linux 2.4.X detected$NC ${xC3}]$NC"
echo -e " ${xC3}[$NC ${xC2}ok$NC ${xC3}]$NC"
# Verifying if packages are not yet installed
pacman -Q alsa-driver alsa-lib alsa-utils alsa-oss hwd
if [ $? != '0' ]; then
echo -en "${xC3}[$NC ${xC2}installing 'alsa-driver alsa-lib alsa-utils alsa-oss hwd'$NC
${xC3}]$NC"
pacman -Sy --noconfirm alsa-driver alsa-lib alsa-utils alsa-oss hwd
depmod -a
echo -e " ${xC3}[$NC ${xC2}ok$NC ${xC3}]$NC"
else
echo "${xC3}[$NC ${xC2}Packages are allready installed$NC ${xC3}]$NC"
echo -e ""
fi
elif [ ${kernel:0:3} = '2.6' ]; then
echo -e "${xC3}[$NC ${xC2}linux 2.6.X détecté$NC ${xC3}]$NC"
pacman -Q alsa-lib alsa-utils alsa-oss hwd
if [ $? != '0' ]; then
echo -en "${xC3}[$NC ${xC2}installing 'alsa-lib alsa-utils alsa-oss hwd'$NC ${xC3}]$NC"
pacman -Sy --noconfirm alsa-lib alsa-utils alsa-oss hwd
echo -e " ${xC3}[$NC ${xC2}ok$NC ${xC3}]$NC"
else
echo -e "${xC3}[$NC ${xC2}Packages are allready installed$NC ${xC3}]$NC"
echo -e ""
fi
else
echo -e "********************"
echo -e "${xC3}[$NC ${xC2}Unknown kernel : exit$NC ${xC3}]$NC"
echo -e "********************"
exit
fi
# With hwd we look what are the sound cards modules and put it in a table
# Then, modules are probe
# If modules are note probed successfully, script exit
# Else, the others modules are probed
tab_sndmod=( $(hwd -e | grep -o "snd-[^ ]*") )
for sndmod in ${tab_sndmod}; do
modprobe $sndmod; done
if [ $? = '0' ]; then
echo -e "${xC3}[$NC ${xC4}modprobe of modules: $NC ${xC3}]$NC"
echo -en "${xC3}[$NC ${xC2}module snd-pcm-oss : $NC ${xC3}]$NC"
modprobe snd-pcm-oss
sleep 0.5
echo -e " ${xC3}[$NC ${xC2}ok$NC ${xC3}]$NC"
echo -en "${xC3}[$NC ${xC2}module snd-mixer-oss : $NC ${xC3}]$NC"
modprobe snd-mixer-oss
sleep 0.5
echo -e " ${xC3}[$NC ${xC2}ok$NC ${xC3}]$NC"
echo -en "${xC3}[$NC ${xC2}module snd-mixer-oss : $NC ${xC3}]$NC"
modprobe snd-seq-oss
sleep 0.5
echo -e " ${xC3}[$NC ${xC2}ok$NC ${xC3}]$NC"
else
echo "*******************************"
echo "Error while loading $sndmod"
echo "*******************************"
exit
fi
# Configuration of alsamixer
# Then writing of the alsamixer deamon as /etc/rc.d/alsamixer
# and giving the rights on the deamon
if [ ${#tab_sndmod} = 1 ]; then
echo -e "${xC3}[$NC ${xC2}Updating sound level of Master and PCM: $NC ${xC3}]$NC"
echo ""
amixer set Master 90 unmute
amixer set PCM 90 unmute
echo -en "${xC3}[$NC ${xC2}Sound level of Master and PCM updated: $NC ${xC3}]$NC"
echo -e " ${xC3}[$NC ${xC2}ok$NC ${xC3}]$NC"
elif [ ${#tab_sndmod} != 0 ]; then
echo -e "${xC3}[$NC ${xC2}Updating sound level of Master and PCM: $NC ${xC3}]$NC"
echo ""
amixer -c 0 set Master 90 unmute
amixer -c 0 set PCM 90 unmute
echo -en "${xC3}[$NC ${xC2}Sound level of Master ans PCM updated: $NC ${xC3}]$NC"
echo -e " ${xC3}[$NC ${xC2}ok$NC ${xC3}]$NC"
fi
alsactl store
alsad="#!/bin/bash\n\
. /etc/rc.conf\n\
. /etc/rc.d/functions\n\
case \"\$1\" in\n\
start)\n\
stat_busy \"Restoring Alsa mixer volumes\"\n\
alsactl restore\n\
if [ $? -gt 0 ]; then\n\
stat_fail\n\
else\n\
add_daemon alsamixer\n\
stat_done\n\
fi\n\
;;\n\
stop)\n\
stat_busy \"Storing Alsa mixer volumes\"\n\
alsactl store\n\
if [ $? -gt 0 ]; then\n\
stat_fail\n\
else\n\
rm_daemon alsamixer\n\
stat_done\n\
fi\n\
;;\n\
restart)\n\
$0 stop\n\
sleep 1\n\
$0 start\n\
;;\n\
*)\n\
echo \"Usage $0 {start|stop|restart}\"\n\
;;\n\
esac"
# We send the variable in the file
# then we give the rights on the deamon
echo -en "${xC3}[$NC ${xC2}installing alsamixer script: $NC ${xC3}]$NC"
echo $alsad > /etc/rc.d/alsamixer
chmod 755 /etc/rc.d/alsamixer
echo -e " ${xC3}[$NC ${xC2}ok$NC ${xC3}]$NC"
sleep 1
# Installation of dmix that allows users to play several sounds in the same time
dmix="#/etc/asound.conf start:\n\
pcm.!default {\n\
type plug\n\
slave.pcm \"dmixer\"\n\
}\n\
pcm.dsp0 {\n\
type plug\n\
slave.pcm \"dmixer\"\n\
}\n\
pcm.dmixer {\n\
type dmix\n\
ipc_key 1024\n\
slave {\n\
pcm \"hw:0,0\"\n\
period_time 0\n\
period_size 1024\n\
buffer_size 8192\n\
rate 44100\n\
}\n\
bindings {\n\
0 0\n\
1 1\n\
}\n\
}\n\
ctl.dmixer {\n\
type hw\n\
card 0\n\
}\n\
#end."
# The dmix string is send to the file
# Then /etc/libao.conf is created
# See http://wiki2.archlinux.org/index.php/Allow%20multiple%20programs%20to%20play%20sound%20at%20once
echo -en "${xC3}[$NC ${xC2}configuring dmix: $NC ${xC3}]$NC"
echo $dmix > /etc/asound.conf
echo "default_driver=alsa09" > /etc/libao.conf
echo -e " ${xC3}[$NC ${xC2}ok$NC ${xC3}]$NC"
# Saving /etc/rc.conf then modifying it to write modules and deamon
echo -en "${xC3}[$NC ${xC2}Saving /etc/rc.conf as /etc/rc.conf.save $NC ${xC3}]$NC"
cp /etc/rc.conf /etc/rc.conf.save
echo -e " ${xC3}[$NC ${xC2}ok$NC ${xC3}]$NC"
# Verifying if modules and deamon are not yet write in /etc/rc.conf
echo -e "${xC3}[$NC ${xC4}Verifying if modules and deamon are not yet write in /etc/rc.conf $NC ${xC3}]$NC"
echo -e ""
for sndmod in ${tab_sndmod}; do
grep $sndmod /etc/rc.conf
if [ $? != 0 ]; then
sed -ie "/^MODULES/s/)/ $sndmod)/" /etc/rc.conf
echo -e "${xC3}[$NC ${xC2} $sndmod added to /etc/rc.conf $NC ${xC3}]$NC"
else
echo -e "${xC3}[$NC ${xC3} $sndmod is yet in /etc/rc.conf $NC ${xC3}]$NC"
fi
done
grep snd-pcm-oss /etc/rc.conf
if [ $? != 0 ]; then
sed -ie "/^MODULES/s/)/ snd-pcm-oss)/" /etc/rc.conf
echo -e "${xC3}[$NC ${xC2} snd-pcm-oss added to /etc/rc.conf $NC ${xC3}]$NC"
else
echo -e "${xC3}[$NC ${xC3} snd-pcm-oss is yet in /etc/rc.conf $NC ${xC3}]$NC"
fi
grep snd-mixer-oss /etc/rc.conf
if [ $? != 0 ]; then
sed -ie "/^MODULES/s/)/ snd-mixer-oss)/" /etc/rc.conf
echo -e "${xC3}[$NC ${xC2} snd-mixer-oss added to /etc/rc.conf $NC ${xC3}]$NC"
else
echo -e "${xC3}[$NC ${xC3} snd-mixer-oss is yet in /etc/rc.conf $NC ${xC3}]$NC"
fi
grep snd-seq-oss /etc/rc.conf
if [ $? != 0 ]; then
sed -ie "/^MODULES/s/)/ snd-seq-oss)/" /etc/rc.conf
echo -e "${xC3}[$NC ${xC2} snd-seq-oss added to /etc/rc.conf $NC ${xC3}]$NC"
else
echo -e "${xC3}[$NC ${xC3} snd-seq-oss is yet in /etc/rc.conf $NC ${xC3}]$NC"
fi
grep "DAEMONS=(" /etc/rc.conf | grep alsamixer
if [ $? != 0 ]; then
sed -ie "/^DAEMONS/s/)/ alsamixer)/" /etc/rc.conf
echo -e "${xC3}[$NC ${xC2} alsamixer added to /etc/rc.conf $NC ${xC3}]$NC"
else
echo -e "${xC3}[$NC ${xC3} alsamixer is yet in /etc/rc.conf $NC ${xC3}]$NC"
fi
echo -en "${xC3}[$NC ${xC2}/etc/rc.conf updated $NC ${xC3}]$NC"
echo -e " ${xC3}[$NC ${xC2}ok$NC ${xC3}]$NC"
# For the end, we ask what user must be added to the audio group
# and the user is add
tab_user=( $(ls /home) )
echo "Which user do tou want to add to the audio group?"
for username in ${tab_user}; do
echo " $username"
done
read USERNAME
echo -en "${xC3}[$NC ${xC2}add $USERNAME in the audio group $NC ${xC3}]$NC"
gpasswd -a $USERNAME audio
echo -e " ${xC3}[$NC ${xC2}ok$NC ${xC3}]$NC"
;;
fr | FR )
# French part of the script / Partie françisée du script
# Verification de la version du kernel (alsa-driver doit etre installé pour les kernel 2.4)
# Si le kernel n'est ni un 2.4 ni 2.6, on sort du script
kernel=$(uname -r)
echo "Noyau : $kernel"
if [ ${kernel:0:3} = '2.4' ]; then
echo -en "${xC3}[$NC ${xC2}linux 2.4.X détecté$NC ${xC3}]$NC"
echo -e " ${xC3}[$NC ${xC2}ok$NC ${xC3}]$NC"
# On vérifie si les package ne sont pas déjà installés
pacman -Q alsa-driver alsa-lib alsa-utils alsa-oss hwd
if [ $? != '0' ]; then
echo -en "${xC3}[$NC ${xC2}installation de 'alsa-driver alsa-lib alsa-utils alsa-oss hwd'$NC
${xC3}]$NC"
pacman -Sy --noconfirm alsa-driver alsa-lib alsa-utils alsa-oss hwd
depmod -a
echo -e " ${xC3}[$NC ${xC2}ok$NC ${xC3}]$NC"
else
echo "${xC3}[$NC ${xC2}Les paquets sont déjà installés$NC ${xC3}]$NC"
echo -e ""
fi
elif [ ${kernel:0:3} = '2.6' ]; then
echo -e "${xC3}[$NC ${xC2}linux 2.6.X détecté$NC ${xC3}]$NC"
pacman -Q alsa-lib alsa-utils alsa-oss hwd
if [ $? != '0' ]; then
echo -en "${xC3}[$NC ${xC2}installation de 'alsa-lib alsa-utils alsa-oss hwd'$NC ${xC3}]$NC"
pacman -Sy --noconfirm alsa-lib alsa-utils alsa-oss hwd
echo -e " ${xC3}[$NC ${xC2}ok$NC ${xC3}]$NC"
else
echo -e "${xC3}[$NC ${xC2}Les paquets sont déjà installés$NC ${xC3}]$NC"
echo -e ""
fi
else
echo -e "********************"
echo -e "${xC3}[$NC ${xC2}Noyau inconnu : exit$NC ${xC3}]$NC"
echo -e "********************"
exit
fi
# With hwd we look what are the sound cards modules and put it in a table
# Then, modules are probe
# If modules are note probed successfully, script exit
# Else, the others modules are probed
tab_sndmod=( $(hwd -e | grep -o "snd-[^ ]*") )
for sndmod in ${tab_sndmod}; do
modprobe $sndmod; done
if [ $? = '0' ]; then
echo -e "${xC3}[$NC ${xC4}modprobe des modules: $NC ${xC3}]$NC"
echo -en "${xC3}[$NC ${xC2}module snd-pcm-oss : $NC ${xC3}]$NC"
modprobe snd-pcm-oss
sleep 0.5
echo -e " ${xC3}[$NC ${xC2}ok$NC ${xC3}]$NC"
echo -en "${xC3}[$NC ${xC2}module snd-mixer-oss : $NC ${xC3}]$NC"
modprobe snd-mixer-oss
sleep 0.5
echo -e " ${xC3}[$NC ${xC2}ok$NC ${xC3}]$NC"
echo -en "${xC3}[$NC ${xC2}module snd-mixer-oss : $NC ${xC3}]$NC"
modprobe snd-seq-oss
sleep 0.5
echo -e " ${xC3}[$NC ${xC2}ok$NC ${xC3}]$NC"
else
echo "*******************************"
echo "Erreur de chargment de $sndmod"
echo "*******************************"
exit
fi
# Configuration of alsamixer
# Then writing of the alsamixer deamon as /etc/rc.d/alsamixer
# and giving the rights on the deamon
if [ ${#tab_sndmod} = 1 ]; then
echo -e "${xC3}[$NC ${xC2}Mise a niveau du Master et du PCM: $NC ${xC3}]$NC"
echo ""
amixer set Master 90 unmute
amixer set PCM 90 unmute
echo -en "${xC3}[$NC ${xC2}Niveau sonore de Master et PCM mis a jour: $NC ${xC3}]$NC"
echo -e " ${xC3}[$NC ${xC2}ok$NC ${xC3}]$NC"
elif [ ${#tab_sndmod} != 0 ]; then
echo -e "${xC3}[$NC ${xC2}Mise a niveau du Master et du PCM: $NC ${xC3}]$NC"
echo ""
amixer -c 0 set Master 90 unmute
amixer -c 0 set PCM 90 unmute
echo -en "${xC3}[$NC ${xC2}Niveau sonore de Master et PCM mis a jour: $NC ${xC3}]$NC"
echo -e " ${xC3}[$NC ${xC2}ok$NC ${xC3}]$NC"
fi
alsactl store
alsad="#!/bin/bash\n\
. /etc/rc.conf\n\
. /etc/rc.d/functions\n\
case \"\$1\" in\n\
start)\n\
stat_busy \"Restoring Alsa mixer volumes\"\n\
alsactl restore\n\
if [ $? -gt 0 ]; then\n\
stat_fail\n\
else\n\
add_daemon alsamixer\n\
stat_done\n\
fi\n\
;;\n\
stop)\n\
stat_busy \"Storing Alsa mixer volumes\"\n\
alsactl store\n\
if [ $? -gt 0 ]; then\n\
stat_fail\n\
else\n\
rm_daemon alsamixer\n\
stat_done\n\
fi\n\
;;\n\
restart)\n\
$0 stop\n\
sleep 1\n\
$0 start\n\
;;\n\
*)\n\
echo \"Usage $0 {start|stop|restart}\"\n\
;;\n\
esac"
# We send the variable in the file
# then we give the rights on the deamon
echo -en "${xC3}[$NC ${xC2}installation du script alsamixer: $NC ${xC3}]$NC"
echo $alsad > /etc/rc.d/alsamixer
chmod 755 /etc/rc.d/alsamixer
echo -e " ${xC3}[$NC ${xC2}ok$NC ${xC3}]$NC"
sleep 1
# Installation of dmix that allows users to play several sounds in the same time
dmix="#/etc/asound.conf start:\n\
pcm.!default {\n\
type plug\n\
slave.pcm \"dmixer\"\n\
}\n\
pcm.dsp0 {\n\
type plug\n\
slave.pcm \"dmixer\"\n\
}\n\
pcm.dmixer {\n\
type dmix\n\
ipc_key 1024\n\
slave {\n\
pcm \"hw:0,0\"\n\
period_time 0\n\
period_size 1024\n\
buffer_size 8192\n\
rate 44100\n\
}\n\
bindings {\n\
0 0\n\
1 1\n\
}\n\
}\n\
ctl.dmixer {\n\
type hw\n\
card 0\n\
}\n\
#end."
# The dmix string is send to the file
# Then /etc/libao.conf is created
# See http://wiki2.archlinux.org/index.php/Allow%20multiple%20programs%20to%20play%20sound%20at%20once
echo -en "${xC3}[$NC ${xC2}configuration de dmix: $NC ${xC3}]$NC"
echo $dmix > /etc/asound.conf
echo "default_driver=alsa09" > /etc/libao.conf
echo -e " ${xC3}[$NC ${xC2}ok$NC ${xC3}]$NC"
# Saving /etc/rc.conf then modifying it to write modules and deamon
echo -en "${xC3}[$NC ${xC2}Sauvegarde de /etc/rc.conf vers /etc/rc.conf.save $NC ${xC3}]$NC"
cp /etc/rc.conf /etc/rc.conf.save
echo -e " ${xC3}[$NC ${xC2}ok$NC ${xC3}]$NC"
# Verifying if modules and deamon are not yet write in /etc/rc.conf
echo -e "${xC3}[$NC ${xC4}Verification si les modules et daemons ne sont pas déjà écrit dans /etc/rc.conf $NC ${xC3}]$NC"
echo -e ""
for sndmod in ${tab_sndmod}; do
grep $sndmod /etc/rc.conf
if [ $? != 0 ]; then
sed -ie "/^MODULES/s/)/ $sndmod)/" /etc/rc.conf
echo -e "${xC3}[$NC ${xC2} $sndmod ajouté à /etc/rc.conf $NC ${xC3}]$NC"
else
echo -e "${xC3}[$NC ${xC3} $sndmod est déjà dans /etc/rc.conf $NC ${xC3}]$NC"
fi
done
grep snd-pcm-oss /etc/rc.conf
if [ $? != 0 ]; then
sed -ie "/^MODULES/s/)/ snd-pcm-oss)/" /etc/rc.conf
echo -e "${xC3}[$NC ${xC2} snd-pcm-oss ajouté à /etc/rc.conf $NC ${xC3}]$NC"
else
echo -e "${xC3}[$NC ${xC3} snd-pcm-oss est déjà dans /etc/rc.conf $NC ${xC3}]$NC"
fi
grep snd-mixer-oss /etc/rc.conf
if [ $? != 0 ]; then
sed -ie "/^MODULES/s/)/ snd-mixer-oss)/" /etc/rc.conf
echo -e "${xC3}[$NC ${xC2} snd-mixer-oss ajouté à /etc/rc.conf $NC ${xC3}]$NC"
else
echo -e "${xC3}[$NC ${xC3} snd-mixer-oss est déjà dans /etc/rc.conf $NC ${xC3}]$NC"
fi
grep snd-seq-oss /etc/rc.conf
if [ $? != 0 ]; then
sed -ie "/^MODULES/s/)/ snd-seq-oss)/" /etc/rc.conf
echo -e "${xC3}[$NC ${xC2} snd-seq-oss ajouté à /etc/rc.conf $NC ${xC3}]$NC"
else
echo -e "${xC3}[$NC ${xC3} snd-seq-oss est déjà dans /etc/rc.conf $NC ${xC3}]$NC"
fi
grep "DAEMONS=(" /etc/rc.conf | grep alsamixer
if [ $? != 0 ]; then
sed -ie "/^DAEMONS/s/)/ alsamixer)/" /etc/rc.conf
echo -e "${xC3}[$NC ${xC2} alsamixer ajouté à /etc/rc.conf $NC ${xC3}]$NC"
else
echo -e "${xC3}[$NC ${xC3} alsamixer est déjà dans /etc/rc.conf $NC ${xC3}]$NC"
fi
echo -en "${xC3}[$NC ${xC2}/etc/rc.conf mis à jour $NC ${xC3}]$NC"
echo -e " ${xC3}[$NC ${xC2}ok$NC ${xC3}]$NC"
# For the end, we ask what user must be added to the audio group
# and the user is add
tab_user=( $(ls /home) )
echo "Quel utilisateur voulez vous ajouter au group audio?"
for username in ${tab_user}; do
echo " $username"
done
read USERNAME
echo -en "${xC3}[$NC ${xC2}ajout de $USERNAME au groupe audio $NC ${xC3}]$NC"
gpasswd -a $USERNAME audio
echo -e " ${xC3}[$NC ${xC2}ok$NC ${xC3}]$NC"
;;
esac
done
# If the script is not run as root, we ask the user to log as root
else
echo -e "${xC4}[$NC ${xC2}$USER, loggez vous en root pour executer ce script$NC ${xC3}]$NC"
fi
[/php] |
|