#!/bin/ksh -p
#
# netscape
#
# Copyright 2000-2002 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
#
# ident "12/11/02 @(#)netscape	1.116"

nsargs="$@"
OS_VERSION=`uname -r`
MACH_CLASS=`uname -m`
NS_VERSION="7.0"
SUN_BLD_DATE="(2002.12.11)"
SUN_BLD_NO="7.0_09e"
SUN_BLD_MOZTAG="mozilla20020913-00:05:00"
NS_VERSION_STRING="Netscape $NS_VERSION $SUN_BLD_DATE Bld$SUN_BLD_NO [$SUN_BLD_MOZTAG]"

PRG=`whence $0` >/dev/null 2>&1
progname=`/usr/bin/basename $0`
proc=`/usr/bin/uname -p`
BASEDIR=`/usr/bin/dirname "$PRG"`/

# Resolve symlinks. See 4152645.
while [ -h "$PRG" ]; do
	ls=`/usr/bin/ls -ld "$PRG"`
	link=`/usr/bin/expr "$ls" : '^.*-> \(.*\)$'`
	if /usr/bin/expr "$link" : '^/' > /dev/null; then
	prg="$link"
	else
	prg="`/usr/bin/dirname $PRG`/$link"
	fi
	PRG=`whence "$prg"` > /dev/null 2>&1
	BASEDIR=`/usr/bin/dirname "$PRG"`/
done


#
# merging 4 netscape.* scripts into one;
# use RUNMODE to indicate running mode
# ns only 0; debug 1
# 
NS=0
NSDEBUG=1
RUNMODE=0

 
setup_basic_run_env(){
	NSLANG="en-US";
	NSREGION="US";

	L10NSCRIPT="$BASEDIR/scripts/nslocale-config.$LANG.sh"

	if [ -x "$L10NSCRIPT" ]; then
		NSLANG=`$L10NSCRIPT -UILocale`;
		NSREGION=`$L10NSCRIPT -contentLocale`;
	fi
	for i in $nsargs
	do
		if [ $i = "-UILocale" ]; then
			NSLANG=""
		fi
                if [ $i = "-contentLocale" ]; then
                        NSREGION=""
                fi
	done
        if [ ! -z "$NSREGION" ]; then
                nsargs="-contentLocale $NSREGION $nsargs"
        fi
	if [ ! -z "$NSLANG" ]; then
		nsargs="-UILocale $NSLANG $nsargs"
	fi

	
	#
	# set up basic env
	#
	LIBDISTDIR=/usr/sfw/lib:$BASEDIR/dist/lib
	ARCH=`uname -p`
	JDKHOME=$BASEDIR/java
	if [ -n "$LD_LIBRARY_PATH" ]; then
		LD_LIBRARY_PATH=/usr/sfw/lib:$JDKHOME/lib/$ARCH/client:$JDKHOME/lib/$ARCH:/usr/lib:$LD_LIBRARY_PATH
	else	
		LD_LIBRARY_PATH=/usr/sfw/lib:$JDKHOME/lib/$ARCH/client:$JDKHOME/lib/$ARCH:/usr/lib
	fi
	LD_LIBRARY_PATH=$JDKHOME/lib:$JDKHOME/lib/$ARCH/native_threads:$LD_LIBRARY_PATH
	LD_LIBRARY_PATH=$LIBDISTDIR:$LD_LIBRARY_PATH

	if [ "$MACH_CLASS" = "sun4u" ]; then
	    if [ -n "$LD_LIBRARY_PATH" ]; then
		LD_LIBRARY_PATH=$BASEDIR/sun4u:$LD_LIBRARY_PATH
	    else
		LD_LIBRARY_PATH=$BASEDIR/sun4u
	    fi
	fi
	PATH=$BASEDIR/java/bin:$PATH
	PATH=/bin:$PATH
	export LD_LIBRARY_PATH
	export PATH
}


print_extra_help_info(){
    echo "\t-composer \t Start with editor. Same as -edit"
    echo "\t-messenger \t Start with mail. Same as -mail"
    echo "\t-discussions \t Start with mail. Same as -news"
    echo "\t-debug \t Show detail debugging information"
    echo "\t-sunVersion \t Show Sun Netscape Version information"
}

for arg
do
    
    case "$arg" in 
    -debug) 
	#echo "*** debug"
	RUNMODE=`expr $RUNMODE + $NSDEBUG`
    ;;
    -help | -h)
	setup_basic_run_env
	$BASEDIR/.netscape $nsargs
	print_extra_help_info
	exit
    ;;
    -version | -v)
	setup_basic_run_env
	$BASEDIR/.netscape $nsargs
	exit
    ;;
    -composer)
	nsargs="$nsargs -edit"
    ;;
    -messenger)
	nsargs="$nsargs -mail"
    ;;
    -discussions)
	nsargs="$nsargs -news"
    ;;
    #By default on unix, 
    #the splashscreen would not appear before launching.
    #-no-about-splash)
	#nsargs="$nsargs -splash"
    #;;
    -display)
	nsargs="$nsargs --display"
    ;;
    -CreateProfile)
        setup_basic_run_env
        $BASEDIR/.netscape $nsargs
        exit
    ;;
    -sunVersion)
	echo "Sun Netscape $NS_VERSION"
	echo "Build Date: $SUN_BLD_DATE"
	echo "Build: $SUN_BLD_NO"
	echo "Mozilla Tag: $SUN_BLD_MOZTAG"
        exit
    ;;
    esac
done

#echo "RUNMODE=" $RUNMODE


run_netscape () {

	#echo "start calling run_netscape"
	#
	# print out running mode
	#	
	case "$RUNMODE" in
	$NSDEBUG)
	    echo "------- Running Netscape $NS_VERSION debug mode-------"
	    echo ""
	    ;;
	esac

	#
	# Print out some system information
	#
	if [ "$RUNMODE" = "$NSDEBUG" ]; then

	    $BASEDIR/debuginfo.sh
	    $BASEDIR/checkpatches.sh
    	fi;

	case "$OS_VERSION" in
	"5.7" | "5.8" | "5.9" | "5.10") ;;
	 *) 
		echo ""
		echo "ERROR: Netscape $NS_VERSION requires Solaris 7 or later"
		echo ""
		exit
		;;
	esac

	
	setup_basic_run_env

	(if [ "$RUNMODE" = "$NSDEBUG" ]; then \
		$BASEDIR/.netscape $nsargs  ; \
	else
	    $BASEDIR/.netscape $nsargs >/dev/null 2>/dev/null ;\
	fi; )
 	
}

if ( test -d $HOME/.mozilla ) then
	if ( test ! -f $HOME/.mozilla/.version ) then
	    echo ""
	    echo "WARNING: If you have used a previous version of Netscape or "
	    echo "mozilla, you may experience problems due to incompatible preferences. "
	    echo "It is recommended that you move your existing $HOME/.mozilla "
	    echo "directory aside (e.g. % mv $HOME/.mozilla $HOME/.mozilla-old) "
	    echo "and then restart Netscape $NS_VERSION."
	    echo ""
	    echo "Unknown" > $HOME/.mozilla/.version
	fi
	run_netscape
else


	if ( test -f $BASEDIR/license/locale/$LANG/LicensePopup ) then
		$BASEDIR/license/locale/$LANG/LicensePopup
		testnewflag=$?

	else
		$BASEDIR/license/locale/C/LicensePopup
		testnewflag=$?
	fi

	if [ "$testnewflag" = "0" ]; then

 #################################################
##add for mail migration

 PREF_FILE=$HOME/.netscape/preferences.js
if ( test -f $PREF_FILE ) then

    sed '/^user_pref("mail.migration.copyMailFiles", .*);/d' "$PREF_FILE" > "$PREF_FILE.$$"
    mv -f "$PREF_FILE".$$  $PREF_FILE

    PREF_STRING=`grep 'pref("mail.migration.copyMailFilesPopupWindow", false);' "$BASEDIR/defaults/pref/mailnews.js"`

  if [ "$PREF_STRING" ];  then
   echo ""
else
   if ( test -f $BASEDIR/migration/locale/$LANG/CopymailPopup ) then
                $BASEDIR/migration/locale/$LANG/CopymailPopup
                replyflag=$?
   else
                $BASEDIR/migration/locale/C/CopymailPopup
                replyflag=$?
   fi;

   if [ "$replyflag" = "0" ]; then

   cat >>$HOME/.netscape/preferences.js<<EOF
user_pref("mail.migration.copyMailFiles", true);
EOF
  else
  cat >>$HOME/.netscape/preferences.js<<EOF
user_pref("mail.migration.copyMailFiles", false);
EOF
   fi;
 fi;

fi;
################################################

		mkdir -m 700 $HOME/.mozilla
		echo "$NS_VERSION_STRING" > $HOME/.mozilla/.version
		run_netscape
	else
		echo " You have not accepted the Binary Software Evalution Agreement. Exiting"
		echo ""
		exit 1
	fi;
fi

