#!/bin/bash

SPATH=$_
if [ -L $SPATH ];then
    SPATH=`readlink $SPATH`
fi

self=`dirname $SPATH`
self=`dirname $self`
self=`dirname $self`
self=`(cd $self ; pwd)`

usage(){
    U1="usage: `basename $0` [-setcookie <cookie>] [-nocookie] "
    U2="[-nettick <tick>] [-vsn <OTP version>] node trace [time [msgs [proc]]]"
    echo $U1 $U2
    exit
}

VSN=""
XTRA=""
echo=""

while [ -n "$1" ]
  do
  case $1 in
      "--help"|"-h"|"-?")
          usage
          ;;
      "-vsn"|"-version")
          VSN="+R "$2
          shift
          ;;
      "-nettick"|"-tick")
          nettick="-kernel net_ticktime $2"
          shift
          ;;
      "-cookie"|"-setcookie")
          cookie="-setcookie $2"
          shift
          ;;
      "-debug")
          echo=echo
          ;;
      "-nocookie")
          cookie=""
          ;;
      "-*")
          echo unrecognized flag $1
          usage
          ;;
      *)
          XTRA=" $XTRA $1"
          ;;
  esac
  shift
done

if [ -z "$XTRA" ]; then usage; fi

PATHS="-pa $self/ebin"
name="redbug_"$$
DISTR="-noshell -hidden -sname $name $cookie $nettick"
START="-run redbug unix"

$echo erl $VSN $DISTR $PATHS $START $XTRA

if [ "$?" -eq "1" ]; then usage; fi
