#!/bin/sh

# browser.sh Version 01/20/04
# Open a browser window to a specific URL


# Synopsis: browser.sh  URL

# URL must be fully qualified. For example, for a web site
#     http://home.cc.umanitoba.ca/~frist
#
# For a file,
#     file:///home/psgendb/public_html/programs.html
#
#     That is, the full path to the file must be specified.

# Find out if there is a copy of netscape already running.
# If there is, call netscape using -remote option, otherwise
# launch a new netscape job.
# See http://wp.netscape.com/newsref/std/x-remote.html

# ACE_Browser is an environment variable telling
# the full path to the script that runs netscape
# It has been commented out below to allow it to be set
# by the user's environment
#ACE_Browser='/usr/local/netscape7/netscape'

SEARCH_STRING='netscape'

case "$BIRCH_PLATFORM" in
  sun)
    PS_CMD='ps -u'
    RM_CMD=/usr/bin/rm
    ;;
  linux-intel)
    PS_CMD='ps U'
    RM_CMD=/bin/rm
    ;;
  *)
    PS_CMD='ps -u'
    RM_CMD=rm
    ;;
esac

USERID=`whoami`
URL=$1

TEMPFILE=/tmp/browser.sh.$$
$PS_CMD $USERID > $TEMPFILE

COUNT=`grep -c $SEARCH_STRING < $TEMPFILE`

if [ "$COUNT" -eq "0" ]
   then
      $ACE_Browser $URL 
   else
      REMOTESTRING="openURL($URL,new-window)"
      $ACE_Browser -remote $REMOTESTRING 
fi

$RM_CMD $TEMPFILE
