#!/bin/sh

#
#
echo ""
echo "=================================================================="
echo ""
echo "            Netscape 4.7x [ko] Korean Install"
echo ""
echo "                      ( Super User Only )"
echo "       Copyright (c) 2000 by Netscape Communications Corp."
echo "       Localization kit by CHOI, Junho <cjh@kr.freebsd.org>."
echo ""
echo "=================================================================="
echo ""
echo ""

NETHELP=nethelp-v451.nif

case `uname` in
HP-UX)
	ADLOC="/usr/lib/X11/ko_KR.eucKR/app-defaults";
	CFGLOC="/usr/lib/X11/ko_KR.eucKR/app-defaults";
	MISCLOC="/usr/lib/X11/ko_KR.eucKR/netscape";
	;;
IRIX)
	ADLOC="/usr/lib/X11/ko_KR.EUC/app-defaults";
	CFGLOC="/usr/lib/X11/ko_KR.EUC/app-defaults";
	MISCLOC="/usr/lib/X11/ko_KR.EUC/netscape";
	;;
OSF1)
	ADLOC="/usr/lib/X11/ko_KR/app-defaults";
	CFGLOC="/usr/lib/X11/ko_KR/app-defaults";
	MISCLOC="/usr/lib/X11/ko_KR/netscape";
	;;
SunOS)
	ADLOC="/usr/openwin/lib/locale/ko/app-defaults";
	CFGLOC="/usr/openwin/lib/ko/app-defaults";
	MISCLOC="/usr/openwin/lib/locale/ko/netscape";
	;;
FreeBSD|*)
	# 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

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"

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#^\*appDir:.*#*appDir: ${MISCLOC}#" Netscape.ad-ko > ${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"
	fi
	if test -d /usr/local/netscape/nethelp
	then
	    INSTALL_DIR="/usr/local/netscape"
	fi
	if test -d /usr/local/lib/netscape/nethelp
	then
	    INSTALL_DIR="/usr/local/lib/netscape"
	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} | (cd ${INSTALL_DIR}; tar -xf -)
fi

echo ""
echo "Install completed. Don't forgot to see your platform-specfic"
echo "subdirectory(e.g. FreeBSD/README) for more information to"
echo "work in your platform environment."
echo ""
exit 0

