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


setLangFRA()
{
ST_LANG="FRA"
ST_LANG_SMALL="fra"
ST_READER_RPM_NAME="AdobeReader_fra"
ST_EXCHANGE_RPM_NAME="AdobeAcrobat_fra"
ST_COMMENT_WORD="Commentaire"
ST_DESCRIPTION_WORD="Description"
ST_COMMENT_RPM="Lancer Adobe Reader 7.0"
ST_DES_RPM="Adobe Reader pour Linux. Une application permettant de visualiser, de parcourir et d'imprimer des documents PDF."
ST_DES_TAG01="Adobe Reader permet de lire les documents au format PDF."
ST_DES_TAG02="Adobe Reader vous permet galement d'effectuer des recherches dans des fichiers PDF,"
ST_DES_TAG03="de rechercher des fichiers PDF sur Internet et de participer  des rvisions collectives de documents."
ST_DES_TAG04="Pour plus de dtails, consultez le site Web www.adobe.fr."
ST_THE_FILE="Le fichier"
ST_FOR="for"
ST_YES="oui"
ST_NO="non"
ST_OR="ou"
ST_SMALL_Y="o"
ST_SMALL_N="n"
ST_CAPS_Y="O"
ST_CAPS_N="N"
ST_ACCEPT_CAPS="ACCEPTER"
ST_DECLINE_CAPS="REFUSER"
ST_ACCEPT="accepter"
ST_DECLINE="refuser"
ST_VERSION="version"
ST_STATEMENT_ACCEPT_DECLINE="Tapez \\\"accepter\\\" pour accepter les termes du contrat de licence ou \\\"refuser\\\" pour quitter. "
ST_RESTATEMENT_ACCEPT_DECLINE="Rponse incorrecte, \\\"accepter\\\" ou \\\"refuser\\\" attendu ... ressayer ?"
ST_ER_INVALID_RESP1="ERREUR : rponse incorrecte, attente de"
ST_ER_INVALID_RESP2="ERREUR : rponse incorrecte ... ressayez"
ST_ER_INVALID_RESP3="... voulez-vous ressayer ?"
ST_ER_NO_LIC_FILE="ERREUR : fichier de licence introuvable ... abandon"
ST_TO_ACCEPT="Pour accepter les conditions de ce contrat, saisissez"
ST_TO_DECLINE="Pour refuser les conditions de ce contrat, saisissez"
ST_REQ0101="Saisissez"
ST_REQ0102="pour accepter les conditions du contrat ;"
ST_REQ0103="Saisissez"
ST_REQ0104="pour quitter. "
ST_ER_LIC_NOT_ACCP="Contrat de licence non accept ... abandon de l'installation"
ST_FREE_SPACE_INFO01="L'installation ncessite"
ST_FREE_SPACE_INFO02="Mo d'espace disque."
ST_DONE_WORD="Terminer"
ST_ER_INSTALLING01="Erreur d'installation"
ST_ER_INSTALLING02="nom de produit incorrect"
ST_RES_INST_DIR="Saisir le rpertoire d'installation pour Adobe Reader"
ST_ER_SAME_FILE_NAME_AS_DIR="existe mais n'est pas un rpertoire. Spcifiez un autre emplacement."
ST_DIR_INFO01="Le rpertoire"
ST_DIR_INFO02="n'existe pas."
ST_QUES_CREAT_DIR="Voulez-vous le crer maintenant ? [o] "
ST_ER_EXIT="Fin de l'installation..."
ST_ER_DIR="ERREUR : impossible de crer le rpertoire"
ST_ER_WRITE="ERREUR : impossible d'crire dans le rpertoire"
ST_ER_NO_LIBCURL01="Fichier libcurl.so introuvable. Certaines fonctions d'Adobe Reader risquent d'tre entraves."
ST_ER_NO_LIBCURL02="Il est recommand d'installer curl ver."
ST_ER_NO_LIBCURL03="ou une version ultrieure  ver."
ST_WARN_NO_LIBSSL01="AVERTISSEMENT : la version de libssl.so sur votre ordinateur n'est pas compatible avec libssl.so.0.9.6."
ST_WARN_NO_LIBSSL02="Installez libssl.so.0.9.6."
ST_WARN_LD_LIB01="existe dans le rpertoire"
ST_WARN_LD_LIB02="mais le rpertoire n'est pas inclus dans LD_LIBRARY_PATH."
ST_WARN_LD_LIB03="Veuillez inclure le rpertoire"
ST_WARN_LD_LIB04="dans LD_LIBRARY_PATH"
ST_WARN_LD_LIB05="existe dans le rpertoire"
ST_ER_NO_CONFIG="ERREUR : aucune configuration dtecte ... abandon"
ST_WARN_NO_CONFIG="AVERTISSEMENT : l'excution de la configuration choisie est impossible sur la plate-forme active."
ST_QUE_CONT="Voulez-vous continuer l'installation ?"
ST_INFO_DEF_CONFIG1="Installer la configuration par dfaut"
ST_INFO_DEF_CONFIG2="Les configurations suivantes sont disponibles pour l'installation :"
ST_QUE_CONFIG="Saisir le numro de configuration  installer : "
ST_EXIT_INFO="Quitter le programme d'installation d'Acrobat"
ST_PLAT_INDEP_FILES="Installation des fichiers indpendants de la plate-forme... "
ST_PLAT_DEP_FILES="Installation des fichiers dpendants de la plate-forme... "
ST_RPM_CAN_NOT_DEL="suppression impossible, car des fichiers supplmentaires n'ont pas t installs par RPM"
ST_WEL_ALK="Bienvenue dans le programme d'installation du kit de langues asiatiques"
ST_INFO_ALK01="Cette installation ne fonctionne pas sans"
ST_INFO_ALK02="l'installation pralable d'Adobe Reader pour Unix version 7.0."
ST_INFO_ALK03="Si vous ne disposez pas d'Adobe Reader version 7.0 sur votre"
ST_INFO_ALK04="systme, installez-le avant de procder  l'installation du kit de langues asiatiques."
ST_ER_ALK01="ERREUR : le rpertoire doit tre un chemin absolu."
ST_ER_ALK02="ERREUR : le rpertoire "
ST_ER_ALK03="n'existe pas."
ST_ER_ALK04="ERREUR : le fichier AcroVersion n'existe pas."
ST_ER_ALK05="ERREUR : version d'Acrobat incorrecte :"
ST_ER_ALK06="ERREUR : distribution introuvable ... abandon"
ST_IF_ALK07="Saisir l'emplacement d'installation d'Adobe Reader"
ST_INFO_ALK_CMPLT="Installation termine."
ST_WEL_HLK="Programme d'installation du module tendu de prise en charge linguistique."
ST_INFO_HLK04="systme, installez-le avant de procder  l'installation du module tendu de prise en charge linguistique."
ST_INFO_HLK05="Installation des fichiers du module tendu de prise en charge linguistique... "
ST_WEL_CLK="Programme d'installation du module de prise en charge des polices de caractres d'Europe centrale."
ST_INFO_CLK04="systme, installez-le avant de procder  l'installation du module de prise en charge des polices de caractres d'Europe centrale."
ST_INFO_CLK05="Installation des fichiers du module de prise en charge linguistique d'Europe centrale... "
ST_ER_AR01="ERREUR : impossible de dterminer le rpertoire actuel"
ST_ER_AR02="ERREUR : rpertoire d'installation introuvable"
ST_ER_AR03="ERREUR : impossible de trouver"
ST_INFO_AR01="Le systme d'exploitation "
ST_INFO_AR02="n'est pas install."
ST_INFO_AR03="Essayez l'excution sur une plate-forme installe, puis tablissez une connexion  votre cran."
ST_INFO_AR04="Parmi les plate-formes installes figurent les suivantes :"
ST_INFO_AR05="n'est pas install pour cette configuration,"
ST_IBP_MISC_03="Mozilla"
ST_IBP_MISC_04="Firefox"
ST_IBP_MISC_05="Netscape"
ST_IBP_MISC_06="Quitter"
ST_IBP_INFO_01="L'installation du module externe de navigation pour acroread va s'effectuer."
ST_IBP_INFO_02="Effectuer l'installation globale"
ST_IBP_INFO_03="Effectuer l'installation spcifique  l'utilisateur"
ST_IBP_INFO_04="Saisir la slection voulue"
ST_IBP_INFO_05="Voulez-vous installer un autre navigateur ?"
ST_IBP_INFO_06="Entrer le rpertoire d'installation pour Adobe Reader 7.0"
ST_IBP_INFO_07="Entrer le rpertoire d'installation du navigateur"
ST_IBP_INFO_08="Le module externe est dj install. Voulez-vous vraiment le remplacer? "
ST_IBP_INFO_09="Installation annule"
ST_IBP_INFO_10="Installation russie."
ST_IBP_INFO_11="Cela va activer le module externe pour Mozilla, Firefox et Netscape."
ST_IBP_INFO_12="Si vous rencontrez un problme lors de l'installation pour votre navigateur, copiez le fichier suivant dans le dossier plugin du navigateur :"
ST_IBP_INFO_13="chemin Acroread spcifi"
ST_IBP_INFO_14="Appuyez sur Entre pour continuer"
ST_IBP_INFO_15="En cas de difficults, reportez-vous  la documentation accompagnant le navigateur pour des informations supplmentaires relatives aux nouveaux modules externes."
ST_IBP_INFO_16="Installation du module externe dans"
ST_IBP_INFO_17="Voulez-vous effectuer une installation automatique ?"
ST_IBP_INFO_18="Installation automatique termine."
ST_IBP_INFO_19="Voulez-vous effectuer une installation manuelle ?"
ST_IBP_INFO_20="Voulez-vous installer le module externe de navigation ?"
ST_IBP_INFO_21="Installation du module externe de navigation ignore."
ST_IBP_INFO_22_1="Excuter"
ST_IBP_INFO_22_2="pour installer le module externe de navigation."
ST_IBP_INFO_23="a t ajout."
ST_IBP_INFO_24="Tentative d'installation du module externe pour le navigateur"
ST_IBP_INFO_25="Echec de l'installation"
ST_IBP_ERR_01="Fichier du module externe de navigation introuvable"
ST_IBP_ERR_02="Dossier des modules externes de navigation introuvable"
ST_IBP_ERR_03="Dossier du navigateur introuvable"
ST_IBP_ERR_04="Impossible de supprimer la version prcdente du module externe de"
ST_IBP_ERR_05_1="Impossible de copier le fichier du module externe"
ST_IBP_ERR_05_2="vers"
ST_IBP_ERR_06="Impossible de crer le rpertoire"
ST_IBP_ERR_07="Script d'installation du module externe de navigation introuvable."
ST_IBP_ERR_08="existe dj comme fichier spcial et ne peut pas le remplacer."
ST_IBP_ERR_09="Impossible d'obtenir la variable HOME dans l'environnement. Rpertoire de base introuvable."
ST_IBP_ERR_10="Dossier d'installation introuvable"
ST_IBP_ERR_11="ERREUR INTERNE... Aucun nom de systme d'exploitation correspondant."
ST_SEP_INFO_01="Entrer le rpertoire d'installation pour Adobe Reader 7.0"
ST_SEP_INFO_02="ERREUR INTERNE... Aucun nom de systme d'exploitation correspondant."
ST_SEP_INFO_03="Fichiers appropris introuvables dans le chemin d'installation."
ST_SEP_INFO_04="Rinitialisation des anciens contextes"
ST_SEP_INFO_05="Dfinition de nouveaux contextes pour les fichiers de bibliothque"
ST_SEP_INFO_06="Les fichiers de bibliothque seront mis  jour pour les rendre compatibles avec SELinux."
ST_SEP_INFO_07="Dossier d'installation introuvable."
ST_SEP_INFO_08="Dfinition des contextes termine. Consultez le journal sur"
ST_SEP_INFO_09="Echec de la commande"
ST_SEP_INFO_10="Le correctif n'est peut-tre pas correctement install. Consultez le journal sur"
ST_IOP_ERR1="Le module externe OpenOffice PDF n'a pas pu tre enregistr. Lisez les instructions dans "
ST_IOP_ERR2="pour l'installation manuelle."
ST_IOP_ERR3="L'excution du module externe OpenOffice PDF requiert OpenOffice >= 1.9. Etape d'enregistrement du module ignore."
ST_IOP_ERR4="Le fichier binaire soffice d'OpenOffice est introuvable dans le rpertoire spcifi."
ST_IOP_INFO_01="Spcifiez le rpertoire d'installation d'OpenOffice : "
ST_IOP_INFO_02="Voulez-vous installer le module externe OpenOffice ?"
ST_IAP_ERR1="Le module externe Adobe PDF n'a pas pu tre enregistr. Rfrez-vous aux instructions dans "
ST_IAP_INFO_01="Voulez-vous installer le module externe Adobe PDF ?"
ST_IFE_INFO_01="Voulez-vous installer le module externe de l'extension Firefox ?"
ST_IFE_INFO_02="Indiquez le chemin d'accs du fichier d'excution de Firefox : "
ST_IFE_ERR_01="Le fichier d'excution de Firefox est introuvable ou ne dispose pas d'autorisations d'excution."
ST_IDI_INFO_01="Voulez-vous installer Distiller ?"
ST_MIME_INFO_01="Ouvrez une nouvelle session pour appliquer les modifications apportes aux types et icnes MIME."
true
}

setLangFRA

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


