#!/bin/bash
############################################################################################################################
# Novell Inc.
# 1800 South Novell Place
# Provo, UT 84606-6194
# Script Name:       add_uniquedomainid_object_external.sh
# Description:         This script will add uniquedomianid to a specified object.
#  			                              
# %Version:            1.0
# %Creating Date:   Mon Apr 22 12:28:01 MDT 2013
# %Created by:       Rance Burker - Novell Technical Services
# %Contact Information:	If you have any comments/requests/issues, please contact Rance Burker at rance@novell.com  
###########################################################################################################################
# Display ASCII art
clear
echo ' ___   ___   __ __      __  ___            __                     '
echo '|   \ / __| / _|\ \    / / / _ \ __ __ ___/ /___    __  ___  __ __ '
echo '| |) |\__ \|  _| \ \/\/ / / // // // // _  // -_)_ / _|/ _ \|     |'
echo '|___/ |___/|_|    \_/\_/ /____/ \_,_/ \_,_/ \__/(_)\__|\___/|_|_|_|'
echo '                                                                   '


export LDAPCONF=/etc/opt/novell/xad/openldap/ldap.conf
echo -e "This script will add uniquedomianid to a specified object."
echo -ne "Enter the object to add the uniquedomainid to (cn=user1,o=novell): "
read BASE

/usr/bin/ldapsearch -Y EXTERNAL -LLL -Q -b "$BASE" -s sub dn | grep -v ^# | sed -e :a -e '$!N;s/\n //;ta' -e 'P;D'|sed -e'/^dn/ a\changetype: modify\nadd: uniquedomainid\nuniquedomainid: '1049076'' >/tmp/add_uniquedomainid.ldif
echo ""
cat /tmp/add_uniquedomainid.ldif
echo ""
echo -e "The ldif is located at /tmp/add_uniquedomainid.ldif"
echo -e "You have 10 seconds to abort the script (cntrl-c) before it adds uniquedomainid: '1049076' ..."
sleep 10

/usr/bin/ldapmodify -Y EXTERNAL -f /tmp/add_uniquedomainid.ldif

echo -e "uniqueDomainid has been added"
/usr/bin/ldapsearch -Y EXTERNAL -b "$BASE" -s sub uniquedomainid

exit 0
