#!/bin/sh

# Copyright \251 2004 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, the Sun logo, Java and Sun[tm] ONE are trademarks or
# registered trademarks of Sun Microsystems, Inc. in the U.S. and other
# countries.
#
# Copyright \251 2004 Sun Microsystems, Inc. Tous droits r\351serv\351s. Sun
# Microsystems, Inc. d\351tient les droits de propri\351t\351 intellectuels relatifs
# \340 la technologie incorpor\351e dans le produit qui est d\351crit dans ce document.
# En particulier, et ce sans limitation, ces droits de propri\351t\351
# intellectuelle peuvent inclure un ou plus des brevets am\351ricains list\351s
# \340 l'adresse http://www.sun.com/patents et un ou les brevets suppl\351mentaires
# 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 d\351velopp\351s par des
# tierces parties.
#
# Sun, Sun Microsystems, le logo Sun, Java et Sun[tm] ONE sont des marques
# de fabrique ou des marques d\351pos\351es de Sun Microsystems, Inc. aux
# Etats-Unis et dans d'autres pays.
#
#  set shell variables
#

OS=`uname`
if [ $OS = "Linux" ]; then
    CONFIG_DIR=/etc/opt/sun/identity/config
else
    CONFIG_DIR=/etc/opt/SUNWam/config
fi
export CONFIG_DIR
SVC_XML_DIR_IMPORT=${CONFIG_DIR}/xml
export SVC_XML_DIR_IMPORT


################################################################################
#create dit
#
################################################################################

create_dit() {
    # try multiple times
    i=2
    fail=0
    while [ $i != 3 ]
    do
        sleep $i
        ${PKGDIR}/bin/ldapmodify -D "$DIRMGRDN" -w "$DIRMGRPASSWD" -c -a -h $DS_HOST -p $DS_PORT -f $1
        fail=$?
        if [ $fail = 0 ]
        then
            break
        fi
        i=`expr $i + 1`
        $NECHO "`gettext 'sleep'` $i"
    done
    if [ $fail = 0 ]
    then
        $NECHO "`gettext 'Create DIT succeeded.'`"
    else
        $NECHO "`gettext 'ERROR : create DIT failed.'`"
    fi
}
################################################################################
# execute amadmin
################################################################################

import_service_data() {
    SVC_MODIFICATION_FILES=$*
    eval $NECHO "`gettext 'Applying service modifications $SVC_MODIFICATION_FILES'`"
    eval $NECHO "`gettext 'Applying service modifications $SVC_MODIFICATION FILES'`" >> $LOGFILE
    $ADMIN_CLI --runasdn "$AMADMIN_DN" -w "$ADMINPASSWD" -c -v -t ${SVC_MODIFICATION_FILES}
}

import_new_service_schema() {
    NEW_SVC_SCHEMA=$*
    eval $NECHO "`gettext 'Importing new service'`" 
    eval $NECHO "`gettext 'Importing new service $NEW_SVC_SCHEMA'`" >> $LOGFILE
    $ADMIN_CLI --runasdn "$AMADMIN_DN" -w "$ADMINPASSWD" -c -v -s ${NEW_SVC_SCHEMA}
}

get_attribute_value() {
    SVC_XML_FILE=$*
    ans=`$ADMIN_CLI --runasdn "$AMADMIN_DN" -w "$ADMINPASSWD" -t ${SVC_XML_FILE} |  grep "\[\]"`
    if [ "$ans" = "" ]; then
       return 1
    else
       return 0;
    fi
}
