#!/bin/sh

DIR=$1; shift
cd $DIR
INF=$1; shift
OUT=$1; shift
ERR=$1; shift

if [ ! -f eth0.mac -o ! -f eth1.mac -o -z $DIR -o -z $INF -o -z $OUT -o -z $ERR ]; then
  echo "Directory \"$DIR\" is not a valid uml directory"
  echo "Use start-uml-devices"
  echo "Usage: runlinux dir stdinfile stdoutfile stderrfile [ARGS]"
  echo "eg:  runlinux upro001 /dev/null log.out log.err"
  exit 1
fi

if [ ! -x "$DIR/linux" ]; then
  echo "No executable linux in \$DIR ($DIR)"
  exit 1
fi

if [ -f args ]; then
  ARGS=`cat args`
fi

UML_MEMSIZE="mem=16M"
#trap "" SIGINT SIGHUP SIGQUIT

#echo "$DIR, $INF, $OUT, $ERR"
echo $$ >linux.pid
exec $DIR/linux $UML_MEMSIZE umid=`basename $DIR` \
			eth0=daemon,`cat eth0.mac` \
			eth1=mcast,`cat eth1.mac` \
			ubd4=etc_config.img \
			ubd5=etc_default.img \
			devfs=nomount \
			$ARGS "$@" < $INF > $OUT 2>$ERR
