Update script to handle the @ record
This commit is contained in:
parent
3d758b976b
commit
196a056885
2 changed files with 27 additions and 5 deletions
|
@ -1,3 +1,3 @@
|
||||||
DOMAIN="domain.tld"
|
DOMAIN="domain.tld"
|
||||||
RECORD="host"
|
RECORD="host" # Set to empty string to update the @ record
|
||||||
APIKEY="Your-API-Key"
|
APIKEY="Your-API-Key"
|
||||||
|
|
|
@ -33,8 +33,14 @@ if [[ -z "$WAN_IP4" && -z "$WAN_IP6" ]]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get IP from DNS
|
# Get IP from DNS
|
||||||
|
if [[ ! -z "$RECORD" ]]
|
||||||
|
then
|
||||||
DNS_IP4=$(dig +short @ns1.gandi.net -t A $RECORD.$DOMAIN)
|
DNS_IP4=$(dig +short @ns1.gandi.net -t A $RECORD.$DOMAIN)
|
||||||
DNS_IP6=$(dig +short @ns1.gandi.net -t AAAA $RECORD.$DOMAIN)
|
DNS_IP6=$(dig +short @ns1.gandi.net -t AAAA $RECORD.$DOMAIN)
|
||||||
|
else
|
||||||
|
DNS_IP4=$(dig +short @ns1.gandi.net -t A $DOMAIN)
|
||||||
|
DNS_IP6=$(dig +short @ns1.gandi.net -t AAAA $DOMAIN)
|
||||||
|
fi
|
||||||
|
|
||||||
echo DNS IPv4 : $DNS_IP4 | logger
|
echo DNS IPv4 : $DNS_IP4 | logger
|
||||||
echo DNS IPv6 : $DNS_IP6 | logger
|
echo DNS IPv6 : $DNS_IP6 | logger
|
||||||
|
@ -45,10 +51,18 @@ if [[ ! -z "$WAN_IP4" ]]; then
|
||||||
then
|
then
|
||||||
echo Updating IPv4 DNS records for $RECORD.$DOMAIN | logger
|
echo Updating IPv4 DNS records for $RECORD.$DOMAIN | logger
|
||||||
DATA='{"rrset_values": ["'$WAN_IP4'"]}'
|
DATA='{"rrset_values": ["'$WAN_IP4'"]}'
|
||||||
|
if [[ ! -z "$RECORD" ]]
|
||||||
|
then
|
||||||
IP4_RES=$(curl -s -XPUT -d "$DATA" \
|
IP4_RES=$(curl -s -XPUT -d "$DATA" \
|
||||||
-H"X-Api-Key: $APIKEY" \
|
-H"X-Api-Key: $APIKEY" \
|
||||||
-H"Content-Type: application/json" \
|
-H"Content-Type: application/json" \
|
||||||
"$API/domains/$DOMAIN/records/$RECORD/A" 2>&1)
|
"$API/domains/$DOMAIN/records/$RECORD/A" 2>&1)
|
||||||
|
else
|
||||||
|
IP4_RES=$(curl -s -XPUT -d "$DATA" \
|
||||||
|
-H"X-Api-Key: $APIKEY" \
|
||||||
|
-H"Content-Type: application/json" \
|
||||||
|
"$API/domains/$DOMAIN/records/@/A" 2>&1)
|
||||||
|
fi
|
||||||
echo Update of IPv4 DNS record : $IP4_RES | logger
|
echo Update of IPv4 DNS record : $IP4_RES | logger
|
||||||
else
|
else
|
||||||
echo No need to update IPv4 DNS record for $RECORD.$DOMAIN | logger
|
echo No need to update IPv4 DNS record for $RECORD.$DOMAIN | logger
|
||||||
|
@ -62,10 +76,18 @@ if [[ ! -z "$WAN_IP6" ]]; then
|
||||||
then
|
then
|
||||||
echo Updating IPv6 DNS records for $RECORD.$DOMAIN | logger
|
echo Updating IPv6 DNS records for $RECORD.$DOMAIN | logger
|
||||||
DATA='{"rrset_values": ["'$WAN_IP6'"]}'
|
DATA='{"rrset_values": ["'$WAN_IP6'"]}'
|
||||||
|
if [[ ! -z "$RECORD" ]]
|
||||||
|
then
|
||||||
IP6_RES=$(curl -s -XPUT -d "$DATA" \
|
IP6_RES=$(curl -s -XPUT -d "$DATA" \
|
||||||
-H"X-Api-Key: $APIKEY" \
|
-H"X-Api-Key: $APIKEY" \
|
||||||
-H"Content-Type: application/json" \
|
-H"Content-Type: application/json" \
|
||||||
"$API/domains/$DOMAIN/records/$RECORD/AAAA" 2>&1)
|
"$API/domains/$DOMAIN/records/$RECORD/AAAA" 2>&1)
|
||||||
|
else
|
||||||
|
IP6_RES=$(curl -s -XPUT -d "$DATA" \
|
||||||
|
-H"X-Api-Key: $APIKEY" \
|
||||||
|
-H"Content-Type: application/json" \
|
||||||
|
"$API/domains/$DOMAIN/records/@/AAAA" 2>&1)
|
||||||
|
fi
|
||||||
echo Update of IPv6 DNS record : $IP6_RES | logger
|
echo Update of IPv6 DNS record : $IP6_RES | logger
|
||||||
else
|
else
|
||||||
echo No need to update IPv6 DNS record for $RECORD.$DOMAIN | logger
|
echo No need to update IPv6 DNS record for $RECORD.$DOMAIN | logger
|
||||||
|
|
Loading…
Reference in a new issue