#!/bin/sh
# script to start the driver / create the /dev node(s)
#
#   Copyright (C) 2000  Roland Schwarz
#
#   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; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#   
#   The author can be reached by email: roland.schwarz@riegl.com 

RCDLINKS="S,S60"

module="riport.o"
device="riport"
numdevs=1
group="root"
mode="664"

case "$1" in
start)
	echo -n "Starting riport(s) ... "
	[ `cat /proc/devices | sed -n "s/.*\($device\)/\1/p"` ] || \
	( [ -r $module ] && /sbin/insmod -f $module ) || \
	( [ -r /lib/modules/$module ] && /sbin/insmod /lib/modules/$module ) || exit 1
	#/sbin/insmod $module || exit 1
	rm -f /dev/${device}
	rm -f /dev/${device}[0-9]*
	#major=`cat /proc/devices | awk "\\$2==\"$device\" {print \\$1}"`
	major=`cat /proc/devices | sed -n "s/\(.*\)$device/\1/p"`
	mknod /dev/${device} c $major 0
	n=0
	while [ $n -lt $numdevs ]
	do
		mknod /dev/${device}$n c $major $n
		n=`expr $n + 1`
	done
	chgrp $group /dev/${device}?
	chmod $mode /dev/${device}?
	echo "done."
	;;
stop)
	echo -n "Stopping riport(s) ... "

	rm -f /dev/${device}
	rm -f /dev/${device}[0-9]*
	/sbin/rmmod $device || exit 1
	echo "done."
	;;
*)
	echo "Usage riport {start|stop}"
	exit 1
esac
