pulseaudio/setup-pulseaudio

262 lines
6.4 KiB
Plaintext
Raw Normal View History

#!/bin/sh
LIST_OF_OSS_APPS="aumix sox"
show_help() {
echo "setup-pulseaudio [ --enable | --disable | --status ]"
echo ""
echo "Modifies configuration files of some applications for PulseAudio"
echo " --enable Enables PulseAudio"
echo " --disable Disables PulseAudio"
echo " --status Shows activation state (disabled or enabled) for PulseAudio"
echo ""
echo "You need to be root for this command to succeed"
echo "You may need to re-login for changes to take effect"
exit
}
check_root() {
id=`id -u`
if [ "x$id" = "x0" ]; then
true
else
echo "You need to be root in order to enable/disable pulseaudio"
false
fi
}
enable_phonon() {
echo "Enabling PulseAudio for Phonon..."
perl -pi -e "s|PHONON_PULSEAUDIO_DISABLE=1||g;" /etc/environment
}
enable_alsa() {
echo "Enabling PulseAudio for ALSA..."
if grep "ALSA_CONFIG_PATH" /etc/environment; then
echo "PulseAudio config for ALSA already in use"
else
echo "ALSA_CONFIG_PATH=/etc/alsa-pulse.conf" >> /etc/environment
fi
}
enable_libao() {
echo "Enabling PulseAudio for libao..."
if test -f /etc/libao.conf; then
if grep "default_driver=pulse" /etc/libao.conf; then
echo "Default driver is pulse already in /etc/libao.conf"
else
echo "default_driver=pulse" >> /etc/libao.conf
fi
else
echo "default_driver=pulse" >> /etc/libao.conf
fi
}
enable_mplayer() {
echo "Enabling PulseAudio for mplayer..."
if test -f /etc/mplayer/mplayer.conf; then
if grep -q '^ao=' /etc/mplayer/mplayer.conf; then
perl -pi -e "s|^ao=.*|ao=pulse|g;" /etc/mplayer/mplayer.conf
else
echo "ao=pulse" >> /etc/mplayer/mplayer.conf
fi
fi
# FIXME: mplayerplug-in uses $HOME/.mplayer/mplayerplug-in.conf
}
enable_openal() {
# nothing to do here. openal-soft is patched to prefer pulse but
# it won't autostart the daemon.
return 0
}
enable_oss() {
# this is broken. /etc/environment must only contain environment
# variables. It's not a shell script
return 0
echo "Enabling PulseAudio for OSS..."
for app in $LIST_OF_OSS_APPS; do
if grep "alias $app=padsp $app" /etc/environment; then
echo "Application $app already setup for PulseAudio"
else
echo "alias $app=padsp $app" >> /etc/environment
fi
done
}
enable_sdl() {
echo "Enabling PulseAudio for SDL..."
# For SDL, we just add an environment variable, so that apps use the PA audio driver
if grep SDL_AUDIODRIVER /etc/environment; then
echo "SDL already setup to use PulseAudio"
else
echo "SDL_AUDIODRIVER=pulse" >> /etc/environment
fi
}
enable_timidity() {
# this is broken. /etc/environment must only contain environment
# variables. It's not a shell script
return 0
echo "Enabling PulseAudio for Timidity..."
# Use esound output for timidity
if grep "alias timidity=timidity -Oe" /etc/environment; then
echo "Timidity already setup for using PulseAudio"
else
echo "alias timidity=timidity -Oe" >> /etc/environment
fi
}
enable_xine() {
#echo "Enabling PulseAudio for Xine..."
# FIXME: xine uses $HOME/.xine/config
return 0
}
enable_autospawn() {
echo "Enabling PulseAudio autospawn..."
if grep -q ^autospawn /etc/pulse/client.conf; then
perl -pi -e "s|^autospawn.*|autospawn = yes|g;" /etc/pulse/client.conf
else
echo "autospawn = yes" >> /etc/pulse/client.conf
fi
}
disable_alsa() {
echo "Disabling PulseAudio for ALSA..."
perl -pi -e "s|ALSA_CONFIG_PATH=/etc/alsa-pulse.conf||g;" /etc/environment
}
disable_phonon() {
echo "Disabling PulseAudio for Phonon..."
if grep "PHONON_PULSEAUDIO_DISABLE" /etc/environment; then
echo "PulseAudio config for Phonon already in use"
else
echo "PHONON_PULSEAUDIO_DISABLE=1" >> /etc/environment
fi
}
disable_libao() {
if test -f /etc/libao.conf; then
echo "Disabling PulseAudio for libao..."
perl -pi -e "s|default_driver=pulse||g;" /etc/libao.conf
fi
}
disable_mplayer() {
if test -f /etc/mplayer/mplayer.conf; then
echo "Disabling PulseAudio for mplayer..."
perl -pi -e "s|ao=pulse||g;" /etc/mplayer/mplayer.conf
fi
}
disable_openal() {
# nothing to do here. openal-soft is patched to prefer pulse but
# it won't autostart the daemon.
return 0
}
disable_oss() {
# this is broken. /etc/environment must only contain environment
# variables. It's not a shell script
return 0
for app in $LIST_OF_OSS_APPS; do
perl -pi -e "s|alias $app=padsp $app||g;" /etc/environment
done
}
disable_sdl() {
echo "Disabling PulseAudio for SDL..."
if grep "SDL_AUDIODRIVER=pulse" /etc/environment; then
perl -pi -e "s|SDL_AUDIODRIVER=pulse||g;" /etc/environment
fi
}
disable_timidity() {
# this is broken. /etc/environment must only contain environment
# variables. It's not a shell script
return 0
echo "Disabling PulseAudio for Timidity..."
perl -pi -e "s|alias timidity=timidity -Oe||g;" /etc/environment
}
disable_xine() {
#echo "Disabling PulseAudio for Xine..."
# FIXME: xine uses $HOME/.xine/config
return 0
}
disable_autospawn() {
echo "Disabling PulseAudio autospawn..."
if grep -q ^autospawn /etc/pulse/client.conf; then
perl -pi -e "s|^autospawn.*|autospawn = no|g;" /etc/pulse/client.conf
else
echo "autospawn = no" >> /etc/pulse/client.conf
fi
}
case $1 in
--enable)
check_root || exit
ENABLE=1
enable_alsa
enable_libao
enable_mplayer
enable_openal
enable_oss
enable_sdl
enable_timidity
enable_xine
enable_autospawn
enable_phonon
;;
--disable)
check_root || exit
ENABLE=0
disable_alsa
disable_libao
disable_mplayer
disable_openal
disable_oss
disable_sdl
disable_timidity
disable_xine
disable_autospawn
disable_phonon
;;
--status)
STATUS=`grep PULSEAUDIO_ENABLE /etc/sysconfig/sound | cut -f2 -d= | cut -f2 -d\"`
if [ "x$STATUS" = "xyes" ]; then
echo "enabled"
else
echo "disabled"
fi
exit
;;
*)
show_help
;;
esac
# Now, update /etc/sysconfig/sound with the PA status
if grep -q PULSEAUDIO_ENABLE /etc/sysconfig/sound; then
if [ "x$ENABLE" = "x1" ]; then
perl -pi -e "s|PULSEAUDIO_ENABLE=\"no\"|PULSEAUDIO_ENABLE=\"yes\"|g;" /etc/sysconfig/sound
else
perl -pi -e "s|PULSEAUDIO_ENABLE=\"yes\"|PULSEAUDIO_ENABLE=\"no\"|g;" /etc/sysconfig/sound
fi
else
if [ "x$ENABLE" = "x1" ]; then
echo "PULSEAUDIO_ENABLE=\"yes\"" >> /etc/sysconfig/sound
else
echo "PULSEAUDIO_ENABLE=\"no\"" >> /etc/sysconfig/sound
fi
fi
/sbin/SuSEconfig