#!/bin/sh

if [ "$1" = "stop" ]; then
	echo "1394-reset does nothing on system stop"
	exit 0
fi

VER=`uname -r`
echo
echo "---- Restart 1394 Script $VER ----"

echo "Current modules are ..."
lsmod | grep 1394

echo "Removing modules ..."
echo "removing eth1394"
rmmod eth1394
echo "removing dv1394"
rmmod dv1394
echo "removing raw1394"
rmmod raw1394
echo "removing video1394"
rmmod video1394
echo "removing ohci1394"
rmmod ohci1394
echo "removing ieee1394"
rmmod ieee1394

# Work out which kernel and file extension to use
TWOSIX=`echo $VER | grep "2\.6"`
if [ ! "$TWOSIX" = "" ]; then
  EXT=ko
else
  EXT=o
fi

echo "Restarting modules ..."
MOD=/lib/modules/$VER/kernel/drivers/ieee1394
insmod $MOD/ieee1394.$EXT

# Install the ohci module, this could cause a problem
insmod $MOD/ohci1394.$EXT attempt_root=1 &> /dev/null
if [ ! "$?" = "0" ]; then
	# We have a newer kernel which doesn't support attempt_root
	echo "Module ohci1394.$EXT failed to load so retrying with no attempt_root"
	insmod $MOD/ohci1394.$EXT

	if [ ! "$?" = "0" ]; then
		echo "Cannot load module ohci1394.$EXT due to a fatal error!"
		beep
		exit 1
	fi
fi

# Load the rest of the modules in now
insmod $MOD/video1394.$EXT
insmod $MOD/raw1394.$EXT

echo
echo "Success! Module list is now ..."
lsmod | grep 1394

echo "Waiting 1 second for 1394 bus to settle ..."
sleep 1s

echo "---- Ending 1394 Script ----"
echo
