#!/sbin/runscript
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/sys-apps/setserial/files/serial,v 1.1 2005/02/21 15:53:03 vapier Exp $

depend() {
	need localmount
}

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

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
