#!/bin/sh -f

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

. /etc/sysconfig/system

[ -n "$SERVER_ROLE" ] || exit 0

authtool="/usr/sbin/system-auth"

. shell-quote
. shell-error

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

host_2_dn()
{
    local host="$1" ; shift
    host="$(echo $host|sed -e "s/^/dc=/"|sed -e "s/\./,dc=/g")"
    echo "$host"
}

rename()
{
    local new="${2#*.}" ; shift
    [ -z "$new" ] && fatal "new domain must be set"

    uri="ldap://127.0.0.1"
    basedn="$(host_2_dn "$new")"

    $authtool write ldap "$basedn" "$uri"
}

rename "$olddomain" "$newdomain"

