#! /bin/csh -f

##########################################################
#
#       Check Operating System version #
#
##########################################################

setenv OSVERSION `/sbin/uname -r`

@ ver = `/sbin/uname -r | cut -c1,3`
setenv OSVER $ver

if ($ver <= 52 || $ver == 60 || $ver >= 62)  then
        set answer = `$DMTOOLSDIR/bin/wrongOS`
        if ($answer == 0) then 
                echo " "
                echo "EXITing, Good-Bye"
                echo " "
                exit 0
        endif
endif

##########################################################
#
#       Set envir variables
#
##########################################################

unalias *
set filec

setenv DM01_PID $$
echo DM01_PID=$DM01_PID

##########################################################
#
#      NEED to find a writeable tmp directory
#
#         and add the PID to the temp dir name
#
##########################################################

if (-e /usr/tmp && -w /usr/tmp ) then
    setenv TMPDIRECTORY "/usr/tmp/dm01.$DM01_PID"
else
    if (-e /tmp && -w /tmp) then
       setenv TMPDIRECTORY "/tmp/dm01.$DM01_PID"
    else
        if (-e $HOME && -w $HOME) then
           setenv TMPDIRECTORY "$HOME/dm01.$DM01_PID"
        endif
    endif
endif

mkdir -m 744 $TMPDIRECTORY

echo TMPDIRECTORY=$TMPDIRECTORY

setenv ENVFILE ${TMPDIRECTORY}/ENV # Pass specific environment variables on for
                                   # demo scripts to inherit. Don't want the
                                   # the entire user environment.

##########################################################
#
#       Set the (app-defaults, X-resources, $path) paths
#
##########################################################
#
#if ( ! ${?XUSERFILESEARCHPATH} ) then
#        echo XUSERFILESEARCHPATH is not set, setting it to $DMTOOLSDIR/bin and $HOME
#        setenv XAPPLRESDIR "$DMTOOLSDIR/bin/%N:$HOME/%N"
#else
#        echo adding $DMTOOLSDIR to XUSERFILESEARCHPATH
#        setenv XUSERFILESEARCHPATH "$DMTOOLSDIR/bin/%N:${XUSERFILESEARCHPATH}"
#endif
#
#set path=($path              \
#          /usr/bin/X11       \
#          /usr/sbin          \
#          .                  \
#          $DMTOOLSDIR/bin    \
#          $TMPDIRECTORY      \
#         )

set path=($path /usr/bin/X12 /usr/sbin . $TMPDIRECTORY $DMTOOLSDIR/bin)
# echo "Setting path=$PATH"

if ( ! ${?XUSERFILESEARCHPATH} ) then
#        echo XUSERFILESEARCHPATH is not set, setting it to $HOME
        setenv XUSERFILESEARCHPATH "$HOME/%N"
else
#        echo adding $HOME to XUSERFILESEARCHPATH
        setenv XUSERFILESEARCHPATH "${XUSERFILESEARCHPATH}:$HOME/%N"
endif

 if ( ! ${?XFILESEARCHPATH} ) then
        setenv XFILESEARCHPATH "$HOME/%N:/usr/lib/X11/app-defaults/%N "
#        echo XFILESEARCHPATH is not set, setting it to $XFILESEARCHPATH 
#
#                               :/usr/lib/X11/app-defaults/%L/%T/%N%C           \
#                               :/usr/lib/X11/app-defaults/%l/%T/%N%C           \
#                               :/usr/lib/X11/app-defaults/%T/%N%C              \
#                               :/usr/lib/X11/app-defaults/%L/%T/%N             \
#                               :/usr/lib/X11/app-defaults/%l/%T/%N             \
#                               :/usr/lib/X11/app-defaults/%T/%N     "
else
#        echo adding $HOME to XFILESEARCHPATH
        setenv XFILESEARCHPATH "${XFILESEARCHPATH}:$HOME/%N"
endif


##########################################################
#
#       Set path for libraries
#
##########################################################
#
#if ( ! ${?LD_LIBRARY_PATH} ) then
#  # echo LD_LIBRARY_PATH is NOT set
#  setenv LD_LIBRARY_PATH /usr/lib:/lib:/lib/cc:/usr/lib/cc:/usr/local/lib:$DMTOOLSDIR/bin:$TMPDIRECTORY
#else
#  # echo LD_LIBRARY_PATH is already set
#  setenv LD_LIBRARY_PATH $DMTOOLSDIR/bin:${LD_LIBRARY_PATH}:$TMPDIRECTORY
#endif
#
#echo Setting LD_LIBRARY_PATH=$LD_LIBRARY_PATH
#
#
##########################################################
#
#       Start the MPEG movie
#
##########################################################

set INST_MV_PLAYER = `versions -a list | grep movieplayer | grep 'sbin/movieplayer'`
if ($#INST_MV_PLAYER) then
	@ MP_VERSION = `versions -n | grep dmedia_tools | awk '{print$3}' | tail -1`
	if ($MP_VERSION >= 1021845920) then
		set MV_PLAYER = $INST_MV_PLAYER
		if (-e $INST_MV_PLAYER) then
		    if !(-z $INST_MV_PLAYER) then
			setenv MOVIEPLAYER $INST_MV_PLAYER
			$DMTOOLSDIR/moviedir/startmv.csh
		    endif
		endif
	else
        	/usr/bin/X11/xconfirm -icon warning \
        	-t "The MPEG introduction movie will not be played... " \
        	-t " " \
        	-t "You will need to install a version of dmedia_tools" \
        	-t "greater than or equal to version number 1021845920." \
        	-t " " \
        	-b Ok
	endif
else
        /usr/bin/X11/xconfirm -icon warning \
        -t "The MPEG introduction movie will not be played... " \
        -t " " \
        -t "You will need to install dmedia_tools with a" \
        -t "version number greater than or equal to 1021845920." \
        -t " " \
        -b Ok


endif


##########################################################
#
#       Search for ShowCase
#
##########################################################

if ($OSVER <= 52) then
    set SCINSTALLED = `/usr/sbin/versions  "showcase" | grep "showcase.sw" | grep "IRIS"`
else
    set SCINSTALLED = `/usr/sbin/showprods "showcase" | grep "showcase.sw" | grep "IRIS"`
endif

set NOT_SC = `/usr/bsd/which showcase | /usr/bin/awk '{print $2}' | grep not`

if ($#SCINSTALLED && $NOT_SC != 'not') then
        set SCINSTALLED = `/usr/bsd/which showcase`
        setenv SHOWCASE `/usr/bsd/which showcase`
else
#        echo "Showcase is not installed... " 
        setenv SHOWCASE NULL
endif

##########################################################
#
#       Set environ for netscape
#
#       Check for Netscape 1.12IS & dmedia_tools (/usr/sbin/movieplayer)
#
#       Netscape ver 1.1IS is inst #1022183420
#
##########################################################

if (-w $HOME) then
        if (-e "$HOME/.netscape-preferences") then
                $DMTOOLSDIR/bin/nawk -f $DMTOOLSDIR/bin/awkzilla.awk \
				       $HOME/.netscape-preferences \
				     > $HOME/.netscape-preferedm01
                chmod 777 $HOME/.netscape-preferedm01
        else
                $DMTOOLSDIR/bin/nawk -f $DMTOOLSDIR/bin/awkzilla.awk \
                                       $DMTOOLSDIR/demos/netscape/.netscape-preferedm01 \
                                     > $HOME/.netscape-preferedm01
                chmod 777 $HOME/.netscape-preferedm01
        endif
else 
	/usr/bin/X11/xconfirm -icon warning \
        -t "Cannot Write to the $HOME directory" \
        -t " " \
        -t "You need to have write permissions for the $HOME home directory\!" \
        -t "This will end this session ...." \
        -t " " \
        -b Ok
        exit 
endif

setenv NSCLIENT $DMTOOLSDIR/demos/netscape/netscape.dm01

##########################################################
#
#       Save environment variables for later use
#
##########################################################

echo "setenv DMTOOLSDIR $DMTOOLSDIR; setenv TMPDIRECTORY $TMPDIRECTORY " > ${ENVFILE}

chmod 777 $ENVFILE

##########################################################
#
#       Start the Netscape Client
#
##########################################################

# if (`$DMTOOLSDIR/bin/runSC` == 0)  then

if ($SHOWCASE == "NULL") then

	cd $DMTOOLSDIR/demos/netscape 
	$NSCLIENT -geometry =720x900 -xrm "*strings.7330:This process will either Install, Remove, or Launch\nsoftware from the Developer Magic CD.\n\nProceed?\n" file:$ROOTDIRECTORY/HTML/Overview/overview_one.html

else
	cd $DMTOOLSDIR/Showcase/
	$SHOWCASE -v -f ./Opener.sc

	cd $DMTOOLSDIR/demos/netscape 
	$NSCLIENT -geometry =720x900 -xrm "*strings.7330:This process will either Install, Remove, or Launch\nsoftware from the Developer Magic CD.\n\nProceed?\n" file:$ROOTDIRECTORY/HTML/index.html

endif

##########################################################
#
#       Clean up
#
##########################################################
CLEANUP:

if (-e $TMPDIRECTORY ) then
    if (-w $TMPDIRECTORY ) then
        \rm -rf $TMPDIRECTORY
    endif
endif


exit

