#!/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). 

# Source function library.
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: '
        if test -f /usr/sbin/soundoff
	then
	   /usr/sbin/soundoff
	fi
	exit 0
        ;;
  restart)
        $0 stop
        $0 start
        ;;
  *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
esac
