-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcli53routes.tmpl
42 lines (38 loc) · 1.53 KB
/
cli53routes.tmpl
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
#!/bin/bash
[ -z "$PUBLIC_IP" ] && PUBLIC_IP=`curl -s http://169.254.169.254/latest/meta-data/public-ipv4`
[ -z "$PUBLIC_IPV6" ] && PUBLIC_IPV6=`curl -s http://169.254.169.254/latest/meta-data/network/interfaces/macs/$(curl http://169.254.169.254/latest/meta-data/mac)/ipv6s`
[ -z "$PUBLIC_IP" -o "not found" = "$PUBLIC_IP" ] && PUBLIC_IP=`curl --connect-timeout 3 -s ipv4.icanhazip.com`
[ -z "$PUBLIC_IPV6" -o "not found" = "$PUBLIC_IPV6" ] && PUBLIC_IPV6=`curl --connect-timeout 3 -s ipv6.icanhazip.com`
[ -z "$PRIVATE_TOP_ZONES" ] && PRIVATE_TOP_ZONES="localhost local priv private"
{{ range $zone, $containers := groupByMulti $ "Env.ZONE" "," }}
zone={{ $zone }}
{{ end }}
{{ range $host, $containers := groupByMulti $ "Env.VIRTUAL_HOST" "," }}
host={{ $host }}
topzone=$(echo "${host##*.}")
if [ -n "$zone" ]; then
tenant=$(echo "${host%.$zone}")
else
tenant=$(echo "${host%.*.*}")
zone=$(echo "${host#$tenant.}")
fi
if [ "${PRIVATE_TOP_ZONES#*$topzone}" != "$PRIVATE_TOP_ZONES" -o "$tenant" = "$zone" ]; then
echo "Skipping private hostname $host" >> /var/log/route53-dyndns.log
else
cmd=""
for IP in $PUBLIC_IP
do
cmd="$cmd cli53 rrcreate $zone $tenant A $IP --ttl 300 --replace;"
done
for IPV6 in $PUBLIC_IPV6
do
cmd="$cmd cli53 rrcreate $zone $tenant AAAA $IPV6 --ttl 300 --replace;"
done
if [ -z "$DRY_ROUTE53" ]; then
echo "$cmd" >> /var/log/route53-dyndns.log
eval "$cmd" >> /var/log/route53-dyndns.log 2>&1
else
echo "DRYRUN: $cmd"
fi
fi
{{ end }}