#!/bin/bash
#
# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: package/.../serpnp/serpnp.init
# Copyright (C) 2004 - 2006 The T2 SDE Project
#
# More information can be found in the files COPYING and README.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. A copy of the
# GNU General Public License can be found in the file COPYING.
# --- SDE-COPYRIGHT-NOTE-END ---
#
# Desc: Serial PNP at bootup
# Runlevel: 20 rcX rc3 rc3 rc5
#

main_begin

    block_begin(start, `Serial PNP probing.')
	title "Searching for serial mices ..."
	tmp=$(mktemp)
	echo -n "Testing "
	for x in /dev/ttyS* ; do
		[ -e $x ] || continue
		echo -n "$x "
		serpnp $x > $tmp
		echo -n $(grep -B 1 "CLASS:" $tmp)
		if grep -q "CLASS: MOUSE" $tmp; then
			mode=$(grep "CLASS:" $tmp | cut -d' ' -f3)
			echo "\nStarting: inputattach $mode $x"
			inputattach $mode $x &
			echo -n "Testing "
		fi
	done
    block_end

    block_begin(stop, `Serial PNP stopping possible inputattach instances.')
	killall -15 inputattach 2>/dev/null
    	status
    block_end

main_end