#!/sbin/runscript
# Copyright 1999-2003 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2
# $Header: /home/cvsroot/gentoo-src/rc-scripts/init.d/serial,v 1.8 2003/01/14 06:12:27 azarah Exp $


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

setport() {
	# arguments: device, irq, port, args

	#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

	ebegin "Setting /dev/$1"
	${SETSERIAL} -b /dev/$1 irq $2 port $3 $4 1>&2
	if [ "$?" -gt 0 ]
	then
		eend 1 "Error setting serial port $1 to irq $2 port $3 (args: $4)"
		no_errs=0
	else
		eend 0
		done="${done} /dev/$1"
	fi
}

depend() {
	need localmount
}

start() {
	if [ -e /etc/rc.d/config/serial ]
	then
		source /etc/rc.d/config/serial
	else
		return
	fi

	SETSERIAL="/sbin/setserial"

	no_errs=1
	done=""
	setports
	return
}


# vim:ts=4
