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


setLangNOR()
{
ST_LANG="NOR"
ST_LANG_SMALL="nor"
ST_READER_RPM_NAME="AdobeReader_nor"
ST_EXCHANGE_RPM_NAME="AdobeAcrobat_nor"
ST_COMMENT_WORD="Kommentar"
ST_DESCRIPTION_WORD="Beskrivelse"
ST_COMMENT_RPM="Start Adobe Reader 7.0"
ST_DES_RPM="Adobe Reader for Linux. Et program som kan vise, navigere i og skrive ut PDF-dokumenter."
ST_DES_TAG01="Adobe Reader kan lese dokumenter i PDF-format."
ST_DES_TAG02="I Adobe Reader kan du også søke i PDF-filer,"
ST_DES_TAG03="søke etter PDF-filer på Internett og gå gjennom dokumenter i samarbeid med andre."
ST_DES_TAG04="Hvis du vil ha mer informasjon, se www.adobe.no."
ST_THE_FILE="Filen"
ST_FOR="for"
ST_YES="ja"
ST_NO="nei"
ST_OR="eller"
ST_SMALL_Y="j"
ST_SMALL_N="n"
ST_CAPS_Y="J"
ST_CAPS_N="N"
ST_ACCEPT_CAPS="GODTA"
ST_DECLINE_CAPS="AVSLÅ"
ST_ACCEPT="godta"
ST_DECLINE="avslå"
ST_VERSION="versjon"
ST_STATEMENT_ACCEPT_DECLINE="Skriv inn \\\"godta\\\" hvis du godtar vilkårene i lisensavtalen. Skriv inn \\\"avslå\\\" hvis du vil avslutte. "
ST_RESTATEMENT_ACCEPT_DECLINE="Ugyldig svar. Bare \\\"godta\\\" eller \\\"avslå\\\" er gyldige svar. Vil du prøve på nytt?"
ST_ER_INVALID_RESP1="Feil!  Ugyldig svar, forventet"
ST_ER_INVALID_RESP2="Feil!  Ugyldig svar ... prøv på nytt"
ST_ER_INVALID_RESP3="... prøve på nytt?"
ST_ER_NO_LIC_FILE="Feil!  Finner ikke lisensfilen ... avbryter"
ST_TO_ACCEPT="Hvis du godtar vilkårene i denne avtalen, angir du"
ST_TO_DECLINE="Hvis du ikke godtar vilkårene i denne avtalen, angir du"
ST_REQ0101="Skriv inn"
ST_REQ0102="hvis du godtar vilkårene i lisensavtalen,"
ST_REQ0103="Skriv inn"
ST_REQ0104="for å avslutte."
ST_ER_LIC_NOT_ACCP="Du godtok ikke lisensavtalen ... avbryter installasjonen"
ST_FREE_SPACE_INFO01="Installasjonen krever"
ST_FREE_SPACE_INFO02="MB ledig diskplass."
ST_DONE_WORD="Ferdig"
ST_ER_INSTALLING01="Feil under installasjon av"
ST_ER_INSTALLING02="ugyldig produktnavn"
ST_RES_INST_DIR="Angi installasjonsmappen for Adobe Reader"
ST_ER_SAME_FILE_NAME_AS_DIR="finnes, men er ikke en mappe. Angi en annen plassering."
ST_DIR_INFO01="Mappen"
ST_DIR_INFO02="finnes ikke."
ST_QUES_CREAT_DIR="Vil du opprette den nå? [j] "
ST_ER_EXIT="Avslutter installasjonen ..."
ST_ER_DIR="Feil!  Kan ikke opprette mappen"
ST_ER_WRITE="Feil!  Kan ikke skrive til mappen"
ST_ER_NO_LIBCURL01="Fant ikke libcurl.so. Noe av funksjonaliteten i Adobe Reader kan bli redusert."
ST_ER_NO_LIBCURL02="Det anbefales å installere CURL-versjonen"
ST_ER_NO_LIBCURL03="eller en versjon etter versjon"
ST_WARN_NO_LIBSSL01="Advarsel!  Versjonen libssl.so på maskinen er ikke kompatibel med libssl.so.0.9.6."
ST_WARN_NO_LIBSSL02="Installer libssl.so.0.9.6."
ST_WARN_LD_LIB01="finnes i mappen ,"
ST_WARN_LD_LIB02="men denne mappen finnes ikke i LD_LIBRARY_PATH."
ST_WARN_LD_LIB03="Inkluder mappen"
ST_WARN_LD_LIB04="i LD_LIBRARY_PATH"
ST_WARN_LD_LIB05="finnes i mappen"
ST_ER_NO_CONFIG="Feil!  Ingen konfigurasjoner funnet ... avbryter"
ST_WARN_NO_CONFIG="Advarsel!  Den valgte konfigurasjonen kan ikke kjøres på gjeldende plattform"
ST_QUE_CONT="Fortsette med installasjonen?"
ST_INFO_DEF_CONFIG1="Installer standard konfigurasjon"
ST_INFO_DEF_CONFIG2="Følgende konfigurasjoner er tilgjengelige for installasjon:"
ST_QUE_CONFIG="Angi konfigurasjonsnummeret for å installere:"
ST_EXIT_INFO="Avslutt Acrobat-installasjonen"
ST_PLAT_INDEP_FILES="Installerer plattformuavhengige filer ..."
ST_PLAT_DEP_FILES="Installerer plattformavhengige filer ... "
ST_RPM_CAN_NOT_DEL="kunne ikke slettes fordi den har (en) ekstra filer som ikke ble installert av rpm"
ST_WEL_ALK="Velkommen til installasjonen av asiatisk språkverktøy."
ST_INFO_ALK01="Installasjonen vil ikke fungere hvis du ikke har"
ST_INFO_ALK02="Unix Adobe Reader versjon 7.0 installert før denne installasjonen."
ST_INFO_ALK03="Hvis du ikke allerede har Adobe Reader versjon 7.0 installert på"
ST_INFO_ALK04="maskinen, må du installere denne versjonen før du installerer det asiatiske språkverktøyet."
ST_ER_ALK01="Feil!  Mappe må være en absolutt bane"
ST_ER_ALK02="Feil!  Mappen"
ST_ER_ALK03="finnes ikke."
ST_ER_ALK04="Feil!  AcroVersion-filen finnes ikke."
ST_ER_ALK05="Feil!  Feil Acrobat-versjon:"
ST_ER_ALK06="Feil!  Finner ikke distribusjon ... avbryter"
ST_IF_ALK07="Angi plasseringen som du installerte Adobe Reader på"
ST_INFO_ALK_CMPLT="Installasjon fullført."
ST_WEL_HLK="Velkommen til installasjon av den utvidede språkpakken."
ST_INFO_HLK04="system. Gjør dette før du installerer den utvidede språkpakken."
ST_INFO_HLK05="Installerer filer fra den utvidede språkpakken ... "
ST_WEL_CLK="Velkommen til installasjon av pakken med sentraleuropeiske skrifter."
ST_INFO_CLK04="system. Gjør dette før du installerer pakken med sentraleuropeiske skrifter."
ST_INFO_CLK05="Installerer filer fra pakken med sentraleuropeiske skrifter ..."
ST_ER_AR01="Feil!  Kan ikke fastsette gjeldende mappe."
ST_ER_AR02="Feil!  Finner ikke installasjonsmappen."
ST_ER_AR03="Feil!  Finner ikke"
ST_INFO_AR01="OS med navnet"
ST_INFO_AR02="er ikke installert nå."
ST_INFO_AR03="Prøv å kjøre på en installert plattform, og koble til din visning."
ST_INFO_AR04="Installert(e) plattform(er) er:"
ST_INFO_AR05="ikke installert for denne konfigurasjonen,"
ST_IBP_MISC_03="Mozilla"
ST_IBP_MISC_04="Firefox"
ST_IBP_MISC_05="Netscape"
ST_IBP_MISC_06="Avslutt"
ST_IBP_INFO_01="Leser-plugin-modulen for acroread vil nå bli installert."
ST_IBP_INFO_02="Utfør global installasjon"
ST_IBP_INFO_03="Utfør brukerdefinert installasjon"
ST_IBP_INFO_04="Angi valg"
ST_IBP_INFO_05="Vil du installere en annen leser?"
ST_IBP_INFO_06="Angi installasjonsmappen for Adobe Reader 7.0"
ST_IBP_INFO_07="Angi katalogen for leserinstallasjon"
ST_IBP_INFO_08="Plugin-modulen ser ut til å være installert. Er du sikker på at du vil overskrive?"
ST_IBP_INFO_09="Installasjon avbrutt."
ST_IBP_INFO_10="Installasjonen er fullført."
ST_IBP_INFO_11="Dette vil aktivere plugin-modulen for Mozilla, Firefox og Netscape."
ST_IBP_INFO_12="Hvis du har problemer med å få installasjonen til å fungere sammen med webleseren din, kopierer du følgende fil til webleserens mappe for plugin-moduler:"
ST_IBP_INFO_13="Angitt bane for Acroread"
ST_IBP_INFO_14="Trykk <Enter> for å fortsette"
ST_IBP_INFO_15="Hvis det oppstår vanskeligheter, kan du se i dokumentasjonen som følger med leseren, om å legge til nye plugin-moduler."
ST_IBP_INFO_16="Installerer plugin-modulen i"
ST_IBP_INFO_17="Ønsker du en automatisk installasjon?"
ST_IBP_INFO_18="Automatisk installasjon er fullført."
ST_IBP_INFO_19="Ønsker du en manuell installasjon?"
ST_IBP_INFO_20="Vil du installere plugin-modulen for leseren?"
ST_IBP_INFO_21="Hoppet over installasjon av plugin-modul for leser."
ST_IBP_INFO_22_1="Kjør"
ST_IBP_INFO_22_2="for å installere plugin-modul for leser."
ST_IBP_INFO_23="har blitt lagt til."
ST_IBP_INFO_24="Prøver å installere plugin-modul for leser"
ST_IBP_INFO_25="Installasjon mislykket"
ST_IBP_ERR_01="Finner ikke filen for plugin-modulen for leseren"
ST_IBP_ERR_02="Finner ikke mappen for plugin-moduler for leseren"
ST_IBP_ERR_03="Fant ikke lesermappen"
ST_IBP_ERR_04="Kan ikke fjerne tidligere versjoner av plugin-modulen i"
ST_IBP_ERR_05_1="Kan ikke kopiere filen for plugin-modulen"
ST_IBP_ERR_05_2="til"
ST_IBP_ERR_06="Kan ikke opprette mappen"
ST_IBP_ERR_07="Fant ikke installasjonsskriptet for plugin-modulen for leseren."
ST_IBP_ERR_08="finnes allerede som en egen fil, og den kan ikke overskrives."
ST_IBP_ERR_09="Kan ikke utføre spørring på HOME-variabelen fra miljøet. Finner ikke hjemmekatalogen."
ST_IBP_ERR_10="Fant ikke installasjonsmappen"
ST_IBP_ERR_11="INTERN FEIL ..... Ingen OS-navn som samsvarer."
ST_SEP_INFO_01="Angi installasjonsmappen for Adobe Reader 7.0."
ST_SEP_INFO_02="INTERN FEIL ..... Ingen OS-navn som samsvarer."
ST_SEP_INFO_03="Finner ikke aktuelle filer i installasjonsbanen."
ST_SEP_INFO_04="Tilbakestiller gamle kontekster"
ST_SEP_INFO_05="Angir nye kontekster for bibliotekfiler"
ST_SEP_INFO_06="Dette er et forsøk på å oppdatere bibliotekfilene slik at de finner SELinux."
ST_SEP_INFO_07="Fant ikke installasjonsmappen."
ST_SEP_INFO_08="Angivelse av kontekstene er fullført. Du kan se i loggen på"
ST_SEP_INFO_09="Feil i kommando"
ST_SEP_INFO_10="Oppdateringen er kanskje ikke fullført. Du kan se i loggen på"
ST_IOP_ERR1="Kunne ikke registrere PDF-plugin-modulen for OpenOffice. Les instruksjonene i "
ST_IOP_ERR2="for manuell installasjon."
ST_IOP_ERR3="OpenOffice >= 1.9 kreves for at PDF-plugin-modulen for OpenOffice skal kjøre riktig. Hopper over registreringen av PDF-plugin-modulen."
ST_IOP_ERR4="Fant ikke OpenOffice-binærfil (soffice.bin) i den angitte mappen."
ST_IOP_INFO_01="Angi mappen der OpenOffice er installert:"
ST_IOP_INFO_02="Vil du installere plugin-modulen for OpenOffice?"
ST_IAP_ERR1="Kunne ikke registrere plugin-modulen for Adobe PDF. Følg instruksjonene i"
ST_IAP_INFO_01="Vil du installere plugin-modulen for Adobe PDF?"
ST_IFE_INFO_01="Vil du installere Firefox-tillegget?"
ST_IFE_INFO_02="Angi banen for den kjørbare filen for Firefox:"
ST_IFE_ERR_01="Fant ikke Firefox.exe, eller kjøretillatelser mangler."
ST_IDI_INFO_01="Vil du installere Distiller?"
ST_MIME_INFO_01="Logg på på nytt for å ta i bruk endringer i MIME-typer og -ikoner."
true
}

setLangNOR

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.8

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


