#!/bin/sh
#Tag 0x9085

#**************************************************************************
#*                                                      *
#*          Copyright (c) 1996 Silicon Graphics, Inc.               *
#*                  All Rights Reserved                         *
#*                                                      *
#*       THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI           *
#*                                                      *
#* The copyright notice above does not evidence any actual of intended    *
#* publication of such source code, and is an unpublished work by Silicon *
#* Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is *
#* the property of Silicon Graphics, Inc. Any use, duplication or       *
#* disclosure not specifically authorized by Silicon Graphics is strictly *
#* prohibited.                                              *
#*                                                      *
#* RESTRICTED RIGHTS LEGEND:                                    *
#*                                                      *
#* Use, duplication or disclosure by the Government is subject to       *
#* restrictions as set forth in subdivision (c)(1)(ii) of the Rights in   *
#* Technical Data and Computer Software clause at DFARS 52.227-7013,      *
#* and/or in similar or successor clauses in the FAR, DOD or NASA FAR     *
#* Supplement. Unpublished - rights reserved under the Copyright Laws of  *
#* the United States. Contractor is SILICON GRAPHICS, INC., 2011 N.       *
#* Shoreline Blvd., Mountain View, CA 94039-7311                    *
#**************************************************************************

# Where do we want to go
URL="file:/usr/demos/General_Demos/boink/data/intro.html"


#
# Default place to start up Netscape at,
# currently assuming a 1280x1024 display
#
#GEOMETRY should be of the form "1250x970+15+0"
GEOMETRY="1250x970+15+0"

NETSCAPE_3PREF="/usr/demos/Demo_Interfaces/Web/common/preferences"
NETSCAPE_4PREF="/usr/demos/Demo_Interfaces/Web/common/preferences.js"
NETSCAPE_4XDEFAULTS="/usr/demos/Demo_Interfaces/Web/common/Xdefaults"

remove_lock() {
   if [ -l $HOME/.netscape/lock ]
   then
      rm $HOME/.netscape/lock
   fi
}

launch_ns() {
   remove_lock
   #
   # since an $HOME/.Xdefaults file overrides Netscape's -geometry option
   # we have to use -xrm which overrides .Xdefaults. (The demos account provides
   # an $HOME/.Xdefaults file so that Netscape is a little larger than normal.)
   # Some users may have also specified Netscape geometry in their $HOME/.Xdefaults file.
   # So do the right thing and specify what we want.
   #
   /usr/bin/X11/netscape -xrm "Netscape.Navigator.geometry: $GEOMETRY" $URL &
}

# Parse netscape -v output
NSVERSION=`/usr/bin/X11/netscape -version 2>&1 | /usr/sbin/perl -ne 'if ( /^\w*\s*\w*\s*(\d+\.\w+).*$/ ) {print "$1\n";}'`

case "$NSVERSION" in

   # If not Communicator then at least try Netscape with Navigator's environment
   3*)
       # If USER null, assume script is being run from the Web Interface
       # under the USER name as nobody. So we need to set up a fake home
       # directory. 
       if [ -z "$USER" ]
       then
          HOME="/tmp/nobodyNetscapeHome" ; export HOME
          if [ ! -d $HOME ]
          then
             mkdir -p $HOME/.netscape/cache
             if [ -f $NETSCAPE_3PREF ]
             then
                cp $NETSCAPE_3PREF $HOME/.netscape
             fi
          fi
          launch_ns

       # If USER is set then assume this script was run from the desktop
       # Either demos or another user
       else
          launch_ns
       fi
       ;;

   *)
       # If USER null, assume script is being run from the Web Interface
       # under the USER name as nobody. So we need to set up a fake home
       # directory, else run netscape4
       if [ -z "$USER" ]
       then
          HOME="/tmp/nobodyNetscapeHome" ; export HOME
          if [ ! -d $HOME ]
          then
             mkdir -p $HOME/.netscape/cache $HOME/.netscape/archive
             # the preferences file has browser width and height which
             # netscape 4 will respect, but no way for absolute positioning
             # in the preferences
             if [ -f $NETSCAPE_4PREF ]
             then
                cp $NETSCAPE_4PREF $HOME/.netscape
             fi
             launch_ns

          # If $HOME is set up check to see if it has the old preferences file and replace it
          else
             if [ -f $HOME/.netscape/preferences ]
             then
                rm $HOME/.netscape/preferences
             fi
             if [ ! -f $HOME/.netscape/preferences.js ]
             then
                if [ -f $NETSCAPE_4PREF ]
                then
                   cp $NETSCAPE_4PREF $HOME/.netscape
                fi
             fi
             launch_ns
          fi
       else
          launch_ns
       fi
       ;;

esac
