#!/bin/ksh

AWK=/usr/bin/awk
NAWK=/usr/bin/nawk
ECHO=/usr/bin/echo
MV=/usr/bin/mv
CP=/usr/bin/cp
RM=/usr/bin/rm
GREP=/usr/bin/grep
SED=/usr/bin/sed
MKDIR=/usr/bin/mkdir
BASE_DIR=/
CUT=/usr/bin/cut

CONFIG_DIR=/etc/opt/SUNWam
PRODUCT_DIR=SUNWam

PATH=.:/bin:/usr/bin:/usr/sbin:/etc
export PATH

get_base_dir() {
  pkginfo -q SUNWamsdk
  if [ $? -eq 0 ]; then
    BASE_DIR=`pkginfo -r SUNWamsdk`
    INSTALL_DIR=$BASE_DIR/SUNWam
  else
    exit 1
  fi

}

check_amconfig() {
  check_for_con
  check_for_svc
  if [ $con = "no" ] && [ $svc = "no" ]; then
    return
  fi

  if [ ! -r $AMCONFIG ]; then
    $ECHO "Error: $AMCONFIG does not exist or readable."
    $ECHO "       Can not install the patch."
    exit 2
  fi

  preserve_wars
}


check_for_svc() {
  pkginfo -q SUNWamsvc
  if [ $? -eq 0 ]; then
    svc="yes"
  else
    svc="no"
  fi
}

check_for_con() {
  pkginfo -q SUNWamcon
  if [ $? -eq 0 ]; then
    con="yes"
  else
    con="no"
  fi
}


yesno() {
  ok="no"
 
  question=$1
  default=$2

  valids="ynYN"

  while [ "$ok" = "no" ]; do
    if [ "$default" != "${default%y}" ] || [ "$default" != "${default%Y}" ]
    then
      $ECHO "$question [y]/n \c"
      default="y"
    elif [ "$default" != "${default%n}" ] || [ "$default" != "${default%N}" ]
    then
      $ECHO "$question y/[n] \c"
      default="n"
    else
      $ECHO "$question y/n \c"
      default=""
    fi

    read ans


    if [ "$ans" = "" ]; then
      if [ "$default" != "" ]; then
        ans=$default
      fi 
    fi  

    if [ "$ans" != "${ans%[$valids]}" ]; then
      ok="yes"
    fi

    if [ "$ok" = "no" ]; then
      $ECHO
      $ECHO "Invalid response"
      $ECHO
    fi

  done

    # make sure we have a std response so client doesn't need to check

    if [ "$ans" = "y" ]; then
      ans="y"
    elif [ "$ans" = "n" ]; then
      ans="n"
    elif [ "$ans" = "N" ]; then
      ans="n"
    fi
}


license_accept() {
  more LICENSE.TXT
  $ECHO
  yesno "Do you agree to the license terms?" "n"
 
  if [ "$ans" = "n" ]; then
    exit 1
  fi
}

backupBin() {
   if [ -d $BASE_DIR/SUNWam/bin ]; then
      cd $BASE_DIR/SUNWam
      cp -rf bin .bin-6.3

      if [ -d $BASE_DIR/SUNWam/web-src ]; then
         cp -rp web-src .web-src-6.3
      fi
   fi
}

backupCfg() {
   if [ -d /etc/opt/SUNWam/config ]; then
      cd /etc/opt/SUNWam
      cp -rp config .config-6.3
   fi
}

############################################################
## Create silent install file from existing configuration ##
############################################################
create_silent_file() {

AMCONFIG=$CONFIG_DIR/config/AMConfig.properties
AMXML=$CONFIG_DIR/config/xml/amAuth.xml
AMSAML=$CONFIG_DIR/config/xml/amSAML.xml
AMPLATFORM=$CONFIG_DIR/config/xml/amPlatform.xml
AM2BAK=$BASE_DIR/$PRODUCT_DIR/bin/am2bak
if [ ! -d $CONFIG_DIR/config/xml ];then
	mkdir -p $CONFIG_DIR/config/xml
fi
if [ ! -d $BASE_DIR/$PRODUCT_DIR/bin ];then
	mkdir -p $BASE_DIR/$PRODUCT_DIR/bin
fi

for file in $AMXML $AMSAML $AMPLATFORM $AM2BAK
do
 touch $file
done

DEPLOY_LEVEL=0
pkginfo -q SUNWamsvc
if [ $? -eq 0 ];then
 DEPLOY_LEVEL=1
else
 pkginfo -q SUNWamcon
 if [ $? -eq 0 ];then
   DEPLOY_LEVEL=2
 else
  pkginfo -q SUNWamsdk
  if [ $? -eq 0 ];then
    DEPLOY_LEVEL=3
  else
    echo "no level"
  fi
 fi
fi

echo "DEPLOY_LEVEL=$DEPLOY_LEVEL" > /tmp/.amsilent
echo "BASEDIR=$BASE_DIR" >> /tmp/.amsilent
SERVER_HOST=`grep ^com.iplanet.am.server.host= $AMCONFIG \
  | sed -e "s#com.iplanet.am.server.host=#SERVER_HOST=#"`
echo $SERVER_HOST >> /tmp/.amsilent
SERVER_PORT=`grep ^com.iplanet.am.server.port= $AMCONFIG \
  | sed -e "s#com.iplanet.am.server.port=#SERVER_PORT=#"`
echo $SERVER_PORT >> /tmp/.amsilent
SERVER_PROTOCOL=`grep ^com.iplanet.am.server.protocol= $AMCONFIG \
  | sed -e "s#com.iplanet.am.server.protocol=#SERVER_PROTOCOL=#"`
echo $SERVER_PROTOCOL >> /tmp/.amsilent

echo "CONSOLE_HOST=\$SERVER_HOST" >> /tmp/.amsilent
echo "CONSOLE_PORT=\$SERVER_PORT" >> /tmp/.amsilent
echo "CONSOLE_PROTOCOL=\$SERVER_PROTOCOL" >> /tmp/.amsilent

CONSOLE_REMOTE=`grep ^com.iplanet.am.console.remote= $AMCONFIG \
  | sed -e "s#com.iplanet.am.console.remote=#CONSOLE_REMOTE=#g"`
echo $CONSOLE_REMOTE >> /tmp/.amsilent
DS_HOST=`grep ^com.iplanet.am.directory.host= $AMCONFIG \
  | sed -e "s#com.iplanet.am.directory.host=#DS_HOST=#g"`
echo $DS_HOST >> /tmp/.amsilent
DS_PORT=`grep ^com.iplanet.am.directory.port= $AMCONFIG \
  | sed -e "s#com.iplanet.am.directory.port=#DS_PORT=#g"`
echo $DS_PORT >> /tmp/.amsilent

###????? DS_DIRMGRDN="cn=Directory Manager"
###????? DS_DIRMGRPASSWD=11111111

ROOT_SUFFIX=`grep ^com.iplanet.am.defaultOrg= $AMCONFIG \
  | sed -e "s#com.iplanet.am.defaultOrg=#ROOT_SUFFIX=#"`
echo $ROOT_SUFFIX >> /tmp/.amsilent

###??????? ADMINPASSWD=11111111
###??????? AMLDAPUSERPASSWD=00000000

CONSOLE_DEPLOY_URI=`grep ^com.iplanet.am.console.deploymentDescriptor= $AMCONFIG\
  | sed -e "s#com.iplanet.am.console.deploymentDescriptor=#CONSOLE_DEPLOY_URI=#"`
echo $CONSOLE_DEPLOY_URI >> /tmp/.amsilent
SERVER_DEPLOY_URI=`grep ^com.iplanet.am.services.deploymentDescriptor= $AMCONFIG\
  | sed -e "s#com.iplanet.am.services.deploymentDescriptor=#SERVER_DEPLOY_URI=#"`
echo $SERVER_DEPLOY_URI >> /tmp/.amsilent
PASSWORD_DEPLOY_URI=`grep ^com.sun.identity.password.deploymentDescriptor= \
  $AMCONFIG | sed -e "s#com.sun.identity.password.deploymentDescriptor=#PASSWORD_DEPLOY_URI=#"`
echo $PASSWORD_DEPLOY_URI >> /tmp/.amsilent

COMMON_DEPLOY_URI=/amcommon
echo "COMMON_DEPLOY_URI=$COMMON_DEPLOY_URI" >> /tmp/.amsilent
COOKIE_DOMAIN=`sed -n -e "/iplanet-am-platform-cookie-domains/,/AttributeSchema/p" $AMPLATFORM | grep "<Value>" | sed -e "s/<Value>//" | sed -e "s#</Value>##" | sed -e "s# ##g"`
echo "COOKIE_DOMAIN=$COOKIE_DOMAIN" >> /tmp/.amsilent

JAVA_HOME=`grep ^com.iplanet.am.jdk.path= $AMCONFIG \
  | sed -e "s#com.iplanet.am.jdk.path=#JAVA_HOME=#"`
echo $JAVA_HOME >> /tmp/.amsilent

PLATFORM_LOCALE=`grep ^com.iplanet.am.locale= $AMCONFIG \
  | sed -e "s#com.iplanet.am.locale=#PLATFORM_LOCALE=#"`
echo $PLATFORM_LOCALE >> /tmp/.amsilent
XML_ENCODING=`grep encoding $AMXML | awk -F= '{print $NF}'|awk -F\" '{print $2}'`
echo "XML_ENCODING=$XML_ENCODING" >> /tmp/.amsilent

echo "NEW_INSTANCE=false" >> /tmp/.amsilent
NEW_OWNER=`ls -l $AMCONFIG | awk 'BEGIN { FS=" " } { print $3 }'`
echo "NEW_OWNER=$NEW_OWNER" >> /tmp/.amsilent
NEW_GROUP=`ls -l $AMCONFIG | awk 'BEGIN { FS=" " } { print $4 }'`
echo "NEW_GROUP=$NEW_GROUP" >> /tmp/.amsilent

CONTAINER_CERTDB_DIR=`grep ^com.iplanet.am.admin.cli.certdb.dir $AMCONFIG \
  | sed -e "s#com.iplanet.am.admin.cli.certdb.dir=##"`
echo "CONTAINER_CERTDB_DIR=$CONTAINER_CERTDB_DIR" >> /tmp/.amsilent
CONTAINER_CERTDB_PREFIX=`grep ^com.iplanet.am.admin.cli.certdb.prefix $AMCONFIG \
  | sed -e "s#com.iplanet.am.admin.cli.certdb.prefix=##"`
echo "CONTAINER_CERTDB_PREFIX=$CONTAINER_CERTDB_PREFIX" >> /tmp/.amsilent
COOKIE_ENCODE=`grep ^com.iplanet.am.cookie.encode $AMCONFIG \
  |  sed -e "s#com.iplanet.am.cookie.encode=##"`
echo "COOKIE_ENCODE=$COOKIE_ENCODE" >> /tmp/.amsilent
LB_COOKIE=`grep ^com.iplanet.am.lbcookie.name $AMCONFIG \
  |  sed -e "s#com.iplanet.am.lbcookie.name=##"`
echo "LB_COOKIE=$LB_COOKIE" >> /tmp/.amsilent
COOKIE_CHECK=`grep ^com.sun.identity.am.cookie.check $AMCONFIG \
  | sed -e "s#com.sun.identity.am.cookie.check=##"`
if [ x$COOKIE_CHECK = "x" ] || [ $COOKIE_CHECK = "COOKIE_CHECK" ]; then
  COOKIE_CHECK="false"
fi
$ECHO "COOKIE_CHECK=$COOKIE_CHECK" >> /tmp/.amsilent
DONOTTRIMLIST=`grep ^com.sun.identity.session.property.doNotTrimList $AMCONFIG \
  | sed -e "s#com.sun.identity.session.property.doNotTrimList=##"`
$ECHO "DONOTTRIMLIST=\"$DONOTTRIMLIST\"" >> /tmp/.amsilent
USER_NAMING_ATTR=`grep ^com.sun.identity.authentication.super.user $AMCONFIG \
  | awk 'BEGIN { FS="=" } { print $2 }'`
echo "USER_NAMING_ATTR=$USER_NAMING_ATTR" >> /tmp/.amsilent
WEBAPPSDIR=`grep ^com.iplanet.am.install.basedir $AMCONFIG \
  | sed -e "s#com.iplanet.am.install.basedir=##" | sed -e "s#/WEB-INF##"`
echo "WEBAPPSDIR=$WEBAPPSDIR" >> /tmp/.amsilent
ENCLDAPUSERPASSWD=`grep ^com.iplanet.am.service.secret $AMCONFIG \
  | sed -e "s#com.iplanet.am.service.secret=##"`
echo "ENCLDAPUSERPASSWD=$ENCLDAPUSERPASSWD" >> /tmp/.amsilent
AM_ENC_PWD=`grep ^am.encryption.pwd $AMCONFIG \
  | sed -e "s#am.encryption.pwd=##"`
echo "AM_ENC_PWD=$AM_ENC_PWD" >> /tmp/.amsilent
SAML_SITEID=`grep siteid= $AMSAML | awk 'BEGIN { FS="|" } { print $2 }' \
  | sed -e "s#siteid=##"`
echo "SAMLSITEID=$SAML_SITEID" >> /tmp/.amsilent
WEB_CONTAINER=`grep ^com.sun.identity.webcontainer= $AMCONFIG \
  | sed -e "s#com.sun.identity.webcontainer=##"`
echo "WEB_CONTAINER=$WEB_CONTAINER" >> /tmp/.amsilent
WS61_HOME=`grep ^WS_LOCATION= $AM2BAK | sed -e "s#WS_LOCATION=##" \
  | sed -e "s# ##g"`
echo "WS61_HOME=$WS61_HOME" >> /tmp/.amsilent 

#################
## The values are fixed in the script
echo "DIT_COMPLIANCE=false" >> /tmp/.amsilent
echo "DCTREE_SUFFIX=false" >> /tmp/.amsilent
echo "UM_ENABLED=true" >> /tmp/.amsilent
#################

echo "ORG_NAMING_ATTR=o" >> /tmp/.amsilent
echo "ORG_OBJECT_CLASS=sunmanagedorganization" >> /tmp/.amsilent
echo "USER_OBJECT_CLASS=inetorgperson" >> /tmp/.amsilent
echo "DEFAULT_ORGANIZATION=" >> /tmp/.amsilent
$ECHO "NEW_INSTANCE=false" >> /tmp/.amsilent
}

##############################################################
# keep services.war and the other two war files for backout
##############################################################
preserve_wars() {
  WEBAPPS_SOURCE_DIR=$INSTALL_DIR/web-src
  cd $INSTALL_DIR
  AMCONFIG=$CONFIG_DIR/config/AMConfig.properties

  if [ ! -f services.war ]; then
    URI=`$GREP "^com.iplanet.am.services.deploymentDescriptor=" $AMCONFIG \
        | $CUT -d= -f2`
    WARFILE=$INSTALL_DIR/${URI:-amserver}.war
    if [ -f $WARFILE ]; then
      $CP $WARFILE services.war
    else
      $ECHO "Error: $WARFILE does not exist."
      $ECHO "       Can not save services.war for backout."
      exit 3
    fi
  fi

  if [ ! -f password.war ]; then
    URI=`$GREP "^com.sun.identity.password.deploymentDescriptor=" $AMCONFIG \
        | $CUT -d= -f2`
    WARFILE=$INSTALL_DIR/${URI:-ampassword}.war
    if [ -f $WARFILE ]; then
      $CP $WARFILE password.war
    else
      $ECHO "Error: $WARFILE does not exist."
      $ECHO "       Can not save password.war for backout."
      exit 3
    fi
  fi

  if [ ! -f introduction.war ]; then
    URI=
    WARFILE=$INSTALL_DIR/${URI:-amcommon}.war
    if [ -f $WARFILE ]; then
      $CP $WARFILE introduction.war
    else
      $ECHO "Warning: $WARFILE does not exist."
      $ECHO "         Can not save introduction.war for backout."
    fi
  fi
}


##############################################
# main start
##############################################

# ask for ADMINPASSWD
#ADMINPASSWD=$adminpassword
# ask for AMLDAPUSERPASSWD
#AMLDAPUSERPASSWD=$amldapuserpasswd

#backup AMConfig.properties
#cp -p $CONFIG_DIR/config/AMConfig.properties $CONFIG_DIR/config/.AMConfig.properties.6.3-RTM

#license_accept 

#ROOTDIR=${1:-/}
if [ x"${ROOTDIR}" != "x/" ]; then
  echo "ERROR: This patch does not support alternate root install through the use of the '-R <client_root_path>' flag"
  exit 1;
fi

get_base_dir
check_amconfig

if [ ! -f /etc/opt/SUNWam/config/AMConfig.properties ];then
 echo "WARNING:  The AM 6.3 instance is incomplete on this machine and can not do upgrade !!!"
 exit 11
fi

create_silent_file

backupBin
backupCfg

#backup serverconfig.xml
cp -p $CONFIG_DIR/config/serverconfig.xml $CONFIG_DIR/config/.serverconfig.xml.6.3

# make sure the directory exists, or the patch will fail!
if [ ! -d $BASE_DIR/SUNWam/samples/authentication/spi/genuid ]; then
   mkdir -p $BASE_DIR/SUNWam/samples/authentication/spi/genuid
   chmod 755 $BASE_DIR/SUNWam/samples/authentication/spi/genuid
fi
if [ ! -d $BASE_DIR/SUNWam/upgrade/scripts/locale/LC_MESSAGES ]; then
   mkdir -p $BASE_DIR/SUNWam/upgrade/scripts/locale/LC_MESSAGES
fi
if [ ! -d $BASE_DIR/SUNWam/upgrade/services/00_DAI/10_20/data ]; then
   mkdir -p $BASE_DIR/SUNWam/upgrade/services/00_DAI/10_20/data
fi
if [ ! -d $BASE_DIR/SUNWam/upgrade/services/10_iPlanetAMAdminConsoleService/10_20/data ]; then
   mkdir -p $BASE_DIR/SUNWam/upgrade/services/10_iPlanetAMAdminConsoleService/10_20/data
fi
if [ ! -d $BASE_DIR/SUNWam/upgrade/services/20_iPlanetAMUserService/10_20/data ]; then
   mkdir -p $BASE_DIR/SUNWam/upgrade/services/20_iPlanetAMUserService/10_20/data
fi
if [ ! -d $BASE_DIR/SUNWam/upgrade/services/50_iPlanetAMAuthNTService/10_20/data ]; then
   mkdir -p $BASE_DIR/SUNWam/upgrade/services/50_iPlanetAMAuthNTService/10_20/data
fi
if [ ! -d $BASE_DIR/SUNWam/upgrade/services/50_iPlanetAMAuthSafeWordService/10_20/data ]; then
   mkdir -p $BASE_DIR/SUNWam/upgrade/services/50_iPlanetAMAuthSafeWordService/10_20/data
fi
if [ ! -d $BASE_DIR/SUNWam/upgrade/services/50_iPlanetAMAuthService/10_20/data ]; then
   mkdir -p $BASE_DIR/SUNWam/upgrade/services/50_iPlanetAMAuthService/10_20/data
fi
if [ ! -d $BASE_DIR/SUNWam/upgrade/services/50_iPlanetAMLoggingService/10_20/data ]; then
   mkdir -p $BASE_DIR/SUNWam/upgrade/services/50_iPlanetAMLoggingService/10_20/data
fi
if [ ! -d $BASE_DIR/SUNWam/upgrade/services/50_iPlanetAMNamingService/10_20/data ]; then
   mkdir -p $BASE_DIR/SUNWam/upgrade/services/50_iPlanetAMNamingService/10_20/data
fi
if [ ! -d $BASE_DIR/SUNWam/upgrade/services/50_iPlanetAMPolicyConfigService/10_20/data ]; then
   mkdir -p $BASE_DIR/SUNWam/upgrade/services/50_iPlanetAMPolicyConfigService/10_20/data
fi
if [ ! -d $BASE_DIR/SUNWam/upgrade/services/50_iPlanetAMPolicyService/10_20/data ]; then
   mkdir -p $BASE_DIR/SUNWam/upgrade/services/50_iPlanetAMPolicyService/10_20/data
fi
if [ ! -d $BASE_DIR/SUNWam/upgrade/services/50_iPlanetAMProviderConfigService/10_20/data ]; then
   mkdir -p $BASE_DIR/SUNWam/upgrade/services/50_iPlanetAMProviderConfigService/10_20/data
fi
if [ ! -d $BASE_DIR/SUNWam/upgrade/services/50_iPlanetAMSessionService/10_20/data ]; then
   mkdir -p $BASE_DIR/SUNWam/upgrade/services/50_iPlanetAMSessionService/10_20/data
fi
if [ ! -d $BASE_DIR/SUNWam/upgrade/services/99_iPlanetAMAuthADService/s_20 ]; then
   mkdir -p $BASE_DIR/SUNWam/upgrade/services/99_iPlanetAMAuthADService/s_20
fi
if [ ! -d $BASE_DIR/SUNWam/upgrade/services/99_iPlanetAMAuthJDBCService/s_20 ]; then
   mkdir -p $BASE_DIR/SUNWam/upgrade/services/99_iPlanetAMAuthJDBCService/s_20
fi
if [ ! -d $BASE_DIR/SUNWam/upgrade/services/99_iPlanetAMAuthMSISDNService/s_20 ]; then
   mkdir -p $BASE_DIR/SUNWam/upgrade/services/99_iPlanetAMAuthMSISDNService/s_20
fi
if [ ! -d $BASE_DIR/SUNWam/upgrade/services/99_iPlanetAMAuthSAMLService/s_10 ]; then
   mkdir -p $BASE_DIR/SUNWam/upgrade/services/99_iPlanetAMAuthSAMLService/s_10
fi
if [ ! -d $BASE_DIR/SUNWam/upgrade/services/50_iPlanetAMAgentService/10_20/data ]; then
   mkdir -p $BASE_DIR/SUNWam/upgrade/services/50_iPlanetAMAgentService/10_20/data
fi
if [ ! -d $BASE_DIR/SUNWam/upgrade/services/50_sunIdentityLocaleService/10_20/data ]; then
   mkdir -p $BASE_DIR/SUNWam/upgrade/services/50_sunIdentityLocaleService/10_20/data
fi
if [ ! -d $BASE_DIR/SUNWam/upgrade/services/50_sunIdentityServerDiscoveryService/10_20/data ]; then
   mkdir -p $BASE_DIR/SUNWam/upgrade/services/50_sunIdentityServerDiscoveryService/10_20/data
fi
if [ ! -d $BASE_DIR/SUNWam/upgrade/services/50_sunIdentityServerSOAPBinding/10_20/data ]; then
   mkdir -p $BASE_DIR/SUNWam/upgrade/services/50_sunIdentityServerSOAPBinding/10_20/data
fi
if [ ! -d $BASE_DIR/SUNWam/upgrade/services/50_sunIdentityServerLibertyPPService/10_20/data ]; then
   mkdir -p $BASE_DIR/SUNWam/upgrade/services/50_sunIdentityServerLibertyPPService/10_20/data
fi
if [ ! -d $BASE_DIR/SUNWam/upgrade/services/99_iPlanetAMAuthADService/s_10 ]; then
mkdir -p $BASE_DIR/SUNWam/upgrade/services/99_iPlanetAMAuthADService/s_10
fi
if [ ! -d $BASE_DIR/SUNWam/upgrade/services/99_iPlanetAMAuthJDBCService/s_10 ]; then
mkdir -p $BASE_DIR/SUNWam/upgrade/services/99_iPlanetAMAuthJDBCService/s_10
fi
if [ ! -d $BASE_DIR/SUNWam/upgrade/services/99_iPlanetAMAuthMSISDNService/s_10 ]; then
mkdir -p $BASE_DIR/SUNWam/upgrade/services/99_iPlanetAMAuthMSISDNService/s_10
fi
if [ ! -d $BASE_DIR/SUNWam/upgrade/services/99_sunIdentityServerAuthnService/s_10 ]; then
mkdir -p $BASE_DIR/SUNWam/upgrade/services/99_sunIdentityServerAuthnService/s_10
fi
if [ ! -d $BASE_DIR/SUNWam/share/HARepo ]; then
mkdir -p $BASE_DIR/SUNWam/share/HARepo
chmod 755 $BASE_DIR/SUNWam/share/HARepo
fi
if [ ! -d $BASE_DIR/SUNWam/samples/phase2/authnsvc ]; then
mkdir -p $BASE_DIR/SUNWam/samples/phase2/authnsvc
chmod 755 $BASE_DIR/SUNWam/samples/phase2/authnsvc
fi
if [ ! -d $BASE_DIR/SUNWam/lib/jaxrpc_1.0 ]; then
mkdir -p $BASE_DIR/SUNWam/lib/jaxrpc_1.0
chmod 755 $BASE_DIR/SUNWam/lib/jaxrpc_1.0
fi

if [ ! -d $BASE_DIR/SUNWam/bin/.dsame63 ];then
 mkdir -p $BASE_DIR/SUNWam/bin/.dsame63
fi
if [ ! -d $BASE_DIR/SUNWam/lib/.dsame63 ];then
 mkdir -p $BASE_DIR/SUNWam/lib/.dsame63
fi
for file in ldapjdk.jar dom.jar xalan.jar xercesImpl.jar jaxr-api.jar jaxr-impl.jar jaxrpc-api.jar jaxrpc-impl.jar jaxrpc-spi.jar jaxb-api.jar jaxb-impl.jar jaxb-xjc.jar jaxb-libs.jar saaj-api.jar saaj-impl.jar jax-qname.jar namespace.jar activation.jar mail.jar relaxngDatatype.jar xsdlib.jar
do
 if [ -f $BASE_DIR/SUNWam/lib/$file ];then
	mv $BASE_DIR/SUNWam/lib/$file $BASE_DIR/SUNWam/lib/.dsame63/
 fi
 ln -s /usr/share/lib/$file $BASE_DIR/SUNWam/lib/  2>/dev/null
done

for file in amadmin ampassword amverifyarchive
do
 cp -f $BASE_DIR/SUNWam/bin/$file $BASE_DIR/SUNWam/bin/.dsame63
done

exit 0
