5 kx #
5 kx # /etc/rc.serial
5 kx # Initializes the serial ports on your system
5 kx #
5 kx # chkconfig: 2345 50 75
5 kx # description: This initializes the settings of the serial port
5 kx #
5 kx # FILE_VERSION: 19981128
5 kx #
5 kx # Distributed with setserial and the serial driver. We need to use the
5 kx # FILE_VERSION field to assure that we don't overwrite a newer rc.serial
5 kx # file with a newer one.
5 kx #
5 kx # XXXX For now, the autosave feature doesn't work if you are
5 kx # using the multiport feature; it doesn't save the multiport configuration
5 kx # (for now). Autosave also doesn't work for the hayes devices.
5 kx #
5 kx
5 kx RCLOCKFILE=/var/lock/subsys/serial
5 kx DIRS="/lib/modules/`uname -r`/misc /lib/modules /usr/lib/modules ."
5 kx PATH=/bin:/sbin:/usr/bin
5 kx DRIVER=serial
5 kx DRIVER_NAME=serial
5 kx MODULE_REGEXP="serial\b"
5 kx
5 kx ALLDEVS="/dev/ttyS?"
5 kx if /bin/ls /dev/ttyS?? >& /dev/null ; then
5 kx ALLDEVS="$ALLDEVS /dev/ttyS??"
5 kx fi
5 kx
5 kx SETSERIAL=""
5 kx if test -x /bin/setserial ; then
5 kx SETSERIAL=/bin/setserial
5 kx elif test -x /sbin/setserial ; then
5 kx SETSERIAL=/sbin/setserial
5 kx fi
5 kx
5 kx #
5 kx # See if the serial driver is loaded
5 kx #
5 kx LOADED=""
5 kx if test -f /proc/devices; then
5 kx if grep -q " ttyS$" /proc/devices ; then
5 kx LOADED="yes"
5 kx else
5 kx LOADED="no"
5 kx fi
5 kx fi
5 kx
5 kx #
5 kx # Find the serial driver
5 kx #
5 kx for i in $DIRS
5 kx do
5 kx if test -z "$MODULE" -a -f $i/$DRIVER.o ; then
5 kx MODULE=$i/$DRIVER.o
5 kx fi
5 kx done
5 kx
5 kx if ! test -f /proc/modules ; then
5 kx MODULE=""
5 kx fi
5 kx
5 kx #
5 kx # Handle System V init conventions...
5 kx #
5 kx case $1 in
5 kx start)
5 kx action="start";
5 kx ;;
5 kx stop)
5 kx action="stop";
5 kx ;;
5 kx *)
5 kx action="start";
5 kx esac
5 kx
5 kx if test $action = stop ; then
5 kx if test -n ${SETSERIAL} -a "$LOADED" != "no" -a \
5 kx `head -1 /etc/serial.conf`X = "###AUTOSAVE###X" ; then
5 kx echo -n "Saving state of serial devices... "
5 kx grep "^#" /etc/serial.conf > /etc/.serial.conf.new
5 kx ${SETSERIAL} -G -g ${ALLDEVS} >> /etc/.serial.conf.new
5 kx mv /etc/serial.conf /etc/.serial.conf.old
5 kx mv /etc/.serial.conf.new /etc/serial.conf
5 kx echo "done."
5 kx fi
5 kx if test -n "$MODULE" ; then
5 kx module=`grep $MODULE_REGEXP /proc/modules | awk '{print $1}'`
5 kx if test -z "$module" ; then
5 kx echo "The $DRIVER_NAME driver is not loaded."
5 kx rm -f ${RCLOCKFILE}
5 kx exit 0
5 kx fi
5 kx if rmmod $module ; then :; else
5 kx echo "The $DRIVER_NAME driver could NOT be unloaded."
5 kx exit 1;
5 kx fi
5 kx echo "The $DRIVER_NAME driver has been unloaded."
5 kx fi
5 kx rm -f ${RCLOCKFILE}
5 kx exit 0
5 kx fi
5 kx
5 kx #
5 kx # If not stop, it must be a start....
5 kx #
5 kx
5 kx if test -n "$MODULE" -a "$LOADED" != "yes" ; then
5 kx if insmod -f $MODULE $DRIVER_ARG ; then
5 kx true
5 kx else
5 kx echo "Couldn't load $DRIVER_NAME driver."
5 kx exit 1
5 kx fi
5 kx fi
5 kx
5 kx if test -f /etc/serial.conf ; then
5 kx if test -n ${SETSERIAL} ; then
5 kx grep -v ^# < /etc/serial.conf | while read device args
5 kx do
5 kx if [ ! "$device" = "" -a ! "$args" = "" ]; then
5 kx ${SETSERIAL} -z $device $args
5 kx fi
5 kx done
5 kx fi
5 kx else
5 kx echo "###AUTOSAVE###" > /etc/serial.conf
5 kx fi
5 kx
5 kx touch ${RCLOCKFILE}
5 kx ${SETSERIAL} -bg ${ALLDEVS}