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


set_lang_FRA()
{
    ST_QUES_SKIP_MOZILLA_PATH="Vous n\'avez pas saisi le répertoire d\'installation pour mozilla/firefox/xulrunner, voulez-vous vraiment continuer ?"
    ST_ER_SAME_FILE_NAME_AS_DIR="%s existe mais n\'est pas un répertoire. Spécifiez un autre emplacement."
    ST_QUES_MOZILLA_INSTALL_DIR="Entrez le nom du répertoire où mozilla, firefox ou xulrunner est installé :"
    ST_WARN_NO_MOZILLA_PATH="Certaines fonctionnalités telles que Adobe Help, DownTown et HowTo nécessitent les bibliothèques mozilla/firefox/xulrunner et risquent de ne pas fonctionner correctement. L\'accès à ces bibliothèques peut être configuré ultérieuremennt en définissant le paramètre MOZILLA_COMP_PATH avec le chemin d\'accès des bibliothèques mozilla, firefox ou xulrunner avant de lancer Adobe Reader."
    ST_DONE_WORD="Terminer"
    ST_SMALL_N="n"
    ST_INSTALL_OPT05="%d. Acrobat Reader %s pour SPARC/Solaris 2.x."
    ST_ER_INVALID_RESP1="ERREUR : réponse incorrecte, attente de %s ou %s."
    ST_ER_NO_CONFIG="ERREUR : aucune configuration détectée ... abandon"
    ST_INSTALL_OPT08="%d. Acrobat Reader %s pour Intel/Linux."
    ST_QUE_CONFIG="Saisir le numéro de configuration à installer : "
    ST_INSTALL_OPT03="%d. Acrobat %s pour AIX."
    ST_INSTALL_OPT01="%d. Acrobat %s pour SPARC/Solaris 2.x."
    ST_INSTALL_OPT06="%d. Acrobat Reader %s pour HP-UX."
    ST_MIME_INFO_01="Ouvrez une nouvelle session pour appliquer les modifications apportées aux types et icônes MIME."
    ST_ER_DIR="ERREUR : impossible de créer le répertoire %s."
    ST_YES="oui"
    ST_CAPS_N="N"
    ST_WARN_NO_CONFIG="AVERTISSEMENT : l\'exécution de la configuration choisie est impossible sur la plate-forme active (%s/%s)."
    ST_PLAT_INDEP_FILES="Installation des fichiers indépendants de la plate-forme... "
    ST_QUES_CREAT_DIR="Voulez-vous le créer maintenant ? [o] "
    ST_PLAT_DEP_FILES="Installation des fichiers dépendants de la plate-forme... "
    ST_QUE_CONT="Voulez-vous continuer l\'installation ? "
    ST_RES_INST_DIR="Entrer le répertoire d\'installation pour Adobe Reader %s [%s] "
    ST_DIR_INFO01="Le répertoire %s n\'existe pas."
    ST_IBP_ERR_07="Script d\'installation du module externe de navigation introuvable."
    ST_CAPS_Y="O"
    ST_INSTALL_OPT02="%d. Acrobat %s pour HP-UX."
    ST_ER_EXIT="Fin de l\'installation..."
    ST_INSTALL_OPT09="%d. Quitter le programme d\'installation d\'Acrobat."
    ST_INSTALL_OPT04="%d. Acrobat %s pour Intel/Linux."
    ST_NO="non"
    ST_INFO_DEF_CONFIG2="Les configurations suivantes sont disponibles pour l\'installation :"
    ST_FREE_SPACE_INFO01="Cette installation nécessite %s Mo d\'espace disque."
    ST_ER_INVALID_RESP2="ERREUR : réponse incorrecte ... réessayez"
    ST_SMALL_Y="o"
    ST_ER_WRITE="ERREUR : impossible d\'écrire dans le répertoire %s."
    ST_INSTALL_OPT07="%d. Acrobat Reader %s pour AIX."
}


set_lang_FRA_utf()
{
    ST_QUES_SKIP_MOZILLA_PATH="Vous n\'avez pas saisi le rÃ©pertoire d\'installation pour mozilla/firefox/xulrunner, voulez-vous vraiment continuer ?"
    ST_ER_SAME_FILE_NAME_AS_DIR="%s existe mais n\'est pas un rÃ©pertoire. SpÃ©cifiez un autre emplacement."
    ST_QUES_MOZILLA_INSTALL_DIR="Entrez le nom du rÃ©pertoire oÃ¹ mozilla, firefox ou xulrunner est installÃ© :"
    ST_WARN_NO_MOZILLA_PATH="Certaines fonctionnalitÃ©s telles que Adobe Help, DownTown et HowTo nÃ©cessitent les bibliothÃ¨ques mozilla/firefox/xulrunner et risquent de ne pas fonctionner correctement. L\'accÃ¨s Ã  ces bibliothÃ¨ques peut Ãªtre configurÃ© ultÃ©rieuremennt en dÃ©finissant le paramÃ¨tre MOZILLA_COMP_PATH avec le chemin d\'accÃ¨s des bibliothÃ¨ques mozilla, firefox ou xulrunner avant de lancer Adobe Reader."
    ST_DONE_WORD="Terminer"
    ST_SMALL_N="n"
    ST_INSTALL_OPT05="%d. Acrobat Reader %s pour SPARC/Solaris 2.x."
    ST_ER_INVALID_RESP1="ERREUR : rÃ©ponse incorrecte, attente de %s ou %s."
    ST_ER_NO_CONFIG="ERREUR : aucune configuration dÃ©tectÃ©e ... abandon"
    ST_INSTALL_OPT08="%d. Acrobat Reader %s pour Intel/Linux."
    ST_QUE_CONFIG="Saisir le numÃ©ro de configuration Ã  installer : "
    ST_INSTALL_OPT03="%d. Acrobat %s pour AIX."
    ST_INSTALL_OPT01="%d. Acrobat %s pour SPARC/Solaris 2.x."
    ST_INSTALL_OPT06="%d. Acrobat Reader %s pour HP-UX."
    ST_MIME_INFO_01="Ouvrez une nouvelle session pour appliquer les modifications apportÃ©es aux types et icÃ´nes MIME."
    ST_ER_DIR="ERREUR : impossible de crÃ©er le rÃ©pertoire %s."
    ST_YES="oui"
    ST_CAPS_N="N"
    ST_WARN_NO_CONFIG="AVERTISSEMENT : l\'exÃ©cution de la configuration choisie est impossible sur la plate-forme active (%s/%s)."
    ST_PLAT_INDEP_FILES="Installation des fichiers indÃ©pendants de la plate-forme... "
    ST_QUES_CREAT_DIR="Voulez-vous le crÃ©er maintenant ? [o] "
    ST_PLAT_DEP_FILES="Installation des fichiers dÃ©pendants de la plate-forme... "
    ST_QUE_CONT="Voulez-vous continuer l\'installation ? "
    ST_RES_INST_DIR="Entrer le rÃ©pertoire d\'installation pour Adobe Reader %s [%s] "
    ST_DIR_INFO01="Le rÃ©pertoire %s n\'existe pas."
    ST_IBP_ERR_07="Script d\'installation du module externe de navigation introuvable."
    ST_CAPS_Y="O"
    ST_INSTALL_OPT02="%d. Acrobat %s pour HP-UX."
    ST_ER_EXIT="Fin de l\'installation..."
    ST_INSTALL_OPT09="%d. Quitter le programme d\'installation d\'Acrobat."
    ST_INSTALL_OPT04="%d. Acrobat %s pour Intel/Linux."
    ST_NO="non"
    ST_INFO_DEF_CONFIG2="Les configurations suivantes sont disponibles pour l\'installation :"
    ST_FREE_SPACE_INFO01="Cette installation nÃ©cessite %s Mo d\'espace disque."
    ST_ER_INVALID_RESP2="ERREUR : rÃ©ponse incorrecte ... rÃ©essayez"
    ST_SMALL_Y="o"
    ST_ER_WRITE="ERREUR : impossible d\'Ã©crire dans le rÃ©pertoire %s."
    ST_INSTALL_OPT07="%d. Acrobat Reader %s pour AIX."
}

if echo $LANG | grep -i utf >/dev/null; then
    set_lang_FRA_utf
else
    set_lang_FRA
fi

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

    if $TestCmd -e . 2>/dev/null; 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
        printf "%s\n" "`pwd`/$lfile"
        cd "$OLDPWD"
        return 0
    fi

    cd "$OLDPWD"
    return 1
}


MkTempInternal()
{
    if [ "${mktemp_count+set}" != "set" ]; then
        mktemp_count="0"
    fi

    mktemp_file="/tmp/acrobat.$$.${mktemp_count}"

    while /usr/bin/test -e "$mktemp_file"
    do
        mktemp_count="`expr $mktemp_count + 1`"
        mktemp_file="/tmp/acrobat.$$.${mktemp_count}"
    done

    touch "$mktemp_file" && chmod 600 "$mktemp_file" && echo "$mktemp_file"
}

MkTemp()
{
    template="tmp.XXXXXXXXXX";
    MKTEMP="`Which mktemp 2>/dev/null`";
    if [ "$MKTEMP" != "" ]; then
	    :
    else
	    MKTEMP="MkTempInternal";
    fi

    $MKTEMP /tmp/acrobat.$template
}


yesno()
{
  msg="$1"
  def="$2"
  while : ; do
    printf "\n%s" "$msg"
    read answer
    if [ "$answer" ] ; then
      case "$answer" in
        "$ST_SMALL_Y" | "$ST_CAPS_Y" | "$ST_YES")
          return 0
          ;;
        "$ST_SMALL_N" | "$ST_CAPS_N" | "$ST_NO")
          return 1
          ;;
        *)
          printf "$ST_ER_INVALID_RESP1\n" "$ST_YES" "$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`

  printf "$ST_FREE_SPACE_INFO01\n" "${megs}"
}


ExtractFiles ()
{
   prev_directory="`pwd 2> /dev/null`"
   cd "$1" 

   case "`uname -s`" in
	 Linux)
		tar -xvpf "$2" ;;
	 HP-UX)
		tar xfo "$2" && tar tf "$2" ;;
     *)
		tar xpfo "$2" && tar tf "$2" ;;
   esac | sed -e "s#^#${1}/#" >> "$installLogFile"

   cd "$prev_directory"
}


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

  printf "\n"

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

  if [ -z "$msg" ] ; then
    printf "%s\n" "$ST_DONE_WORD"
  fi
}


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

    case "$var" in
    /*) ;;
    *)  var="`pwd`/${var}" ;;
	esac

    printf "%s" "$var"
}


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

  while [ -z "$InstallDir" ] ; do

    InstallDir="$defdir"

    printf "\n$ST_RES_INST_DIR" "${Version}" "${InstallDir}"
    read answer
    case "$answer" in
      "")
        ;;
      *)
        eval InstallDir=\"$answer\"
        ;;
    esac

    InstallDir="`ExpandDirPath "$InstallDir"`"

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

    if [ ! -d "$InstallDir" ] ; then
      printf "\n$ST_DIR_INFO01\n\n" "\"$InstallDir\""
      while :
      do
          printf "%s" "$ST_QUES_CREAT_DIR"
          read answer

          case "$answer" in
            "$ST_SMALL_Y" | "$ST_CAPS_Y" | "" )
                mkdir -p "$InstallDir"
                break ;;
            "$ST_SMALL_N" | "$ST_CAPS_N" )
                printf "%s\n" "$ST_ER_EXIT"
                exit 0 ;;
            *)
                printf "%s\n" "$ST_ER_INVALID_RESP2"
          esac
      done

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


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

 

  ReadInstallDir="$InstallDir"
}


Which()
{
    OLD_IFS="$IFS"
    IFS=":"
    status=1

    for i in $PATH; do
        if [ -x "$i/$1" ]; then
            printf "%s\n" "$i/$1"
            status=0
            break
        fi
    done

    IFS="$OLD_IFS"
    return $status
}


#Make Soft Links To gnome-speech libraries
MakeLibGnomeSpeechLinks()
{
    install_dir="$1/Adobe/Reader8/Reader"
    configured_dir="$2"
    lib_dir="$install_dir/$configured_dir/lib"

    if TESTSPEECHEXEC="`Which test-speech`" && Which ldd >/dev/null && Which awk >/dev/null; then
        rm -f "$lib_dir/libORBit-2.so" 2>/dev/null
        rm -f "$lib_dir/libbonobo-2.so" 2>/dev/null
        rm -f "$lib_dir/libbonobo-activation.so" 2>/dev/null
        rm -f "$lib_dir/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" "$lib_dir/libORBit-2.so" && record_config remove "$lib_dir/libORBit-2.so"
            ln -s "$lib_bonobo" "$lib_dir/libbonobo-2.so" && record_config remove "$lib_dir/libbonobo-2.so"
            ln -s "$lib_bonoboactivation" "$lib_dir/libbonobo-activation.so" && record_config remove "$lib_dir/libbonobo-activation.so"
            ln -s "$lib_gnomespeech" "$lib_dir/libgnomespeech.so" && record_config remove "$lib_dir/libgnomespeech.so"
        fi
    fi
}


MakeLibLDAPLinks()
{
install_dir="$1/Adobe/Reader8/Reader"

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

	LIB_LDAP="`ls -tr /usr/lib/libldap.so*  2>/dev/null | tail -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 -1`"
	fi

	if [ "$LIB_LDAP" != "" ] 
	then
		ln -s "$LIB_LDAP" "$install_dir/intellinux/lib/libldap.so" && record_config remove "$install_dir/intellinux/lib/libldap.so"
	fi
fi

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

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

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

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


InstallBrowserPlugin()
{
    install_dir="$1"
    opts="-silent -global -user"

    if [ -f "$install_dir/Adobe/Reader8/Browser/install_browser_plugin" ]; then
        "$install_dir/Adobe/Reader8/Browser/install_browser_plugin" $opts "$install_dir"
    else
        printf "\n%s\n" "$ST_IBP_ERR_07"
        exit 1
    fi
}


MakeMozillaConfig()
{
    install_dir="$1"

    for i in /etc/gre.d/gre.conf /etc/gre.d/firefox.conf /etc/gre.d/mozilla.conf /etc/gre.d/*.conf /etc/gre.conf
    do
        if [ -f "$i" ] && grep "^GRE_PATH=" "$i" >/dev/null 2>&1; then
            return;
        fi
    done

    while :; do
        printf "$ST_QUES_MOZILLA_INSTALL_DIR "
        read mozilla_dir

        if [ -n "$mozilla_dir" ]; then
            if [ -d "$mozilla_dir" ]; then
                if [ -f "$mozilla_dir/libgtkembedmoz.so" ]; then
                    break
                elif [ -f "$mozilla_dir/lib/libgtkembedmoz.so" ]; then
                    mozilla_dir="$mozilla_dir/lib"
                    break
                fi
            fi
        else
            while :
            do
                printf "$ST_QUES_SKIP_MOZILLA_PATH [$ST_SMALL_Y/$ST_SMALL_N]: "
                read REPLY
                case "$REPLY" in
                    $ST_SMALL_Y|$ST_CAPS_Y)
                        printf "\n%s\n" "$ST_WARN_NO_MOZILLA_PATH"
                        break 2;;
                    $ST_SMALL_N|$ST_SMALL_N) break ;;
                esac
            done
        fi
    done

    if [ -n "$mozilla_dir" ]; then
        config_file="$install_dir/Adobe/Reader8/Reader/GlobalPrefs/mozilla_config"
        mozilla_dir="`echo $mozilla_dir | sed -e 's/\"/\\\\\"/g'`"
        echo "MOZILLA_COMP_PATH=\"$mozilla_dir\"" > "$config_file"
        echo "export MOZILLA_COMP_PATH" >> "$config_file"
        record_config remove "$config_file"
    fi
}


record_config()
{
    config_file="$ReadInstallDir/Adobe/Reader8/Reader/GlobalPrefs/.config"
    echo "$@" >> "$config_file"
}


install_icon()
{
    PATH="$PATH:$ReadInstallDir/Adobe/Reader8/Reader/intellinux/bin" xdg-icon-resource install "$@" 2>/dev/null

    if [ $? -eq 0 ]; then
        record_config uninstall_icon "$@"
    fi
}


install_desktop_menu()
{
    eval desktop_file="\$$#"
    tempfile="`MkTemp`"

    PATH="$PATH:$ReadInstallDir/Adobe/Reader8/Reader/intellinux/bin" xdg-desktop-menu uninstall --mode system "$@" >/dev/null 2>&1
    PATH="$PATH:$ReadInstallDir/Adobe/Reader8/Reader/intellinux/bin" xdg-desktop-menu uninstall --mode user "$@" >/dev/null 2>&1
    sed -e "s#^Exec=acroread#Exec=$ReadInstallDir/Adobe/Reader8/bin/acroread#g" < "$desktop_file" > "$tempfile"
    mv -f "$tempfile" "$desktop_file"
    PATH="$PATH:$ReadInstallDir/Adobe/Reader8/Reader/intellinux/bin" xdg-desktop-menu install "$@" 2>/dev/null

    if [ $? -eq 0 ]; then
        record_config uninstall_desktop_menu "$@"
    fi
}


install_desktop_icon()
{
    eval desktop_file="\$$#"
    tempfile="`MkTemp`"

    PATH="$PATH:$ReadInstallDir/Adobe/Reader8/Reader/intellinux/bin" xdg-desktop-icon uninstall "$@" 2>/dev/null
    sed -e "s#^Exec=acroread#Exec=$ReadInstallDir/Adobe/Reader8/bin/acroread#g" < "$desktop_file" > "$tempfile"
    mv -f "$tempfile" "$desktop_file"
    PATH="$PATH:$ReadInstallDir/Adobe/Reader8/Reader/intellinux/bin" xdg-desktop-icon install "$@" 2>/dev/null

    if [ $? -eq 0 ]; then
        chmod 777 "$HOME/Desktop/`basename "$desktop_file"`" 2>/dev/null
        record_config uninstall_desktop_icon "$@"
    fi
}


install_mime()
{
    PATH="$PATH:$ReadInstallDir/Adobe/Reader8/Reader/intellinux/bin" xdg-mime install "$@" 2>/dev/null

    if [ $? -eq 0 ]; then
        record_config uninstall_icon "$@"
    fi
}


InstallIcons()
{
    install_dir="$1/Adobe/Reader8/Resource/Icons"

    for icon_size in 16 20 22 24 32 36 48 64 96 128 192; do
        install_icon --noupdate --novendor --context apps --size $icon_size "$install_dir/${icon_size}x${icon_size}/AdobeReader8.png"
        install_icon --noupdate --novendor --context apps --size $icon_size "$install_dir/${icon_size}x${icon_size}/adobe.pdf.png"
        install_icon --noupdate --novendor --context mimetypes --size $icon_size "$install_dir/${icon_size}x${icon_size}/adobe.pdf.png" 'application-pdf'
        install_icon --noupdate --novendor --context apps --size $icon_size "$install_dir/${icon_size}x${icon_size}/vnd.fdf.png"
        install_icon --noupdate --novendor --context mimetypes --size $icon_size "$install_dir/${icon_size}x${icon_size}/vnd.fdf.png" 'application-vnd.fdf'
        install_icon --noupdate --novendor --context apps --size $icon_size "$install_dir/${icon_size}x${icon_size}/vnd.adobe.pdx.png"
        install_icon --noupdate --novendor --context mimetypes --size $icon_size "$install_dir/${icon_size}x${icon_size}/vnd.adobe.pdx.png" 'application-vnd.adobe.pdx'
        install_icon --noupdate --novendor --context apps --size $icon_size "$install_dir/${icon_size}x${icon_size}/vnd.adobe.xdp+xml.png"
        install_icon --noupdate --novendor --context mimetypes --size $icon_size "$install_dir/${icon_size}x${icon_size}/vnd.adobe.xdp+xml.png" 'application-vnd.adobe.xdp+xml'
        install_icon --noupdate --novendor --context apps --size $icon_size "$install_dir/${icon_size}x${icon_size}/vnd.adobe.xfdf.png"
        install_icon --noupdate --novendor --context mimetypes --size $icon_size "$install_dir/${icon_size}x${icon_size}/vnd.adobe.xfdf.png" 'application-vnd.adobe.xfdf'
    done
}


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
        printf "$ST_ER_SAME_FILE_NAME_AS_DIR\n" "\"$ReadInstallDir\""
        exit 1
    fi

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

    if [ $? -ne 0 ]; then
        printf "$ST_ER_DIR\n" "\"$InstallDir\""
        exit 1
    fi

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

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

  installLogFile="`MkTemp`"
  printf "%s\n" "$ReadInstallDir"

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

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

  rm -f /usr/bin/acroread 2>/dev/null && \
  ln -s "$ReadInstallDir/Adobe/Reader8/bin/acroread" /usr/bin/acroread 2>/dev/null && \
  record_config remove /usr/bin/acroread

  if [ "`uname -s`" = "Linux" ]; then
      MakeLibLDAPLinks "$ReadInstallDir"
      
      if Which kde-config >/dev/null; 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

      if GNOME_BASE_DIR="`Which gnome-open`"; 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

      InstallIcons "$ReadInstallDir"
      install_mime --novendor "$ReadInstallDir/Adobe/Reader8/Resource/Support/AdobeReader.xml"

      for i in application/pdf application/vnd.adobe.xfdf application/vnd.fdf application/vnd.adobe.xdp+xml application/vnd.adobe.pdx application/fdf application/xdp application/xfdf application/pdx; do
        PATH="$PATH:$ReadInstallDir/Adobe/Reader8/Reader/intellinux/bin" xdg-mime default "$ReadInstallDir/Adobe/Reader8/Resource/Support/AdobeReader.desktop" "$i" 2>/dev/null
      done

      install_desktop_menu --novendor "$ReadInstallDir/Adobe/Reader8/Resource/Support/AdobeReader.desktop"
      install_desktop_icon --novendor "$ReadInstallDir/Adobe/Reader8/Resource/Support/AdobeReader.desktop"
      PATH="$PATH:$ReadInstallDir/Adobe/Reader8/Reader/intellinux/bin" xdg-icon-resource forceupdate >/dev/null 2>&1
  fi

  sort -r < "$installLogFile" | \
  while read REPLY
  do
     record_config remove "$REPLY"
  done

  rm -f "$installLogFile"

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

  InstallBrowserPlugin "$ReadInstallDir" >/dev/null 2>&1

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


ShowUsage()
{
	printf "%s\n" "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


Version=8.1.4

#
# 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* | */ILINXRPRO.TAR* | */ilinxrpro.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
  printf "\n%s\n" "$ST_ER_NO_CONFIG"
  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
  printf "%s\n" "$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
    #

    printf "\n%s\n" "$ST_INFO_DEF_CONFIG2"

    if [ "$AcroSparcSolarisNum" ] ; then
      printf "$ST_INSTALL_OPT01\n" "$AcroSparcSolarisNum" "${Version}"
    fi
    if [ "$AcroHppaHpuxNum" ] ; then
      printf "$ST_INSTALL_OPT02\n" "$AcroHppaHpuxNum" "${Version}"
    fi
    if [ "$AcroRS6000AIXNum" ] ; then
      printf "$ST_INSTALL_OPT03\n" "$AcroRS6000AIXNum" "${Version}"
    fi
    if [ "$AcroIntelLinuxNum" ] ; then
      printf "$ST_INSTALL_OPT04\n" "$AcroIntelLinuxNum" "${Version}"
    fi
    if [ "$ReadSparcSolarisNum" ] ; then
      printf "$ST_INSTALL_OPT05\n" "$ReadSparcSolarisNum" "${Version}"
    fi
    if [ "$ReadHppaHpuxNum" ] ; then
      printf "$ST_INSTALL_OPT06\n" "$ReadHppaHpuxNum" "${Version}"
    fi
    if [ "$ReadRS6000AIXNum" ] ; then
      printf "$ST_INSTALL_OPT07\n" "$ReadRS6000AIXNum" "${Version}"
    fi
    if [ "$ReadIntelLinuxNum" ] ; then
      printf "$ST_INSTALL_OPT08\n" "$ReadIntelLinuxNum" "${Version}"
    fi
    if [ "$ExitNum" ] ; then
        printf "$ST_INSTALL_OPT09\n" "${ExitNum}"
    fi

    printf "\n%s" "$ST_QUE_CONFIG"
    read ConfigNum

  fi


  #
  # Install the configuration
  #

  if [ -z "$ConfigNum" ] ; then
    printf "\n%s\n" "$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
    printf "%s\n" "$ST_ER_INVALID_RESP2"
    continue
  fi

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

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

  NumConfigs=`expr $NumConfigs - 1`

done

printf "\n"
exit 0
