#!/bin/sh # # Script to ensure USB Audio device is hotplugable. # # # Default sound device # # $DEFAULT = the card number of your default device ('cat /proc/asound/cards') # $DEFAULT_NAME = the name of your default device (from /etc/asound.conf) # DEFAULT=0 DEFAULT_NAME="hda-intel" # # USB sound device # # $USB_AUDIO = the card number of your usb device ('cat /proc/asound/cards') # $USB_AUDIO_NAME = the name of your usb device (from /etc/asound.conf) # USB_AUDIO=1 USB_AUDIO_NAME="usb-audio" # # Where are your user home directories? This variable will allow script to write # to /$DIR/$USER/.asoundrc # DIRS=`ls /home` # If USB-Audio card does not exist, this will be an empty value # thus defaulting to Intel HDA CARD_EXISTS=`grep -o -e 'USB-Audio' < /proc/asound/cards` CARD=${DEFAULT} if [ "${CARD_EXISTS}" == "USB-Audio" ] ; then CARD=${USB_AUDIO} fi if [ "${CARD}" == "${DEFAULT}" ] ; then DEVICE_NAME="${DEFAULT_NAME}" else DEVICE_NAME="${USB_AUDIO_NAME}" fi # Write to user's .asoundrc file for userdir in ${DIRS} ; do cat< /home/${userdir}/.asoundrc pcm.!default { type plug slave.pcm "${DEVICE_NAME}" } ctl.!default { type plug slave.pcm "${DEVICE_NAME}" } EOF done # Write to user's .openalrc file for userdir in ${DIRS} ; do cat< /home/${userdir}/.openalrc (define devices '(alsa)) (define alsa-out-device "hw:${CARD},0") EOF done fi exit