#!/bin/sh

#
#
echo ""
echo "=================================================================="
echo ""
echo "            Communicator4.73[ja] Japanese  Install  "
echo ""
echo "                      ( Super User Only )"
echo "       Copyright (c) 1999 by Netscape Communications Corp."
echo ""
echo "=================================================================="
echo ""
echo ""

case `uname` in
HP-UX)
	ADLOC="/usr/lib/X11/ja_JP.eucJP/app-defaults";
	CFGLOC="/usr/lib/X11/ja_JP.eucJP/app-defaults";
	MISCLOC="/usr/lib/X11/ja_JP.eucJP/netscape";
	;;  
IRIX)
	ADLOC="/usr/lib/X11/ja_JP.EUC/app-defaults";
	CFGLOC="/usr/lib/X11/ja_JP.EUC/app-defaults";
	MISCLOC="/usr/lib/X11/ja_JP.EUC/netscape";
	;;
SunOS)
	ADLOC="/usr/openwin/lib/locale/ja/app-defaults";
	CFGLOC="/usr/openwin/lib/ja/app-defaults";
	MISCLOC="/usr/openwin/lib/locale/ja/netscape";
	;;
AIX)
	ADLOC="/usr/lib/X11/ja_JP/app-defaults";
	CFGLOC="/usr/lib/X11/ja_JP/app-defaults";
	MISCLOC="/usr/lib/X11/ja_JP/netscape";
	;;
FreeBSD|*)
	if [ "x$LANG" = "x" ] ; then
	    LANG=ja_JP.EUC
	fi
	# Location for the apps-default file
	ADLOC="/usr/X11R6/lib/X11/${LANG}/app-defaults";
	# Location for the netscape.cfg file
	CFGLOC="/usr/lib/X11/${LANG}/app-defaults";
	# Location for some Misc pieces
	MISCLOC="/usr/X11R6/lib/X11/${LANG}/netscape";
	;;
esac

# platform dependent change for resource
nsMotifFSBHacks=True
case `uname` in
FreeBSD)
	nsMotifFSBHacks=False;
	;;
esac

cde_ready=0
if [ -e /usr/dt ] ; then
    cde_ready=1		# CDE was installed
else
    cde_font="-dt-interface system-medium-*-*-S*-*-*-*-*-*-*-*-*";
#    cde_font="-misc-fixed-medium-r-normal--14-*-*-*-*-*-iso8859-1"; #for debug
    result=`xlsfonts -fn $cde_font 2>&1`
    echo $result | grep "unable to open" > /dev/null
    if [ $? = 1 ] ; then # can connect server
	echo $result | grep unmatch > /dev/null
	if [ $? = 1 ] ; then	# not unmatch -> have CDE fonts
	    cde_ready=1
	fi
    fi
fi

echo "Following settings are right for your system?"
echo "If right, type any key to go on."
echo "If not, exit with Ctrl-C and modify this install script to fit your system."
echo ""
echo "	ADLOC   = $ADLOC"
echo "	CFGLOC  = $CFGLOC"
echo "	MISCLOC = $MISCLOC"
if [ $cde_ready = 1 ] ; then
    echo "	We will use CDE(Common Desktop Environment) font."
else
    echo "	We don't have any CDE(Common Desktop Environment) fonts."
fi

read dummy

#
# See if we have to use the lame SYS-V echo command flags.
#
if test "`/bin/echo 'blah\c'`" = "blah\c"
then
        EFLAG="-n"
        ENDER=""
else
        EFLAG=""
        ENDER="\c"
fi
ECHO="/bin/echo ${EFLAG}"
#
# Checking to see if script has been run as root
#
touch /tmp/foo.$$
OWNER="`ls -l /tmp/foo.$$ | awk '{print $3}'`"
rm -f /tmp/foo.$$
if test ! "${OWNER}" = "root"
then
   if test ! "`who am i|awk '{print $1}'`" = "root" 
   then
      if test ! "`whoami`" = "root" 
      then
         if test ! ${USER} = "root" 
         then 
            if test ! ${LOGNAME} = "root" 
            then
               ${ECHO} "Sorry, you need to be root (super user) to run this script."
               exit 0
            fi
         fi
      fi
   fi
fi
GZIP="gzip"
flag=1
while test ${flag} -eq 1
do
        ${GZIP} -h >/dev/null 2>&1
        if test $? -ne 0
        then
                echo ""
                echo "Unable to locate 'gzip' in your path.  Please provide the
fully-qualified"
                echo "directory in which it can be found."
                echo ""
                ${ECHO} "Directory containing the 'gzip' binary: ${ENDER}"
                read GZIP_DIR
                GZIP="${GZIP_DIR}/gzip"
        else
                flag=0
        fi
done                            

if test ! -d ${ADLOC}
   then
      mkdir -p ${ADLOC}
fi
sed "s/-dt-interface system-medium-\*-\*-S\*-\*-\*-\*-\*-\*-\*-\*-\*:/-misc-fixed-medium-r-normal--14-\*-\*-\*-\*-\*-iso8859-1; -misc-fixed-medium-r-normal--14-*-*-*-*-*-jisx0208.1983-0; -misc-fixed-medium-r-normal--14-*-*-*-*-*-jisx0201.1976-0:/;\
s!^\*appDir:.*!*appDir: ${MISCLOC}!;\
s/^\(\*nsMotifFSBHacks:\) .*/\1 ${nsMotifFSBHacks}/;" \
Netscape.ad-ja_euc > ${ADLOC}/Netscape

if test ! -d ${CFGLOC}
   then
      mkdir -p ${CFGLOC}
fi
cp  netscape.cfg ${CFGLOC}/netscape.cfg
if test ! -d ${MISCLOC}
   then
      mkdir -p ${MISCLOC}
fi
cp  about plugins splash LICENSE mail.msg ${MISCLOC}

# Try and find where the English version was installed.
#
# If MOZILLA_HOME is set, assume that's the place
#
if test ! -z "${MOZILLA_HOME}" -a -d ${MOZILLA_HOME}/nethelp
then
	INSTALL_DIR="${MOZILLA_HOME}"
else
	if test -d /opt/netscape/nethelp
	then
	    INSTALL_DIR="/opt/netscape"
	else
	    if test -d /usr/local/netscape/nethelp
	    then
		INSTALL_DIR="/usr/local/netscape"
	    fi
	fi
fi

echo ""
echo "The localized user interface has been installed."
echo ""
echo "The rest of the installation will overwrite some existing"
echo ""
echo "components of the netscape software (in particular NetHelp)."
echo ""

while test -z ""
do
   ${ECHO}  "Do you want to continue? (Y/N): ${ENDER}"
   read choice
   case $choice in
      [yY]) break;;
      [nN]) exit 0;;
   esac
done

if test -z "${INSTALL_DIR}"
then
    echo ""
    echo "Sorry, can't find where the Netscape software was installed."
    echo ""
    echo "Please enter the path to your Install Directory:"
    echo ""
    ${ECHO} "[Netscape Install Directory] : ${ENDER}"
    read TARGET
else
    echo ""
    echo "Please enter the path to your Install Directory."
    echo ""
    echo "Hit return to use the indicated default."
    echo ""
    ${ECHO} "[Install Directory - ${INSTALL_DIR}] : ${ENDER}"
    read TARGET
fi

if test ! -z "${TARGET}"
then
    if test -d ${TARGET}/nethelp
    then
        INSTALL_DIR=${TARGET}
    fi
fi

if test -z "${INSTALL_DIR}"
then
    echo ""
    echo "Sorry, that doesn't look like the correct location."
    echo ""
    echo "Some localized components (NetHelp, etc) can not be installed at this time."
    echo "Re-run this script if you'd like to try again."
else
    if test -f ${INSTALL_DIR}/bookmark.htm
       then
       mv ${INSTALL_DIR}/bookmark.htm ${INSTALL_DIR}/old_bookmark.htm
    fi
    cp bookmark.htm ${INSTALL_DIR}/bookmark.htm
    if test ! -d ${INSTALL_DIR}/old_nethelp
        then
	mv ${INSTALL_DIR}/nethelp ${INSTALL_DIR}/old_nethelp
    fi
    mkdir ${INSTALL_DIR}/nethelp
    ${GZIP} -dc nethelp-v47.nif | (cd ${INSTALL_DIR}; tar -xf -)
    if test -f ${INSTALL_DIR}/java/classes/resource.jar
       then
       mv ${INSTALL_DIR}/java/classes/resource.jar ${INSTALL_DIR}/java/classes/old_resource.jar
    fi
    cp resource.jar ${INSTALL_DIR}/java/classes/resource.jar
fi
exit 0

