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


set_lang_NOR()
{
    ST_QUES_SKIP_MOZILLA_PATH="Du angav ikke installasjonsmappen for Mozilla/Firefox/XULRunner. Vil du hoppe over dette"
    ST_ER_SAME_FILE_NAME_AS_DIR="finnes, men er ikke en mappe. Angi en annen plassering."
    ST_QUES_MOZILLA_INSTALL_DIR="Angi mappen der Mozilla eller Firefox eller XULRunner er installert:"
    ST_WARN_NO_MOZILLA_PATH="Noen funksjoner, for eksempel Adobe Help, DownTown og HowTo, krever mozilla/firefox/xulrunner-bibliotek, og fungerer kanskje ikke som de skal. Dette kan bli ordnet senere, ved å angi MOZILLA_COMP_PATH som bane til bibliotekene for mozilla eller firefox eller xulrunner libraries før du starter Adobe Reader."
    ST_DONE_WORD="Ferdig"
    ST_SMALL_N="n"
    ST_INSTALL_OPT05="%d. Acrobat Reader %s for SPARC/Solaris 2.x."
    ST_ER_INVALID_RESP1="Feil! Ugyldig svar, forventet %s eller %s."
    ST_ER_NO_CONFIG="Feil!  Ingen konfigurasjoner funnet ... avbryter"
    ST_INSTALL_OPT08="%d. Acrobat Reader %s for Intel/Linux."
    ST_QUE_CONFIG="Angi konfigurasjonsnummeret for å installere:"
    ST_INSTALL_OPT03="%d. Acrobat %s for AIX."
    ST_INSTALL_OPT01="%d. Acrobat %s for SPARC/Solaris 2.x."
    ST_INSTALL_OPT06="%d. Acrobat Reader %s for HP-UX."
    ST_MIME_INFO_01="Logg på på nytt for å ta i bruk endringer i MIME-typer og -ikoner."
    ST_ER_DIR="Feil! Kan ikke opprette mappen %s."
    ST_YES="ja"
    ST_CAPS_N="N"
    ST_WARN_NO_CONFIG="Advarsel!  Den valgte konfigurasjonen kan ikke kjøres på gjeldende plattform (s%/%s)"
    ST_PLAT_INDEP_FILES="Installerer plattformuavhengige filer ..."
    ST_QUES_CREAT_DIR="Vil du opprette den nå? [j] "
    ST_PLAT_DEP_FILES="Installerer plattformavhengige filer ... "
    ST_QUE_CONT="Fortsette installasjonen?"
    ST_RES_INST_DIR="Angi installasjonsmappen for Adobe Reader %s [%s]"
    ST_DIR_INFO01="Mappen %s finnes ikke."
    ST_IBP_ERR_07="Fant ikke installasjonsskriptet for plugin-modulen for leseren."
    ST_CAPS_Y="J"
    ST_INSTALL_OPT02="%d. Acrobat %s for HP-UX."
    ST_ER_EXIT="Avslutter installasjonen ..."
    ST_INSTALL_OPT09="%d. Avslutt installasjon av Acrobat."
    ST_INSTALL_OPT04="%d. Acrobat %s for Intel/Linux."
    ST_NO="nei"
    ST_INFO_DEF_CONFIG2="Følgende konfigurasjoner er tilgjengelige for installasjon:"
    ST_FREE_SPACE_INFO01="Installasjonen krever %s MB ledig diskplass."
    ST_ER_INVALID_RESP2="Feil!  Ugyldig svar ... prøv på nytt"
    ST_SMALL_Y="j"
    ST_ER_WRITE="Feil!  Kan ikke skrive til mappen"
    ST_INSTALL_OPT07="%d. Acrobat Reader %s for AIX."
}


set_lang_NOR_utf()
{
    ST_QUES_SKIP_MOZILLA_PATH="Du angav ikke installasjonsmappen for Mozilla/Firefox/XULRunner. Vil du hoppe over dette"
    ST_ER_SAME_FILE_NAME_AS_DIR="finnes, men er ikke en mappe. Angi en annen plassering."
    ST_QUES_MOZILLA_INSTALL_DIR="Angi mappen der Mozilla eller Firefox eller XULRunner er installert:"
    ST_WARN_NO_MOZILLA_PATH="Noen funksjoner, for eksempel Adobe Help, DownTown og HowTo, krever mozilla/firefox/xulrunner-bibliotek, og fungerer kanskje ikke som de skal. Dette kan bli ordnet senere, ved Ã¥ angi MOZILLA_COMP_PATH som bane til bibliotekene for mozilla eller firefox eller xulrunner libraries fÃ¸r du starter Adobe Reader."
    ST_DONE_WORD="Ferdig"
    ST_SMALL_N="n"
    ST_INSTALL_OPT05="%d. Acrobat Reader %s for SPARC/Solaris 2.x."
    ST_ER_INVALID_RESP1="Feil! Ugyldig svar, forventet %s eller %s."
    ST_ER_NO_CONFIG="Feil!  Ingen konfigurasjoner funnet ... avbryter"
    ST_INSTALL_OPT08="%d. Acrobat Reader %s for Intel/Linux."
    ST_QUE_CONFIG="Angi konfigurasjonsnummeret for Ã¥ installere:"
    ST_INSTALL_OPT03="%d. Acrobat %s for AIX."
    ST_INSTALL_OPT01="%d. Acrobat %s for SPARC/Solaris 2.x."
    ST_INSTALL_OPT06="%d. Acrobat Reader %s for HP-UX."
    ST_MIME_INFO_01="Logg pÃ¥ pÃ¥ nytt for Ã¥ ta i bruk endringer i MIME-typer og -ikoner."
    ST_ER_DIR="Feil! Kan ikke opprette mappen %s."
    ST_YES="ja"
    ST_CAPS_N="N"
    ST_WARN_NO_CONFIG="Advarsel!  Den valgte konfigurasjonen kan ikke kjÃ¸res pÃ¥ gjeldende plattform (s%/%s)"
    ST_PLAT_INDEP_FILES="Installerer plattformuavhengige filer ..."
    ST_QUES_CREAT_DIR="Vil du opprette den nÃ¥? [j] "
    ST_PLAT_DEP_FILES="Installerer plattformavhengige filer ... "
    ST_QUE_CONT="Fortsette installasjonen?"
    ST_RES_INST_DIR="Angi installasjonsmappen for Adobe Reader %s [%s]"
    ST_DIR_INFO01="Mappen %s finnes ikke."
    ST_IBP_ERR_07="Fant ikke installasjonsskriptet for plugin-modulen for leseren."
    ST_CAPS_Y="J"
    ST_INSTALL_OPT02="%d. Acrobat %s for HP-UX."
    ST_ER_EXIT="Avslutter installasjonen ..."
    ST_INSTALL_OPT09="%d. Avslutt installasjon av Acrobat."
    ST_INSTALL_OPT04="%d. Acrobat %s for Intel/Linux."
    ST_NO="nei"
    ST_INFO_DEF_CONFIG2="FÃ¸lgende konfigurasjoner er tilgjengelige for installasjon:"
    ST_FREE_SPACE_INFO01="Installasjonen krever %s MB ledig diskplass."
    ST_ER_INVALID_RESP2="Feil!  Ugyldig svar ... prÃ¸v pÃ¥ nytt"
    ST_SMALL_Y="j"
    ST_ER_WRITE="Feil!  Kan ikke skrive til mappen"
    ST_INSTALL_OPT07="%d. Acrobat Reader %s for AIX."
}

if echo $LANG | grep -i utf >/dev/null; then
    set_lang_NOR_utf
else
    set_lang_NOR
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.3

#
# 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
