24 lines
1.1 KiB
Bash
24 lines
1.1 KiB
Bash
|
#!/bin/bash
|
||
|
APIKEY="$(awk 'BEGIN {RS="\n"; FS="\t";}{if($1=="APIKEY"){print $2}}' /etc/zoneupdate.conf)"
|
||
|
DOMAIN="$(awk 'BEGIN {RS="\n"; FS="\t";}{if($1=="DOMAIN"){print $2}}' /etc/zoneupdate.conf)"
|
||
|
subdomainList=(@ "$(awk 'BEGIN {RS="\n"; FS="\t";}{if($1=="SUBDOMAIN"){print $2}}' /etc/zoneupdate.conf)")
|
||
|
OLD_IP="$(awk 'BEGIN {RS="\n"; FS="\t";}{if($1=="IP"){print $2}}' /etc/zoneupdate.conf)"
|
||
|
NEW_IP=$(curl -4 -s icanhazip.com)
|
||
|
|
||
|
|
||
|
if [[ "${OLD_IP}" != "${NEW_IP}" ]]; then
|
||
|
for subdomain in ${subdomainList[@]}; do
|
||
|
RESP=$(curl -s -X PUT -H "Content-Type: application/json" \
|
||
|
-H "X-Api-Key: $APIKEY" \
|
||
|
-d '{"items": [{"rrset_type": "A",
|
||
|
"rrset_ttl": 3600,
|
||
|
"rrset_values":["'$NEW_IP'"]}]}' \
|
||
|
https://dns.api.gandi.net/api/v5/domains/$DOMAIN/records/$subdomain)
|
||
|
[[ "${RESP}" != '{"message": "DNS Record Created"}' ]] && ERROR=true
|
||
|
done
|
||
|
[[ "${ERROR}" != "true" ]] && { gawk -i inplace -v IP="${NEW_IP}" 'BEGIN {RS="\n"; FS="\t"; OFS="\t"}{if($1=="IP"){$2=IP}{print $0}}' /etc/zoneupdate.conf; exit 0; } || { echo ${RESP}; exit 1; }
|
||
|
else
|
||
|
exit 0
|
||
|
fi
|
||
|
|