-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdnssd-domain
executable file
·58 lines (49 loc) · 2.07 KB
/
dnssd-domain
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
#
# Sends DNS-SD updates for domain browsing setup
#------------------------------------------------------------------------------
# load helpful functions
for i in functions/*.sh
do
. ${i}
[[ -n ${DEBUG_SET_VARS} ]] && echo "Sourced ${PWD}/$i ..."
done
set_vars $*
#------------------------------------------------------------------------------
# test
NEW_SUBZONE=${NEW_SUBZONE:-""}
# select zone or subdomain within zone
if [[ -n ${NEW_SUBZONE} ]]; then
DNSSD_DOMAIN="${NEW_SUBZONE}.${ZONE}"
else
DNSSD_DOMAIN="${ZONE}"
fi
NSUPDATE_AUTH_SIG0_KEY_FQDN=${NSUPDATE_AUTH_SIG0_KEY_FQDN:-${DNSSD_DOMAIN}}
# define default update add
NSUPDATE_ACTION=${NSUPDATE_ACTION:-"add"}
NSUPDATE_TTL="600"
for word in lb b db r dr
do
# echo "***** DEBUG: ZONE = '${ZONE}' NEW_SUBZONE='${NEW_SUBZONE}' NEW_FQDN='${NEW_FQDN}'"
case ${NSUPDATE_ACTION} in
add)
NSUPDATE_PRECONDITION_SET="nxrrset"
NSUPDATE_PRECONDITION="prereq ${NSUPDATE_PRECONDITION_SET} ${word}._dns-sd._udp.${DNSSD_DOMAIN}. IN PTR"
NSUPDATE_ITEM_RR="update ${NSUPDATE_ACTION} ${word}._dns-sd._udp.${DNSSD_DOMAIN} ${NSUPDATE_TTL} PTR ${DNSSD_DOMAIN}."
send_nsupdate "${DNSSD_DOMAIN}" "$(echo ${NSUPDATE_PRECONDITION};echo ${NSUPDATE_ITEM_RR})" "${NSUPDATE_AUTH_SIG0_KEY_FQDN}"
;;
delete)
NSUPDATE_PRECONDITION_SET="yxrrset"
NSUPDATE_PRECONDITION="prereq ${NSUPDATE_PRECONDITION_SET} ${word}._dns-sd._udp.${DNSSD_DOMAIN}. IN PTR"
NSUPDATE_ITEM_RR="update ${NSUPDATE_ACTION} ${word}._dns-sd._udp.${DNSSD_DOMAIN} ${NSUPDATE_TTL} PTR ${DNSSD_DOMAIN}."
send_nsupdate "${DNSSD_DOMAIN}" "$(echo ${NSUPDATE_PRECONDITION};echo ${NSUPDATE_ITEM_RR})" "${NSUPDATE_AUTH_SIG0_KEY_FQDN}"
;;
*)
# NSUPDATE_ACTION should default to "add" - should never get here
echo "Error: NSUPDATE_ACTION is set to '${NSUPDATE_ACTION}', but must be set to 'add' or 'delete'."
exit 1
;;
esac
DIG_QUERY_PARAM="@${ZONE_SOA_MASTER} +short"
[[ -n ${DEBUG} ]] && echo "dig @${ZONE_SOA_MASTER} PTR ${word}._dns-sd._udp.${DNSSD_DOMAIN}. '$( dig ${DIG_QUERY_PARAM} PTR ${word}._dns-sd._udp.${DNSSD_DOMAIN}. )'"
done