mconf()
{
# arbitrary, but I can't imagine a system with more
# than 6 *different* audio cards !
for i in `seq 6` ;
  do C=`echo snd-$CARDS | sed s/\,/\,snd-/g | cut -d, -f${i}` ;
  if [ -n "$C" ] ; then
    echo  "alias snd-card-`expr $i - 1` $C">>${INSTALL_ROOT}/etc/modules.d/alsa &&
    echo  "alias snd-slot-`expr $i - 1` snd-card-`expr $i - 1`">>${INSTALL_ROOT}/etc/modules.d/alsa
  fi ;
done  &&

cat >> ${INSTALL_ROOT}/etc/modules.d/alsa <<EOF
alias /dev/mixer snd-mixer-oss
alias /dev/dsp snd-pcm-oss
alias /dev/midi snd-seq-oss
EOF
}

dconf()
{
  if test -f ${INSTALL_ROOT}/etc/devfsd.conf && ! grep -q alsa ${INSTALL_ROOT}/etc/devfsd.conf; then
    cat >> ${INSTALL_ROOT}/etc/devfsd.conf <<EOF

# some MODLOAD
LOOKUP          midi            MODLOAD

# setup permissions for oss audio/alsa oss emulation
REGISTER        ^sound/         PERMISSIONS -1.audio 0660

# setup some symlinks for oss audio/alsa oss emulation
REGISTER        ^sound/mixer$   CFUNCTION GLOBAL mksymlink $devname mixer
REGISTER        ^sound/mixer$   CFUNCTION GLOBAL mksymlink $devname mixer0
UNREGISTER      ^sound/mixer$   CFUNCTION GLOBAL unlink mixer
UNREGISTER      ^sound/mixer$   CFUNCTION GLOBAL unlink mixer0
REGISTER        ^sound/dsp$     CFUNCTION GLOBAL mksymlink $devname dsp
UNREGISTER      ^sound/dsp$     CFUNCTION GLOBAL unlink dsp
REGISTER        ^sound/adsp$    CFUNCTION GLOBAL mksymlink $devname dsp1
UNREGISTER      ^sound/adsp$    CFUNCTION GLOBAL unlink dsp1
REGISTER        ^sound/midi$    CFUNCTION GLOBAL mksymlink $devname midi
UNREGISTER      ^sound/midi$    CFUNCTION GLOBAL unlink midi
REGISTER        ^sound/amidi$   CFUNCTION GLOBAL mksymlink $devname amidi
UNREGISTER      ^sound/amidi$   CFUNCTION GLOBAL unlink amidi
EOF
  else
    echo "devfsd.conf already configured, skipping"
  fi
}

default_install  &&
./snddevices     &&

if  [  -f  ${INSTALL_ROOT}/dev/snd  ];  then
  rm  -f   ${INSTALL_ROOT}/dev/snd
fi  &&

chown root.audio ${INSTALL_ROOT}/dev/adsp         &&
chmod 777 ${INSTALL_ROOT}/dev/adsp                &&
chown root.audio ${INSTALL_ROOT}/dev/amidi        &&
chmod 777 ${INSTALL_ROOT}/dev/amidi               &&
chown root.audio ${INSTALL_ROOT}/dev/audio        &&
chmod 777 ${INSTALL_ROOT}/dev/audio               &&
chown root.audio ${INSTALL_ROOT}/dev/dsp          &&
chmod 777 ${INSTALL_ROOT}/dev/dsp                 &&
chown root.audio ${INSTALL_ROOT}/dev/midi*        &&
chmod 777 ${INSTALL_ROOT}/dev/midi*               &&
chown root.audio ${INSTALL_ROOT}/dev/mixer        &&
chmod 777 ${INSTALL_ROOT}/dev/mixer               &&
chown root.audio ${INSTALL_ROOT}/dev/sequencer*   &&
chmod 777 ${INSTALL_ROOT}/dev/sequencer*          &&
chown root.audio ${INSTALL_ROOT}/dev/snd          &&
chmod 777 ${INSTALL_ROOT}/dev/snd                 &&

if  [  !  -f   ${INSTALL_ROOT}/etc/modules.d/alsa  ];  then
  mkdir   -p   ${INSTALL_ROOT}/etc/modules.d  &&
  mconf
fi  &&

dconf   &&

MOD="${INSTALL_ROOT}/etc/modules.conf"
INC="include  ${TRACK_ROOT}/etc/modules.d/alsa"
    
grep    -q  "$INC"      $MOD  ||
echo        "$INC"  >>  $MOD  &&
depmod  -a
