-
Notifications
You must be signed in to change notification settings - Fork 22
/
rsdns-dc6.sh
executable file
·137 lines (115 loc) · 2.99 KB
/
rsdns-dc6.sh
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
#
# rsdns-dc.sh - A Dynamic DNS Client for rackspace cloud DNS
#
# config file for variables.
if [ -e ~/.rsdns_config ]
then
. ~/.rsdns_config
else
printf "\n"
printf "No config file found. Please see REAME.md"
printf "\n"
exit
fi
# load up our auth & funct library
if [ -e $RSPATH/lib/auth.sh ]
then
. $RSPATH/lib/auth.sh
else
printf "\n"
printf "auth.sh not found, please check you RSPATH"
printf "\n"
exit 95
fi
if [ -e $RSPATH/lib/func.sh ]
then
. $RSPATH/lib/func.sh
else
printf "\n"
printf "func.sh not found, please check you RSPATH"
printf "\n"
exit 95
fi
# Check for additional dependency
check_dep "dig"
#prints out the usage information on error or request.
function usage () {
printf "\n"
printf "rsdns-dc6.sh -n name \n"
printf "\t-h Show this.\n"
printf "\t-q Quiet.\n"
printf "\n"
printf "PLEASE NOTE: You need a ~/.rsdns_config config file, see README.md for Help!"
printf "\n"
}
#prints words for master rsdns script output
function words () {
printf "Dynamic DNS Client for rackspace cloud DNS for IPv6 \n"
}
#Get options from the command line.
while getopts "n:H::hqw" option
do
case $option in
n ) NAME=$OPTARG ;;
H ) HOST=$OPTARG ;;
h ) usage;exit 0 ;;
q ) QUIET=1 ;;
w ) words;exit 0 ;;
esac
done
# need a hostname.
if [ -z $NAME ]
then
usage
exit 1
fi
# Only run if the internet is avilable
if [ -z $HOST ]
then
HOST="www.google.com"
fi
if ! ping6 -c 3 $HOST &>/dev/null
then
if [[ $QUIET -eq 0 ]]; then
echo "The Internet is down, cannot ping6 $HOST"
fi
exit
fi
# get and set our current IP address
IP=`curl -A "rsdns/$RSDNS_VERSION (https://github.com/linickx/rsdns)" -s -k http://ipv6.icanhazip.com`
# Check the RS DNS servers for the current A Record
AAAARECORD=`dig @ns.rackspace.com +short -t aaaa $NAME`
# if the IP doesn't match the A record update :)
if [ "$IP" != "$AAAARECORD" ];
then
# Authenticate and get started
get_auth $RSUSER $RSAPIKEY
if test -z $TOKEN
then
if [[ $QUIET -eq 0 ]]; then
echo Auth Token does not exist.
fi
exit 98
fi
if test -z "$MGMTSVR"
then
if [[ $QUIET -eq 0 ]]; then
echo Management Server does not exist.
fi
exit 97
fi
# what domain does the host belong to?
get_domain $NAME
# set our record type
RECORDTYPE="AAAA"
# find the record ID for our $NAME
get_recordid
# get_recordid will bail if $NAME is not found, this is to stop cron jobs from creating many many records.
# POST!
RSPOST=`echo '{ "name" : "'$NAME'", "data" : "'$IP'" }'`
RC=`curl -A "rsdns/$RSDNS_VERSION (https://github.com/linickx/rsdns)" -k -s -X PUT -H X-Auth-Token:\ $TOKEN -H Content-Type:\ application/json -H Accept:\ application/json $DNSSVR/$USERID/domains/$DOMAINID/records/$RECORDID --data "$RSPOST" |tr -s '[:cntrl:]' "\n"`
UPDATE=1
rackspace_cloud
fi
#done.