#!/bin/sh 

UNAME=`uname`
ARCH=`uname -m`

JREDIR=soljre
if [ "${UNAME}" = "Linux" ]; then
   JREDIR=linjre
elif [ "${UNAME}" = "SunOS" ]; then
   	JREDIR=soljre
elif [ "${UNAME}" = "HP-UX" ]; then
        if [ "${ARCH}" = "ia64" ]; then
           JREDIR=hpjre_ia64
        else
           JREDIR=hpjre_PARISC
        fi
fi

PATH=.:/bin:/usr/bin:/usr/local/bin:$PATH; export PATH
SRCDIR=`dirname $0`
if [ "${SRCDIR}" = "." ]; then
   SRCDIR=`pwd`
fi

echo Welcome to the VERITAS Documentation CD Installer
echo -------------------------------------------------
echo This installer will copy the Documentation CD contents into a directory of 
echo your choice for easy access at a later time. The CD contains the following
echo Documentation formats...
echo 
echo 1. Searchable Documentation.
echo 2. Printable Documentation [PDF].
echo 

echo Please enter the directory you wish to install to : [Installer will create a directory called VRTSdocs under this directory]

done="0"
while [ "${done}" != "1" ] 
do
  read DIRNAME 
 
  if [ ! -d ${DIRNAME} ]; then
    echo The directory does not exist, try again :
    done="0"
  else
    mkdir ${DIRNAME}/VRTSdocs 
    if [ -d ${DIRNAME}/VRTSdocs ]; then
       done="1"
    else
       echo The directory does not have write permissions, try again :
       done="0"
    fi
  fi
done

target=${DIRNAME}/VRTSdocs


if [ -d ${target} ]; then
   # Copy the JRE to the target location
   echo Copying Java Runtime ...
   cp -r ${SRCDIR}/../${JREDIR} ${target}
   # Copy the documentation sets
   echo Copying the documentation sets ...
   cp -r ${SRCDIR}/../docsets ${target}
   # Copy the library files
   echo Copying required libraries ...
   cp -r ${SRCDIR}/../lib ${target} 
   # Copy the launch script
   echo Copying miscellaneous files ...
   cp ${SRCDIR}/../launch ${target}
   # Make this file executable
   chmod +x ${target}/launch
   # Copy the README.TXT file
   cp ${SRCDIR}/../README ${target}
   
   # Copy the README files with different encodings only if they exist
   if [ -f ${SRCDIR}/../README.pck ]; then
   	cp ${SRCDIR}/../README.pck ${target}
   fi
   
   if [ -f ${SRCDIR}/../README.utf8 ]; then
   	cp ${SRCDIR}/../README.utf8 ${target}
   fi

   if [ -f ${SRCDIR}/../README.euc ]; then
   	cp ${SRCDIR}/../README.euc ${target}
   fi
      
   echo Copy the PDF documents ...
   cp -r ${SRCDIR}/../pdf ${target}
   cp ${SRCDIR}/../pdfs.html ${target}

   echo Installation complete. 
   echo To view the documentation run the script \"launch\" from the ${target} directory. 
   echo To view the printable documentation, open the ${target}/pdfs.html file in a browser.
   echo Launch the Searchable documentation ? [Y/N]
   read YN
   if [ "${YN}" = "Y" ] || [ "${YN}" = "y" ]; then
      cd ${target} 
      ./launch &
   fi
else
   echo Unknown Error
fi