#!/bin/sh
#
# Run blast process
#

umask 077

start() {
	echo "Starting USB blast process"

	# Some platforms may not show USB devices right away. Arbitrary timeout.
	echo "Sleeping for 10 seconds before attempting to discover USB devices."
	sleep 10

	# Search for first usb drive with a blast.sh script
	for x in a b c d e f g h i j k l m; do
		readlink /sys/class/block/sd${x}1 | grep usb > /dev/null 2>&1
		if [ $? != 0 ]; then
			continue;
		fi;
		mkdir /mnt/usb/ > /dev/null 2>&1
		mount -o ro /dev/sd${x}1 /mnt/usb/
		if [ -e /mnt/usb/blast.sh ]; then
			/mnt/usb/blast.sh
			break;
		fi
	done
}

stop() {
	true
}

restart() {
	stop
	start
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart|reload)
        restart
        ;;
  *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
esac

exit $?
