#!/bin/bash
#
#       /etc/rc.d/init.d/oss
#
# Starts the OSS sound driver
#
# chkconfig: 2345 80 20
# description: Open Sound System for Linux (OSS/Linux) is a \
# commercial quality sound driver distributed by 4Front Technologies \
# (http://www.opensound.com).

### BEGIN INIT INFO
# Provides: oss
# Required-Start: $local_fs $remote_fs 
# Should-Start: 
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start OSS
### END INIT INFO

# Source function library.
if test -f /lib/lsb/init-functions
then
. /lib/lsb/init-functions
fi

if test -f /etc/rc.d/init.d/functions
then
. /etc/rc.d/init.d/functions
fi

# Add oss configuration.
. /etc/oss.conf

RETVAL=0

#
#       See how we were called.
#
case "$1" in
  start)
        # Check if OSS is already running
        echo -n 'Starting Open Sound System: '
        if ! test -f /usr/sbin/soundon
	then
		exit 0
	fi

	if test -f $OSSLIBDIR/starting
	then
		ls -l $OSSLIBDIR/starting
		echo Previous start of OSS crashed the system
		echo Please resolve the situation and remove file
		echo \"$OSSLIBDIR/starting\". Then start OSS by
		echo running soundon
		exit 0
	fi

	if ! /usr/sbin/soundon
	then
	  echo Starting OSS failed
	fi
	rm -f $OSSLIBDIR/starting
        ;;
  stop)
        echo -n 'Stopping Open Sound System: '

	/usr/sbin/savemixer
	exit 0
        ;;
  restart)
        $0 stop
	/usr/sbin/soundoff
        $0 start
        ;;
  *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
esac
