2009-09-07 04:55:32 +04:00
#!/bin/bash
# example script to setup DNS for a vampired domain
[ $# = 3 ] || {
echo "Usage: setup_dns.sh HOSTNAME DOMAIN IP"
exit 1
}
2009-09-07 08:08:03 +04:00
HOSTNAME = " $( echo $1 | tr '[a-z]' '[A-Z]' ) "
DOMAIN = " $( echo $2 | tr '[a-z]' '[A-Z]' ) "
2009-09-07 04:55:32 +04:00
IP = " $3 "
RSUFFIX = $( echo $DOMAIN | sed s/[ \. ] /,DC= /g)
2009-09-12 10:08:07 +04:00
[ -z " $PRIVATEDIR " ] && {
2011-06-07 07:46:24 +04:00
PRIVATEDIR = $( bin/samba-tool testparm --section-name= global --parameter-name= 'private dir' --suppress-prompt 2> /dev/null)
2009-09-12 10:08:07 +04:00
}
2009-09-07 04:55:32 +04:00
2010-01-07 13:28:03 +03:00
OBJECTGUID = $( bin/ldbsearch -s base -H " $PRIVATEDIR /sam.ldb " -b " CN=NTDS Settings,CN= $HOSTNAME ,CN=Servers,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC= $RSUFFIX " objectguid| grep ^objectGUID| cut -d: -f2)
2009-09-07 04:55:32 +04:00
2014-05-12 18:56:29 +04:00
samba4kinit = kinit
if test -x $BINDIR /samba4kinit; then
samba4kinit = bin/samba4kinit
fi
2009-09-07 04:55:32 +04:00
echo " Found objectGUID $OBJECTGUID "
2009-09-07 08:08:03 +04:00
echo " Running kinit for $HOSTNAME \$@ $DOMAIN "
2014-05-12 18:56:29 +04:00
$samba4kinit -e arcfour-hmac-md5 -k -t " $PRIVATEDIR /secrets.keytab " $HOSTNAME \$ @$DOMAIN || exit 1
2009-09-07 04:55:32 +04:00
echo " Adding $HOSTNAME . $DOMAIN "
2009-09-07 08:08:03 +04:00
scripting/bin/nsupdate-gss --noverify $HOSTNAME $DOMAIN $IP 300 || {
echo "Failed to add A record"
exit 1
}
echo " Adding $OBJECTGUID ._msdcs. $DOMAIN => $HOSTNAME . $DOMAIN "
scripting/bin/nsupdate-gss --realm= $DOMAIN --noverify --ntype= "CNAME" $OBJECTGUID _msdcs.$DOMAIN $HOSTNAME .$DOMAIN 300 || {
echo "Failed to add CNAME"
exit 1
}
2009-09-07 04:55:32 +04:00
echo "Checking"
2009-10-15 03:00:46 +04:00
rndc flush
2009-09-07 04:55:32 +04:00
host $HOSTNAME .$DOMAIN
2009-09-07 08:08:03 +04:00
host $OBJECTGUID ._msdcs.$DOMAIN