

# Copyright  2005 Sun Microsystems, Inc.  All rights reserved.
#
# Sun Microsystems, Inc. has intellectual property rights relating to
# technology embodied in the product that is described in this document.
# In particular, and without limitation, these intellectual property rights
# may include one or more of the U.S. patents listed at
# http://www.sun.com/patents and one or more additional patents or pending
# patent applications in the U.S. and in other countries.
#
# U.S. Government Rights - Commercial software.  Government users are subject
# to the Sun Microsystems, Inc. standard license agreement and applicable
# provisions of the FAR and its supplements.
#
# Use is subject to license terms.
#
# This distribution may include materials developed by third parties.Sun,
# Sun Microsystems and  the Sun logo are trademarks or registered trademarks
# of Sun Microsystems, Inc. in the U.S. and other countries.  
#
# Copyright  2005 Sun Microsystems, Inc. Tous droits rservs.
# Sun Microsystems, Inc. dtient les droits de proprit intellectuels relatifs
#  la technologie incorpore dans le produit qui est dcrit dans ce document.
# En particulier, et ce sans limitation, ces droits de proprit
# intellectuelle peuvent inclure un ou plus des brevets amricains lists
#  l'adresse http://www.sun.com/patents et un ou les brevets supplmentaires
# ou les applications de brevet en attente aux Etats - Unis et dans les
# autres pays.
#
# L'utilisation est soumise aux termes du contrat de licence.
#
# Cette distribution peut comprendre des composants dvelopps par des
# tierces parties.
#
# Sun,  Sun Microsystems et  le logo Sun sont des marques de fabrique ou des
# marques dposes de Sun Microsystems, Inc. aux Etats-Unis et dans
# d'autres pays.

ECHO=/bin/echo
RPM=/bin/rpm
CUT=/bin/cut
gettext=/usr/bin/gettext

RTM_VERSION="7.0"
CURRENT_RELEASE=19
RPMDIR=./packages/RPMS/i686
AMRPMSUFFIX=$RTM_VERSION-$CURRENT_RELEASE.i686.rpm
MAVERSION=6.2
MARELEASE=25
MOBILEACCESSRPMSUFFIX=$MAVERSION-$MARELEASE.1.i386.rpm

# check Access Manager existance
rpm -q --quiet sun-identity-sdk
if [ $? -eq 0 ];then
  version=`rpm -q --queryformat "%{VERSION}\n" sun-identity-sdk`
  release=`rpm -q --queryformat "%{RELEASE}\n" sun-identity-sdk`
  if [ "$version" != "$RTM_VERSION" ]; then
    $ECHO "`$gettext 'No Access Manager 7.0 installed.'`"
    exit
  elif [ $release -gt $CURRENT_RELEASE ]; then
    $ECHO "`$gettext 'Cannot downgrade/overwrite with this version installed.'`"
    exit
  elif [ $release -eq $CURRENT_RELEASE ]; then
    $ECHO "`$gettext 'This version installed already. Do you want reinstall [y]/n ? '`"
    read ANS
    if [ x$ANS = "xn" ]; then
      exit
    fi
  fi
else
  $ECHO "`$gettext 'No Access Manager installation found.'`"
  exit
fi

# check if existing mobileaccess release is higher
NOMA=n
rpm -q --quiet sun-identity-mobileaccess
if [ $? -eq 0 ];then
  maversion=`rpm -q --queryformat "%{VERSION}\n" sun-identity-mobileaccess`
  marelease=`rpm -q --queryformat "%{RELEASE}\n" sun-identity-mobileaccess`
  marelease=`$ECHO $marelease | $CUT -d. -f1`
  if [ $maversion != $MAVERSION ] || [ $marelease -ge $MARELEASE ]; then
    NOMA=y
    $ECHO
    $ECHO "`$gettext 'sun-identity-mobileaccess and sun-identity-mobileaccess-config will not be installed to downgrade/overwrite existing ones'`"
    $ECHO
  fi
fi

AMCONFIG=/etc/opt/sun/identity/config/AMConfig.properties 
BASEDIR=`grep com.iplanet.am.installdir= $AMCONFIG \
    | sed -e 's/\/identity//g' | sed -e 's/com.iplanet.am.installdir=//g'`

$ECHO "`$gettext 'Starting Upgrading AM 7.0 Packages'`"
installed="`$RPM -qa | grep sun-identity`"
for pkg in $installed
do
  name=`$ECHO $pkg | sed -e "s/^\(..*\)\-[0-9]..*$/\1/"`
  name=`$ECHO $name | sed -e "s/^\(..*\)\-[0-9]..*$/\1/"`
  pkgname=${RPMDIR}/$name-$AMRPMSUFFIX
  if [ $name = "sun-identity-mobileaccess" ] || \
      [ $name = "sun-identity-mobileaccess-config" ]; then
    pkgname=${RPMDIR}/$name-$MOBILEACCESSRPMSUFFIX
    if [ $NOMA = "y" ]; then
      continue
    fi
  fi

  if [ -f $pkgname ]; then
    case "${name}" in
      sun-identity-console-sdk | sun-identity-sdk-config | sun-identity-services-config | sun-identity-mobileaccess-config)
      rpm -Uvh --nodeps --force $pkgname
    ;;

    *)      
      rpm -Uvh --prefix=${BASEDIR} --nodeps --force $pkgname 
    ;;

    esac
  else
    $ECHO "`$gettext 'There is no $pkgname in this patch'`"
  fi
done

