#! /bin/sh
#
### BEGIN INIT INFO
# Provides:             etc-setserial
# Required-Start:       checkfs
# Required-Stop:        $remote_fs
# Default-Start:        S
# Default-Stop:         0 1 6
# Short-Description:    controls configuration of serial ports
# Description:          Set and/or report the configuration information
#                       associated with a serial port. This information
#                       includes what I/O port and which IRQ a particular
#                       serial port is using.
### END INIT INFO
# This file uses settings from /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 /etc/init.d/setserial file.
#

SETSERIAL=/bin/setserial

# 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/serial.conf "
        while read device args
        do
               case "$device" in
                   ""|\#*)
                       continue
                       ;;
               esac
           ${SETSERIAL} -z $device $args
           ${SETSERIAL} -bg $device
        done < /etc/serial.conf
  fi
fi

