#!/sbin/runscript
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-src/rc-scripts/init.d/serial,v 1.12 2004/08/12 03:11:16 vapier Exp $

depend() {
	need localmount
}

moduleinserted() {
	local res="$(grep 'serial' /proc/modules | cut -f1 -d" ")"
	if [ "${res}" ]
	then
		if [ "${res}" = "serial" ]
		then
			return 1
		fi
	fi
}

setports() {
	#if serial module exists, and it's not inserted, insert it permanently
	if [ -f /lib/modules/$(uname -r)/misc/serial.o ]
	then
		moduleinserted;
		if [ "$?" -eq 0 ]
		then
			/sbin/insmod serial 1>&2
		fi
	fi

	if [ -e /etc/serial.conf ]
	then
		grep -v "^#\|^ \|^$" /etc/serial.conf | while read device args
			do
				ebegin "Setting $device to $args"
				${SETSERIAL} -b $device $args 1>&2
				if [ "$?" -gt 0 ]
				then
					eend 1 "Error setting serial port $device $args"
					no_errs=0
				else
					eend 0
					done="${done} /dev/$1"
				fi
			done
	fi
}

start() {
	SETSERIAL="/bin/setserial"
	no_errs=1
	done=""
	setports
	return
}

# vim:ts=4
