#!/bin/sh
#
# Install Script for UNIX Acrobat Exchange and Reader v. 7.0.0
#
# Copyright (c)1995-2005 Adobe Systems Incorporated
# All Rights Reserved
#
##########################################################################


setLangENU()
{
ST_LANG="ENU"
ST_LANG_SMALL="enu"
ST_READER_RPM_NAME="AdobeReader_enu"
ST_EXCHANGE_RPM_NAME="AdobeAcrobat_enu"
ST_COMMENT_WORD="Comment"
ST_DESCRIPTION_WORD="Description"
ST_COMMENT_RPM="Launch Adobe Reader 7.0"
ST_DES_RPM="Adobe Reader for Linux. An application that can view, navigate and print PDF documents."
ST_DES_TAG01="Adobe Reader can read documents in PDF format."
ST_DES_TAG02="Adobe Reader also allows you to search within PDF files,"
ST_DES_TAG03="search for PDF files on the internet and participate in collaborative document reviews."
ST_DES_TAG04="For details, please check www.adobe.com."
ST_THE_FILE="The file"
ST_FOR="for"
ST_YES="yes"
ST_NO="no"
ST_OR="or"
ST_SMALL_Y="y"
ST_SMALL_N="n"
ST_CAPS_Y="Y"
ST_CAPS_N="N"
ST_ACCEPT_CAPS="ACCEPT"
ST_DECLINE_CAPS="DECLINE"
ST_ACCEPT="accept"
ST_DECLINE="decline"
ST_VERSION="version"
ST_STATEMENT_ACCEPT_DECLINE="Please type \\\"accept\\\" to accept the terms and conditions of license agreement; Type \\\"decline\\\" to exit. "
ST_RESTATEMENT_ACCEPT_DECLINE="Invalid response, expected \\\"accept\\\" or \\\"decline\\\" ... try again ?"
ST_ER_INVALID_RESP1="ERROR: Invalid response, expected"
ST_ER_INVALID_RESP2="ERROR: Invalid response ... try again"
ST_ER_INVALID_RESP3="... try again ?"
ST_ER_NO_LIC_FILE="ERROR: Cannot find license file ... aborting"
ST_TO_ACCEPT="To accept the terms and conditions of this agreement enter"
ST_TO_DECLINE="To decline the terms and conditions of this agreement enter"
ST_REQ0101="Please type"
ST_REQ0102="to accept the terms and conditions of license agreement;"
ST_REQ0103="Type"
ST_REQ0104="to exit. "
ST_ER_LIC_NOT_ACCP="License agreement not accepted ... aborting installation"
ST_FREE_SPACE_INFO01="This installation requires"
ST_FREE_SPACE_INFO02="MB of free disk space."
ST_DONE_WORD="Done"
ST_ER_INSTALLING01="ERROR installing"
ST_ER_INSTALLING02="invalid product name"
ST_RES_INST_DIR="Enter installation directory for Adobe Reader"
ST_ER_SAME_FILE_NAME_AS_DIR="exists but is not a directory. Please specify a different location."
ST_DIR_INFO01="Directory"
ST_DIR_INFO02="does not exist."
ST_QUES_CREAT_DIR="Do you want to create it now? [y] "
ST_ER_EXIT="Exiting installation..."
ST_ER_DIR="ERROR: Cannot make directory"
ST_ER_WRITE="ERROR: Cannot write to directory"
ST_ER_NO_LIBCURL01="Not able to locate libcurl.so. Some of the functionality of Adobe Reader may be hampered."
ST_ER_NO_LIBCURL02="It is recommended to install curl ver."
ST_ER_NO_LIBCURL03="or any version later than ver."
ST_WARN_NO_LIBSSL01="WARNING: The libssl.so version on your machine is not compatible to libssl.so.0.9.6."
ST_WARN_NO_LIBSSL02="Please install libssl.so.0.9.6."
ST_WARN_LD_LIB01="exists in the directory"
ST_WARN_LD_LIB02="but this directory is not included in LD_LIBRARY_PATH."
ST_WARN_LD_LIB03="Please include the directory"
ST_WARN_LD_LIB04="in LD_LIBRARY_PATH"
ST_WARN_LD_LIB05="exists in the directory"
ST_ER_NO_CONFIG="ERROR: No configurations found ... aborting"
ST_WARN_NO_CONFIG="WARNING: The chosen configuration will not run on your current platform"
ST_QUE_CONT="Continue installation?"
ST_INFO_DEF_CONFIG1="Install default configuration"
ST_INFO_DEF_CONFIG2="The following configurations are available for installation:"
ST_QUE_CONFIG="Enter the configuration number to install: "
ST_EXIT_INFO="Exit Acrobat installation"
ST_PLAT_INDEP_FILES="Installing platform independent files ... "
ST_PLAT_DEP_FILES="Installing platform dependent files ... "
ST_RPM_CAN_NOT_DEL="could not be deleted as it has some extra file or files that were not installed by rpm"
ST_WEL_ALK="Welcome to the Asian Language Kit installation."
ST_INFO_ALK01="This installation will not work if you do not have the"
ST_INFO_ALK02="Unix Adobe Reader version 7.0 installed prior to this installation."
ST_INFO_ALK03="If you do not have Adobe Reader version 7.0 already installed on your"
ST_INFO_ALK04="system please do so before installing this Asian Language Kit."
ST_ER_ALK01="ERROR: directory must be an absolute path"
ST_ER_ALK02="ERROR: Directory "
ST_ER_ALK03="does not exist."
ST_ER_ALK04="ERROR: AcroVersion file does not exist."
ST_ER_ALK05="ERROR: Incorrect Acrobat version:"
ST_ER_ALK06="ERROR: Could not find distribution ... aborting"
ST_IF_ALK07="Enter the location where you installed the Adobe Reader"
ST_INFO_ALK_CMPLT="Installation completed."
ST_WEL_HLK="Welcome to the Extended Language Pack installation."
ST_INFO_HLK04="system please do so before installing this Extended Language Pack."
ST_INFO_HLK05="Installing Extended Language Pack Files ... "
ST_WEL_CLK="Welcome to the Central European Font Pack installation."
ST_INFO_CLK04="system please do so before installing this Central European Font Pack."
ST_INFO_CLK05="Installing Central European Language Pack Files ... "
ST_ER_AR01="ERROR: Cannot determine current directory."
ST_ER_AR02="ERROR: Cannot find installation directory."
ST_ER_AR03="ERROR: Cannot find"
ST_INFO_AR01="The OS named "
ST_INFO_AR02="is currently not installed."
ST_INFO_AR03="Try running on an installed platform and connecting to your display."
ST_INFO_AR04="Installed platform(s) include the following:"
ST_INFO_AR05="not installed for this configuration,"
ST_IBP_MISC_03="Mozilla"
ST_IBP_MISC_04="Firefox"
ST_IBP_MISC_05="Netscape"
ST_IBP_MISC_06="Quit"
ST_IBP_INFO_01="This will install the browser plugin for acroread."
ST_IBP_INFO_02="Perform global installation"
ST_IBP_INFO_03="Perform user-specific installation"
ST_IBP_INFO_04="Enter your choice"
ST_IBP_INFO_05="Do you want to install another browser ?"
ST_IBP_INFO_06="Enter the install directory for Adobe Reader 7.0"
ST_IBP_INFO_07="Enter the browser install directory"
ST_IBP_INFO_08="The plugin seems to be already installed. Are you sure you want to overwrite ?"
ST_IBP_INFO_09="Installation cancelled."
ST_IBP_INFO_10="Installation successful."
ST_IBP_INFO_11="This will enable the plugin for Mozilla, Firefox and Netscape."
ST_IBP_INFO_12="If you are facing any problem in getting the installation to work for your browser, please copy the following file to the plugin folder of the browser:"
ST_IBP_INFO_13="Acroread path specified"
ST_IBP_INFO_14="Press <Enter> to continue"
ST_IBP_INFO_15="In case of difficulties please refer to the documentation provided along with the browser for addition of new plugins."
ST_IBP_INFO_16="Installing plugin in"
ST_IBP_INFO_17="Do you want to perform automatic installation ?"
ST_IBP_INFO_18="Finished with automatic install."
ST_IBP_INFO_19="Do you want to perform manual installation ?"
ST_IBP_INFO_20="Do you want to install the browser plugin ?"
ST_IBP_INFO_21="Browser plugin installation skipped."
ST_IBP_INFO_22_1="Run"
ST_IBP_INFO_22_2="to install browser plugin."
ST_IBP_INFO_23="has been added."
ST_IBP_INFO_24="Trying to install plugin for browser"
ST_IBP_INFO_25="Installation failed"
ST_IBP_ERR_01="Could not find the browser plugin file"
ST_IBP_ERR_02="Could not find the browser plugins folder"
ST_IBP_ERR_03="Could not find the browser folder"
ST_IBP_ERR_04="Could not remove previous version of the plugin in"
ST_IBP_ERR_05_1="Could not copy the plugin file"
ST_IBP_ERR_05_2="to"
ST_IBP_ERR_06="Could not create the directory"
ST_IBP_ERR_07="Could not find browser plugin install script."
ST_IBP_ERR_08="already exists as a special file and cannot overwrite it."
ST_IBP_ERR_09="Unable to query HOME variable from the environment. Cannot find your home directory."
ST_IBP_ERR_10="Could not find the installation folder"
ST_IBP_ERR_11="INTERNAL ERROR ..... No matching OS name."
ST_SEP_INFO_01="Enter the install directory for Adobe Reader 7.0"
ST_SEP_INFO_02="INTERNAL ERROR ..... No matching OS name."
ST_SEP_INFO_03="Unable to find appropriate files in the installation path."
ST_SEP_INFO_04="Resetting old contexts"
ST_SEP_INFO_05="Setting new contexts for library files"
ST_SEP_INFO_06="This will try to update the library files to make them SELinux aware."
ST_SEP_INFO_07="Could not find the installation folder."
ST_SEP_INFO_08="Finished setting the contexts. You can check the log at"
ST_SEP_INFO_09="Failure in command"
ST_SEP_INFO_10="Patch might not have completed properly. You can check the log at"
ST_IOP_ERR1="OpenOffice PDF Plugin could not be registered. Please read the instructions in "
ST_IOP_ERR2="for manual installation."
ST_IOP_ERR3="OpenOffice >= 1.9 is required for OpenOffice PDF Plugin to run properly. Skipping registration of PDF Plugin."
ST_IOP_ERR4="OpenOffice binary soffice could not located in the specified directory."
ST_IOP_INFO_01="Please specify the directory where OpenOffice is installed: "
ST_IOP_INFO_02="Do you want to install the OpenOffice Plugin ?"
ST_IAP_ERR1="Adobe PDF Plugin could not be registered. Please follow the instructions in "
ST_IAP_INFO_01="Do you want to install the Adobe PDF plugin ?"
ST_IFE_INFO_01="Do you want to install the firefox extension ?"
ST_IFE_INFO_02="Please specify the path for Firefox executable : "
ST_IFE_ERR_01="Firefox exe not found or does not have executable permissions."
ST_IDI_INFO_01="Do you want to install the Distiller ?"
ST_MIME_INFO_01="Please login again for changes to MIME types and icons to take effect."
true
}

setLangENU

echoawk ()
{
  echo $* | awk '{ printf "%s", $0 }'
}

echon ()
{
  echo -n "$*"
}

echoc ()
{
  echo "${*}\c"
}


readlink()
{
    if [ -x /usr/bin/test ]; then
        TestCmd=/usr/bin/test
    else
        TestCmd=test
    fi

    if [ "`$TestCmd -e . 2>/dev/null; echo $?`" = "0" ]; then
        TestCmdOption="-e"
    else
        TestCmdOption="-f"
    fi

    OLDPWD="`pwd`"
    lfile="$1"

    while $TestCmd -h "$lfile" -a $TestCmdOption "$lfile" ; do
        CWD="`dirname "$lfile"`"
        lfile="`basename "$lfile"`"
        cd $CWD
        lfile="`ls -l "$lfile"|sed 's/^.*-> *\(.*\) *$/\1/'`"
    done

    if $TestCmd $TestCmdOption "$lfile" ; then
        CWD="`dirname "$lfile"`"
        lfile="`basename "$lfile"`"
        cd $CWD
        echo `pwd`/$lfile
        cd "$OLDPWD"
        return 0
    fi

    cd "$OLDPWD"
    return 1
}



##########################################################################

yesno()
{
  msg="$1"
  def="$2"
  while true ; do
    echo " "
    $echonl "$msg"
    read answer
    if [ "$answer" ] ; then
      case "$answer" in
        y|Y|yes|YES)
          return 0
          ;;
        n|N|no|NO)
          return 1
          ;;
        *)
          echo " "
          echo "$ST_ER_INVALID_RESP1 \"$ST_YES\" $ST_OR \"$ST_NO\"."
          continue
          ;;
      esac
    else
      return $def
    fi
  done
}

TypeCheck() 
{
  h=`type $1 2> /dev/null`
  case " $h " in
  *' '/*/$1' '*)
    return 0
    ;;
  *)
    return 1
    ;;
  esac
}


PrintRequiredFree()
{
  total=0

  for i in "$@" ; do
    if [ "$i" -a -f "$i" ] ; then

        if [ `uname -s` = "Linux" ] ; then
          size=`ls -lLn "$i" | ( read perm links owner group size date ; echo $size )`
        else
          size=`ls -lLon "$i" | ( read perm links owner size date ; echo $size )`
        fi

      if [ "$size" ] ; then
        total=`expr $total + $size`
      fi
    fi
  done

  megs=`expr $total / 1048576 + 1`

  echo " "
  echo "$ST_FREE_SPACE_INFO01 ${megs} $ST_FREE_SPACE_INFO02"
}

ExtractFiles ()
{

   prev_directory="`pwd 2> /dev/null`"
   cd "$1" 

   case "`uname -s`" in
	 Linux)
		tar --no-same-owner -xpf "$2" ;;
	 HP-UX)
		tar xfo "$2" ;;
     *)
		tar xpfo "$2" ;;
   esac

   cd "$prev_directory"

}


InstallFiles ()
{
  msg="$1"
  install="$2"
  shift
  shift

  echo " "

  for i in "$@" ; do
    if [ "$i" ] ; then
      if [ "$msg" ] ; then
        $echonl "$msg"
        msg=""
      fi
      ExtractFiles "$install" "$i"
    fi
  done

  if [ -z "$msg" ] ; then
    echo "$ST_DONE_WORD"
  fi
}


ExpandDirPath ()
{
    var=`echo $@ |  cut -d "\"" -f 2`

    case "$var" in
    ~*)
      if [ -f /bin/csh -a -x /bin/csh ] ; then
        tmp_var=`/bin/csh -c "echo $var" 2>/dev/null`
        if [ $? -eq 0 ]; then
            var="$tmp_var"
        fi
      fi
      ;;
    ../*|./*|..|.)
      var="`pwd`/${var}"
      ;;
    /*)
    ;;
    *)
        var="`pwd`/${var}"
      ;;
	esac
    eval var=\"${var}\"
    echo $var
}


GetInstallDirectory ()
{
  var=$1
  
  defdir="/usr/local/Adobe/Acrobat7.0"
  case "$OSname" in
    SunOS)
      case "$OSrelease" in
        4.1.3*|4.1.4*|4.1C) defdir="/usr/Adobe/Acrobat7.0" ;;
        5.*) defdir="/opt/Adobe/Acrobat7.0" ;;
      esac
      ;;
    HP-UX)
      case "$OSrelease" in
        *.09.*) defdir="/usr/Adobe/Acrobat7.0" ;;
        *.10.*) defdir="/opt/Adobe/Acrobat7.0" ;;
	*.11.*) defdir="/opt/Adobe/Acrobat7.0" ;;
        *) defdir="/opt/Adobe/Acrobat7.0" ;;
      esac
      ;;
    AIX)
      defdir="/usr/lpp/Adobe/Acrobat7.0"
      ;;
  esac

  while [ -z "$InstallDir" ] ; do

    InstallDir="$defdir"

    echo " "
    $echonl "$ST_RES_INST_DIR ${Version} [${InstallDir}] "
    read answer
    case "$answer" in
      "")
        ;;
      *)
        InstallDir="$answer"
        ;;
    esac

    InstallDir="`ExpandDirPath "$InstallDir"`"

	if [ -f "$InstallDir" ] ; then
      
        echo " "
        echo "\"$InstallDir\" $ST_ER_SAME_FILE_NAME_AS_DIR "
        InstallDir=""
        continue;
      
    fi

    if [ ! -d "$InstallDir" ] ; then
      echo " "
      echo "$ST_DIR_INFO01 \"$InstallDir\" $ST_DIR_INFO02"
      $echonl "$ST_QUES_CREAT_DIR "
      read answer

      if [ "$answer" ] ; then
          case "$answer" in
             "$ST_SMALL_Y" | "$ST_CAPS_Y" )
               mkdir -p "$InstallDir"
             ;;
             "$ST_SMALL_N" | "$ST_CAPS_N" )
               echo "$ST_ER_EXIT"
               exit 0
             ;;
          esac
      else
         mkdir -p "$InstallDir"
      fi

      if [ ! -d "$InstallDir" ] ; then
        echo " "
        echo "$ST_ER_DIR \"$InstallDir\"."
        InstallDir=""
        continue;
      fi
    fi
 
    export "InstallDir"


    if ( echo foo > "$InstallDir"/AcroWriteTest ) 2> /dev/null ; then
      rm -f "$InstallDir"/AcroWriteTest
      break
    else
      echo " "
      echo "$ST_ER_WRITE \"$InstallDir\"."
      InstallDir=""
      continue
    fi
  done

 

  ReadInstallDir="$InstallDir"
}


check_file_in_named_path()
{
     if [ -x "$2/$1" ] ; then
        return 1
     fi

     return 0
}


check_file_in_path()
{
    OLD_IFS=$IFS
    IFS=":"

    if [ -n "$PATH" ] ; then
        for i in $PATH; do
            if [ -d "$i" ] ; then
                check_file_in_named_path "$1" "$i"
                if [ $? -eq 1 ]; then
                    IFS=$OLD_IFS
                    echo "$i/$1"
                    return 1
                fi
           fi
        done
     fi

     IFS=$OLD_IFS
     return 0
}


#Make Soft Links To gnome-speech libraries
MakeLibGnomeSpeechLinks()
{
    InstallDir="$1/Reader"
    ConfiguredDir="$2"
    LibDir="$InstallDir/$ConfiguredDir/lib"

    TESTSPEECHEXEC=`check_file_in_path "test-speech"`
    if [ $? -ne 0 ]
    then
        check_file_in_path "ldd" >/dev/null
        if [ $? -ne 0 ]
        then
            check_file_in_path "awk" >/dev/null
            if [ $? -ne 0 ]
            then
                rm -f "$LibDir"/libORBit-2.so 2>/dev/null
                rm -f "$LibDir"/libbonobo-2.so 2>/dev/null
                rm -f "$LibDir"/libbonobo-activation.so 2>/dev/null
                rm -f "$LibDir"/libgnomespeech.so 2>/dev/null
                LIB_ORBit2="`ldd $TESTSPEECHEXEC 2>/dev/null | grep -i libORBit-2.* | cut -d '>' -f2 | cut -d '(' -f 1 |awk '{print $1}' `"
                LIB_BONOBO="`ldd $TESTSPEECHEXEC 2>/dev/null | grep -i bonobo-2.* | cut -d '>' -f2 | cut -d '(' -f 1 |awk '{print $1}' `"
                LIB_BONOBOACTIVATION="`ldd $TESTSPEECHEXEC 2>/dev/null | grep -i bonobo-activation.* | cut -d '>' -f2 | cut -d '(' -f 1 |awk '{print $1}' `"
                LIB_GNOMESPEECH="`ldd $TESTSPEECHEXEC 2>/dev/null | grep -i libgnomespeech.* | cut -d '>' -f2 | cut -d '(' -f 1 |awk '{print $1}' `"
                if [ -f "$LIB_ORBit2" -a -f "$LIB_BONOBO" -a -f "$LIB_BONOBOACTIVATION" -a -f "$LIB_GNOMESPEECH" ]
                then
                    ln -s "$LIB_ORBit2" "$LibDir/libORBit-2.so"
                    ln -s "$LIB_BONOBO" "$LibDir/libbonobo-2.so"
                    ln -s "$LIB_BONOBOACTIVATION" "$LibDir/libbonobo-activation.so"
                    ln -s "$LIB_GNOMESPEECH" "$LibDir/libgnomespeech.so"
                fi
            fi
        fi
    fi
}

MakeLibLDAPLinks()
{
InstallDir="$1/Reader"

if [ ! -e /usr/lib/libldap.so ]
then
	rm -f "$InstallDir"/intellinux/lib/libldap.so 2>/dev/null

	LIB_LDAP=`ls -tr /usr/lib/libldap.so*  2>/dev/null | tail -n 1`

	if [ "$LIB_LDAP" = "" ] 
	then
		LIB_LDAP=`ls -tr /usr/lib/libldap* 2>/dev/null | grep -v libldap_r | grep -v libldapcpp | grep '\.so' | tail -n 1`
	fi

	if [ "$LIB_LDAP" != "" ] 
	then
		ln -s $LIB_LDAP "$InstallDir"/intellinux/lib/libldap.so
	fi
fi

if [ ! -e /usr/lib/liblber.so ]
then
	rm -f "$InstallDir"/intellinux/lib/liblber.so 2>/dev/null

	LIB_LBER=`ls -tr /usr/lib/liblber.so* 2>/dev/null | tail -n 1`

	if [ "$LIB_LBER" = "" ] 
	then
		LIB_LBER=`ls -tr /usr/lib/liblber* 2>/dev/null | grep -v liblber_r | grep '\.so' | tail -n 1`
	fi

	if [ "$LIB_LBER" != "" ] 
	then
		ln -s $LIB_LBER "$InstallDir"/intellinux/lib/liblber.so
	fi
fi
}


InstallBrowserPlugin()
{
    echo ""
    while :
      do
      $echonl "$ST_IBP_INFO_20 [$ST_SMALL_Y/$ST_SMALL_N] "
      read OVERWRITE_CHOICE
      
      if [ "$OVERWRITE_CHOICE" = "$ST_SMALL_Y" ] || [ "$OVERWRITE_CHOICE" = "$ST_CAPS_Y" ] || [ -z "$OVERWRITE_CHOICE" ]
	  then
	  break
      elif [ "$OVERWRITE_CHOICE" = "$ST_SMALL_N" ] || [ "$OVERWRITE_CHOICE" = "$ST_CAPS_N" ]
	  then
	  return 0
	  break
      fi
    done

    if [ -f "$ReadInstallDir/Browser/install_browser_plugin" ]
	then
	$ReadInstallDir/Browser/install_browser_plugin "$ReadInstallDir"
    else
	echo "$ST_IBP_ERR_07"
	exit 1
    fi
}


UpdateOldGnomeFile()
{
    awk '
BEGIN   { state = 0; }

/^application\/pdf$/    {
        state = 1;
        print $0;
        next;
    }

/^[^ \t].*/ {
        state = 0;
        print $0;
        next;
    }

/^[ \t][ \t]*default_application_id=/ && (state == 1) {
        print gensub(/(^[ \t][ \t]*default_application_id=).*$/, "\\1acroread", "g");
        next;
    }

/.*/    { print $0 }' "$1" > /tmp/acroread.tmp 2>/dev/null

    if [ $? -eq 0 ]; then
        mv -f /tmp/acroread.tmp "$1" 2>/dev/null || rm -f /tmp/acroread.tmp 2>/dev/null
    fi
}


ReadKDEConfigFile()
{
    awk '
BEGIN     { state = 0; MaxPreference = 0; MaxIndex = 0; }

/^[ \t]*\[([^ ]*)[ \t]*-[ \t]*([0-9][0-9]*)[ \t]*\][ \t]*$/  {
                                        app_type = gensub(/^[ \t]*\[([^ ]*)[ \t]*-[ \t]*([0-9][0-9]*)[ \t]*\][ \t]*$/, "\\1", "g");
                                        if ( app_type == "application/pdf" )
                                        {
                                            state = 1;
                                            app_index = gensub(/\[(.*)[ \t]*-[ \t]*([0-9][0-9]*)\]$/, "\\2", "g");
                                            if ( MaxIndex < app_index )
                                                MaxIndex = app_index;
                                        }
                                        else
                                            state = 0;
                                }

/^[ \t]*Preference[ \t]*=[ \t]*[0-9][0-9]*[ \t]*$/ {
                                        if (state == 1) {
                                           app_pref = gensub(/^[ \t]*Preference=[ \t]*([0-9][0-9]*)[ \t]*$/, "\\1", "g");
                                           if ( MaxPreference < app_pref )
                                                MaxPreference = app_pref;
                                        }
                                     }
/.*/      { print $0 }

END       { printf("\n[application/pdf - %d]\nAllowAsDefault=true\nApplication=AdobeReader.desktop\nGenericServiceType=Application\nPreference=%d\nServiceType=application/pdf\n", MaxIndex + 1, MaxPreference + 1);}' "$1" > /tmp/acroread.tmp 2>/dev/null

    if [ $? -eq 0 ]; then
        mv -f /tmp/acroread.tmp "$1" 2>/dev/null || rm -f /tmp/acroread.tmp 2>/dev/null
    fi
}


UpdateIcon()
{
    if [ -n "$1" -a -n "$2" ]; then
        rm -f "$2" 2>/dev/null
        ln -s "$1" "$2" 2>/dev/null
    fi
}


# $1 => Directory where Adobe Acrobat is installed

UpdateDefaultIcons()
{
    InstallDir="$1"
    IconDir="$GNOME_BASE_DIR/share/icons"

    if [ -z "$InstallDir" ]; then
        exit 1
    fi


    for IconSize in 16x16 20x20 24x24 32x32 36x36 48x48 64x64 96x96 128x128 192x192; do
        for gnomeDir in "$GNOME_BASE_DIR/share/icons/Bluecurve/$IconSize/mimetypes" "$GNOME_BASE_DIR/share/icons/hicolor/$IconSize/apps" "$GNOME_BASE_DIR/share/icons/gnome/$IconSize/mimetypes" ; do
            if [ -d "$gnomeDir" ]; then
                UpdateIcon "$InstallDir/Resource/Icons/$IconSize/AdobeReader.png" "$gnomeDir/gnome-mime-application-pdf.png" 2>/dev/null
                UpdateIcon "$InstallDir/Resource/Icons/$IconSize/vnd.fdf.png" "$gnomeDir/gnome-mime-application-vnd.fdf.png" 2>/dev/null
                UpdateIcon "$InstallDir/Resource/Icons/$IconSize/vnd.adobe.pdx.png" "$gnomeDir/gnome-mime-application-vnd.adobe.pdx.png" 2>/dev/null
                UpdateIcon "$InstallDir/Resource/Icons/$IconSize/vnd.adobe.xdp+xml.png" "$gnomeDir/gnome-mime-application-vnd.adobe.xdp+xml.png" 2>/dev/null
                UpdateIcon "$InstallDir/Resource/Icons/$IconSize/vnd.adobe.xfdf.png" "$gnomeDir/gnome-mime-application-vnd.adobe.xfdf.png" 2>/dev/null
            fi
        done

        for kdeDir in "$KDE_BASE_DIR/share/icons/Bluecurve/$IconSize/mimetypes" "$KDE_BASE_DIR/share/icons/default.kde/$IconSize/mimetypes" "$KDE_BASE_DIR/share/icons/hicolor/$IconSize/apps" ; do
            if [ -d "$kdeDir" ]; then
                UpdateIcon "$InstallDir/Resource/Icons/$IconSize/AdobeReader.png" "$kdeDir/pdf.png" 2>/dev/null
                UpdateIcon "$InstallDir/Resource/Icons/$IconSize/vnd.fdf.png" "$kdeDir/vnd.fdf.png" 2>/dev/null
                UpdateIcon "$InstallDir/Resource/Icons/$IconSize/vnd.adobe.pdx.png" "$kdeDir/vnd.adobe.pdx.png" 2>/dev/null
                UpdateIcon "$InstallDir/Resource/Icons/$IconSize/vnd.adobe.xdp+xml.png" "$kdeDir/vnd.adobe.xdp+xml.png" 2>/dev/null
                UpdateIcon "$InstallDir/Resource/Icons/$IconSize/vnd.adobe.xfdf.png" "$kdeDir/vnd.adobe.xfdf.png" 2>/dev/null
            fi
        done
done
}


UpdateConfigurationFiles()
{
    GNOME_CONFIG_FILE="$GNOME_BASE_DIR/share/applications/defaults.list"
    GNOME_OLD_CONFIG_FILE="$GNOME_BASE_DIR/share/mime-info/gnome-vfs.keys"
    KDE_CONFIG_FILE="$KDE_BASE_DIR/share/config/profilerc"

    if [ -f "$GNOME_CONFIG_FILE" ]; then
        ( grep -v "^application\/pdf=." < "$GNOME_CONFIG_FILE" ; echo 'application/pdf=AdobeReader.desktop' ) > /tmp/acroread.tmp 2>/dev/null
        mv -f /tmp/acroread.tmp "$GNOME_CONFIG_FILE" 2>/dev/null || rm -f /tmp/acroread.tmp 2>/dev/null
    else
        if [ -f "$GNOME_OLD_CONFIG_FILE" ]; then
            UpdateOldGnomeFile  "$GNOME_OLD_CONFIG_FILE"
        fi
    fi

    if [ -f "$KDE_CONFIG_FILE" ]; then
        ReadKDEConfigFile "$KDE_CONFIG_FILE"
    fi

    rm -f /tmp/acroread.tmp 2>/dev/null
}


InstallReader()
{
  ReadConfig="$1"
  ReadPlatformTar="$2"
  SearchPlatformTar="$3"
  CustomPlatformTar="$4"

  PrintRequiredFree "$ReadTar" "$SearchTar" "$CustomTar" \
    "$ReadPlatformTar" "$SearchPlatformTar" "$CustomPlatformTar"


  if [ -z "$ReadInstallDir" ] ; then
    GetInstallDirectory
    SilentMode="No"
  else
    ReadInstallDir=`ExpandDirPath "$ReadInstallDir"`
    SilentMode="Yes"

    if [ -f "$ReadInstallDir" ]; then
        echo "\"$ReadInstallDir\" $ST_ER_SAME_FILE_NAME_AS_DIR "
        exit 1
    fi

    mkdir -p "$ReadInstallDir" 2>/dev/null

    if [ $? -ne 0 ]; then
        echo "$ST_ER_DIR \"$ReadInstallDir\"."
        exit 1
    fi

    touch "$ReadInstallDir"/AcroWriteTest 2>/dev/null 

    if [ $? -eq 0 ]; then
        rm -f "$ReadInstallDir"/AcroWriteTest 2>/dev/null
    else
        echo "$ST_ER_WRITE \"$ReadInstallDir\"."
        exit 1
    fi
  fi

  echo $ReadInstallDir
  InstallFiles "$ST_PLAT_INDEP_FILES" \
    "$ReadInstallDir" "$ReadTar" "$SearchTar" "$CustomTar"
  InstallFiles "$ST_PLAT_DEP_FILES" \
    "$ReadInstallDir" \
    "$ReadPlatformTar" "$SearchPlatformTar" "$CustomPlatformTar"

  if [ `uname -s` = "Linux" ] ; then
    MakeLibLDAPLinks "$ReadInstallDir"
  fi
  if [ `uname -s` = "SunOS" ] || [ `uname -s` = "Linux" ] || [ `uname -s` = "AIX" ] ; then
    MakeLibGnomeSpeechLinks "$ReadInstallDir" "$ReadConfig"
  fi 

  if [ "$SilentMode" = "No" ]; then
    InstallBrowserPlugin "$ReadInstallDir"
  else
    echo ""
    echo "$ST_IBP_INFO_21"
    echo "$ST_IBP_INFO_22_1" \"$ReadInstallDir/Browser/install_browser_plugin\" "$ST_IBP_INFO_22_2"
  fi

  rm -f /usr/bin/acroread 2>/dev/null
  ln -s "$ReadInstallDir"/bin/acroread /usr/bin/acroread 2>/dev/null

  rm -f /usr/share/applications/AdobeReader.desktop 2>/dev/null
  ln -s "$ReadInstallDir"/Resource/Support/AdobeReader_GNOME.desktop /usr/share/applications/AdobeReader.desktop 2>/dev/null

  rm -f /usr/share/pixmaps/AdobeReader.desktop 2>/dev/null
  ln -s "$ReadInstallDir"/Resource/Icons/AdobeReader.png /usr/share/pixmaps/AdobeReader.png 2>/dev/null

  if [ "`uname -s`" = "Linux" ]; then
      check_file_in_path kde-config >/dev/null

      if [ $? -ne 0 ]; then
        KDE_BASE_DIR="`kde-config --prefix`"
      elif [ -x /opt/kde3/bin/kde-config ]; then
        KDE_BASE_DIR="/opt/kde3"
      elif [ -x /opt/kde/bin/kde-config ]; then
        KDE_BASE_DIR="/opt/kde"
      else
        KDE_BASE_DIR="/usr"
      fi

      GNOME_BASE_DIR=`check_file_in_path gnome-open`

      if [ $? -ne 0 ]; then
        GNOME_BASE_DIR="`dirname "$GNOME_BASE_DIR"`"
        GNOME_BASE_DIR="`dirname "$GNOME_BASE_DIR"`"
      elif [ -x /opt/gnome/bin/gnome-open ]; then
        GNOME_BASE_DIR="/opt/gnome"
      else
        GNOME_BASE_DIR="/usr"
      fi

      UpdateDefaultIcons "$ReadInstallDir"
      UpdateConfigurationFiles

      if [ -d "$GNOME_BASE_DIR/share/mime/packages" ]; then
          UpdateIcon "$ReadInstallDir/Resource/Support/AdobeReader.xml" "$GNOME_BASE_DIR/share/mime/packages/AdobeReader.xml" 
      fi

      if [ -d "$KDE_BASE_DIR/share/mimelnk/application" ]; then
          UpdateIcon "$ReadInstallDir/Resource/Support/vnd.fdf.desktop" "$KDE_BASE_DIR/share/mimelnk/application/vnd.fdf.desktop"
          UpdateIcon "$ReadInstallDir/Resource/Support/vnd.adobe.pdx.desktop" "$KDE_BASE_DIR/share/mimelnk/application/vnd.adobe.pdx.desktop"
          UpdateIcon "$ReadInstallDir/Resource/Support/vnd.adobe.xdp+xml.desktop" "$KDE_BASE_DIR/share/mimelnk/application/vnd.adobe.xdp+xml.desktop"
          UpdateIcon "$ReadInstallDir/Resource/Support/vnd.adobe.xfdf.desktop" "$KDE_BASE_DIR/share/mimelnk/application/vnd.adobe.xfdf.desktop"
      fi

      OLD_IFS="$IFS"
      IFS=':'

      for idir in $PATH; do
        if [ -x "${idir}"/update-mime-database ]; then
            "${idir}"/update-mime-database "$GNOME_BASE_DIR/share/mime" >/dev/null 2>&1
        fi

        if [ -x "${idir}"/update-desktop-database ]; then
            "${idir}"/update-desktop-database >/dev/null 2>&1
        fi
      done

      IFS="$OLD_IFS"
      OLD_IFS=""
  fi

  if [ "`id 2>/dev/null| cut -d= -f2| cut -d'(' -f1`" = "0" ]; then
    echo "$ST_MIME_INFO_01"
  fi

  ReadTar=""
  SearchTar=""
  CustomTar=""
}


ShowUsage()
{
	echo "Usage : $0 [--install_path=dir]"
}


##############################################################

#
# Initialization:
#

umask 022
ReadInstallDir=""

case $# in
    "1")    
	case "$1" in 
	--install_path=*)
		ReadInstallDir="`echo $1 | cut -d= -f2-`"
		if [ "$ReadInstallDir" = "" ]; then
			ShowUsage "$@"
			exit 1
		fi;;
	*)
		ShowUsage "$@"
		exit 1 ;;
	esac
	;;

    "0")    ;;

    *)    ShowUsage "$@"
        	exit 1;;
esac


ScriptName=`basename "$0"`
CurrentDirectory=`pwd`
eval CurrentDirectory=\"${CurrentDirectory}\"

ScriptDirectory=`dirname "$0"`
eval ScriptDirectory=\"${ScriptDirectory}\"

AcroSerNum=""
AcroCompName=""
case "${ScriptDirectory}" in
  /*) ;;
  .) ScriptDirectory="$CurrentDirectory" ;;
  *) ScriptDirectory="$CurrentDirectory"/"$ScriptDirectory" ;;
esac

 TypeCheck uname

  if [ $? -eq 0 ] ; then
    OSname=`uname -s`
    if [ "$OSname" = "AIX" ] ; then
      OSrelease=`uname -a | ( read name host minor major foo ; echo $major.$minor )`
    else
      OSrelease=`uname -r`
    fi
  else
    OSname=unknown
    OSrelease=unknown
  fi



if [ `echo "x\c"` = "x" ] ; then
  echonl=echoc
else
  echonl=echon
fi

Version=7.0.9

#
# Get the filenames:
#

for i in "${ScriptDirectory}"/* "${ScriptDirectory}"/../COMMON/* "${ScriptDirectory}"/../common/*; do
  if [ -f "$i" ] ; then
    case $i in
      */common.tar*|*/COMMON.TAR*)
        ReadTar="$i"
        ;;
      */search.tar*|*/SEARCH.TAR*)
        SearchTar="$i"
        ;;
      */custom.tar*|*/CUSTOM.TAR*)
        CustomTar="$i"
        ;;
      */solrdr.tar*|*/SSOLR.TAR*)
        ReadSparcSolarisTar="$i"
        ;;
      */hpuxrdr.tar*|*/HPUXRDR.TAR*)
        ReadHppaHpuxTar="$i"
        ;;
      */aixrdr.tar*|*/AIXRDR.TAR*)
        ReadRS6000AIXTar="$i"
        ;;
      */ilinxr.tar*|*/ILINXR.TAR*)
        ReadIntelLinuxTar="$i"
        ;;
      */ilinxc.tar*|*/ILINXC.TAR*)
        CustomIntelLinuxTar="$i"
        ;;
    esac
  fi
done


#
# Validate the configurations:
#

NumConfigs=0

if [ "$ReadTar" ] ; then
  if [ "$ReadSparcSolarisTar" ] ; then
    NumConfigs=`expr $NumConfigs + 1`
    ReadSparcSolarisNum=$NumConfigs
  fi
  if [ "$ReadHppaHpuxTar" ] ; then
    NumConfigs=`expr $NumConfigs + 1`
    ReadHppaHpuxNum=$NumConfigs
  fi
  if [ "$ReadRS6000AIXTar" ] ; then
    NumConfigs=`expr $NumConfigs + 1`
    ReadRS6000AIXNum=$NumConfigs
  fi
  if [ "$ReadIntelLinuxTar" ] ; then
    NumConfigs=`expr $NumConfigs + 1`
    ReadIntelLinuxNum=$NumConfigs
  fi
fi
if [ "$NumConfigs" = "0" ] ; then
  echo " "
  echo "$ST_ER_NO_CONFIG"
  echo " "
  exit 1
elif [ "$NumConfigs" = "1" ] ; then
  SingleConfig=true
fi

NumConfigs=`expr $NumConfigs + 1`
ExitNum=$NumConfigs


#
# Check if there is a configuration supported by this OS.
#

case "$OSname" in
  SunOS)
    case "$OSrelease" in
      4.1.3*|4.1.4*|4.1C)
        ReadDefaultNum="$ReadSparcSunNum"
        DefaultName="SPARC/SunOS 4.1.3 and later"
        ;;
      5.1|5.1.*|5.2|5.2.*)
        ;;
      5.*)
        MachArch=`uname -p`
        case "$MachArch" in
          sparc)
            ReadDefaultNum="$ReadSparcSolarisNum"
            DefaultName="SPARC/Solaris 2.x"
            ;;
          esac
        ;;
    esac
    ;;
  HP-UX)
    case "$OSrelease" in
      *.09.*|*.10.*|*.11.*)
        ReadDefaultNum="$ReadHppaHpuxNum"
        DefaultName="HP-UX"
        ;;
    esac
    ;;
  AIX)
    case "$OSrelease" in
      4.*|5.*)
        ReadDefaultNum="$ReadRS6000AIXNum"
        DefaultName="AIX"
      ;;
    esac
    ;;
  Linux)
    ReadDefaultNum="$ReadIntelLinuxNum"
    DefaultName="Intel/Linux"
    ;;
esac

if  [ -z "$ReadDefaultNum" ] ; then
  echo ""
  echo "$ST_WARN_NO_CONFIG ($OSname/$OSrelease)."
  if [ -z "$ReadInstallDir" ]; then
      if yesno "$ST_QUE_CONT [$ST_SMALL_N] " 1 ; then
        :
      else
        exit 1
      fi
  fi
fi


#
# If multiple confurations, get the default configuration
#

if [ -z "$SingleConfig" ] ; then
  if [ "$ReadDefaultNum" ] ; then
      if [ -n "$ReadInstallDir" ]; then
        DefaultConfig="$ReadDefaultNum"
      elif yesno "Install default configuration, Acrobat Reader ${Version} for $DefaultName? [$ST_SMALL_Y] " 0 ; then
        DefaultConfig="$ReadDefaultNum"
      fi

  fi
fi


#
# If a single configuration available the loop will be executed once
# otherwise it will ask for each configuration to install
#

while [ "$NumConfigs" -gt 1 ] ; do

  #
  # If multiple configuration ask for which to install
  #

  if [ "$SingleConfig" ] ; then

    ConfigNum=1

  elif [ "$DefaultConfig" ] ; then

    ConfigNum="$DefaultConfig"

  else

    #
    # Display multiple configurations
    #

    echo " "
    echo "$ST_INFO_DEF_CONFIG2"
    echo " "

    if [ "$AcroSparcSolarisNum" ] ; then
      echo "  ${AcroSparcSolarisNum}. Acrobat ${Version} for SPARC/Solaris 2.x"
    fi
    if [ "$AcroHppaHpuxNum" ] ; then
      echo "  ${AcroHppaHpuxNum}. Acrobat ${Version} for HP-UX"
    fi
    if [ "$AcroRS6000AIXNum" ] ; then
      echo "  ${AcroRS6000AIXNum}. Acrobat ${Version} for AIX"
    fi
    if [ "$AcroIntelLinuxNum" ] ; then
      echo "  ${AcroIntelLinuxNum}. Acrobat ${Version} for Intel/Linux"
    fi
    if [ "$ReadSparcSolarisNum" ] ; then
        echo "  ${ReadSparcSolarisNum}. Acrobat Reader ${Version} for SPARC/Solaris 2.x"
    fi
    if [ "$ReadHppaHpuxNum" ] ; then
        echo "  ${ReadHppaHpuxNum}. Acrobat Reader ${Version} for HP-UX"
    fi
    if [ "$ReadRS6000AIXNum" ] ; then
      echo "  ${ReadRS6000AIXNum}. Acrobat Reader ${Version} for AIX"
    fi
    if [ "$ReadIntelLinuxNum" ] ; then
      echo "  ${ReadIntelLinuxNum}. Acrobat Reader ${Version} for Intel/Linux"
    fi
    if [ "$ExitNum" ] ; then
        echo "  ${ExitNum}. $ST_EXIT_INFO"
    fi

    echo " "
    $echonl "$ST_QUE_CONFIG"
    read ConfigNum

  fi


  #
  # Install the configuration
  #

  if [ -z "$ConfigNum" ] ; then

    echo " "
    echo "$ST_ER_INVALID_RESP2"
    continue
  elif [ "$ConfigNum" = "$ReadSparcSolarisNum" ] ; then

    InstallReader sparcsolaris "$ReadSparcSolarisTar" \
      "$SearchSparcSolarisTar" "$CustomSparcSolarisTar"
    ReadSparcSolarisNum=""
  elif [ "$ConfigNum" = "$ReadHppaHpuxNum" ] ; then

    InstallReader hppahpux "$ReadHppaHpuxTar" \
      "$SearchHppaHpuxTar" "$CustomHppaHpuxTar"
    ReadHppaHpuxNum=""
  elif [ "$ConfigNum" = "$ReadRS6000AIXNum" ] ; then

    InstallReader rs6000aix "$ReadRS6000AIXTar" \
      "$SearchRS6000AIXTar" "$CustomRS6000AIXTar"
    ReadRS6000AIXNum=""

  elif [ "$ConfigNum" = "$ReadIntelLinuxNum" ] ; then

    InstallReader intellinux "$ReadIntelLinuxTar" \
      "$SearchIntelLinuxTar" "$CustomIntelLinuxTar"
    ReadIntelLinuxNum=""

  elif [ "$ConfigNum" = "$ExitNum" ] ; then

    break

  else

    echo " "
    echo "$ST_ER_INVALID_RESP2"
    continue

  fi

  if [ "$DefaultConfig" ] ; then
    break;
  fi

  if [ -z "$MultipleInstall" ] ; then
    break;
  fi

  NumConfigs=`expr $NumConfigs - 1`

done

echo " "
exit 0


