#! /bin/sh
#
# This file uses /etc/serial.conf to configure the serial devices.
# This file only exists if you chose to configure the serial devices
# by hand yourself. Otherwise serial configuration happens later on
# using the setserial rc file.
#

SETSERIAL=/bin/setserial
modconf=/var/run/setserial.conf

# If the serial executable has been removed abort the configuration
[ -x ${SETSERIAL} ] || exit 0

#
# Support devfs when it arrives.
#
if /bin/ls /dev/tts 2> /dev/null 1>&2 ; then
	ALLDEVS="/dev/tts/*"
else
	# No devfs - old naming scheme
	ALLDEVS="/dev/ttyS?"
	if /bin/ls /dev/ttyS?? 2> /dev/null 1>&2 ; then
		ALLDEVS="$ALLDEVS /dev/ttyS??"
	fi
fi

#
# Handle System V init conventions...
#
case $1 in
start | restart | force-reload )
	action="start";
	;;
stop)
	action="stop";
	;;
modload)
	action="modload";
	;;
modsave)
	action="modsave";
	;;
*)
	action="start";
esac

#
# Is it Start
#

if test $action  = start ; then

  if test -f /etc/serial.conf ; then
        echo "Loading the saved-state of the serial devices from /etc... "
        while read device args
        do
               case "$device" in
                   ""|\#*)
                       continue
                       ;;
               esac
           ${SETSERIAL} -z $device $args
           ${SETSERIAL} -bg $device
        done < /etc/serial.conf
  fi
fi

