#!/bin/bash

if [  `lsmod|grep apci3600|wc -l` -eq 0 ];
then
	echo "The apci3600 driver has to be loaded. (modprobe apci3600 or insmod ../acpi3600.o or .ko)"
	exit 1;
fi

if [ `id -u` -ne 0 ];
then
	echo "This script requires root privileges"
	exit 2 
fi

if [ $# -gt 1 ];
then
	echo -e "Usage : $0 [list_of_sample(s)_to_launch]\nThe list looks like 0,3,6,9 e.g. you will start $0 0,3,6,9"
	exit 3;
elif [ $# -eq 0 ];
then
	echo "This script will launch all the samples"
	SCRIPTS="0 3 6 7 8 9 10 11 12 13"

else
	echo "This script will launch the sample(s) $1"
	SCRIPTS=`echo $1|sed s/,/\ /`
fi 



if [ `uname -r|cut -c 3` -eq 6 ];
then
	EXT="ko"
else
	EXT="o"
fi

for SCRIPT in $SCRIPTS;
do
	LEN=`echo -n "$SCRIPT"|wc -m`
	if [ $LEN -eq 1 ];
	then
		SCRIPT=0$SCRIPT
	fi
	if [ -e ./sample$SCRIPT.$EXT ];
	then
		echo "Loading sample$SCRIPT"
		insmod ./sample$SCRIPT.$EXT
		rmmod sample$SCRIPT
	else
		echo "sample$SCRIPT not found !"
	fi
done


echo "Now, you can check the /var/log/messages, to see output of the sample(s)"
