#!/bin/sh -f

# if we are not server 
[ -f /etc/sysconfig/system ] || exit 0

. /etc/sysconfig/system

[ "$SERVER_ROLE" = "master" ] || exit 0

. alterator-openldap-functions

olddomain="$1" ; shift
newdomain="$1" ; shift

create()
{
    local dn="$1" ; shift

    ldap-dn create "$dn"
}

rename()
{
    local old="${1#*.}" ; shift
    local new="${1#*.}" ; shift

    old="$(host_2_dn "$old")"
    new="$(host_2_dn "$new")"

#    if [ -z "$(ldap-dn find "$old")" ] ;then
        create "$new"
#    else
#        ldap-dn rename "$old" "$new"
#    fi  
}
rename "$olddomain" "$newdomain"

/usr/lib/alterator/backend3/openldap &>/dev/null <<EOF
_message:begin
action:save
local_and_tls:#t
_message:end
EOF
service slapd restart
chkconfig slapd on
