scripts/openwrt/ddns_gandi.sh

23 lines
638 B
Bash
Executable File

#!/bin/sh
ttl=300
ip=${1}
second_level_domain="$domain"
subdomain="{@}"
depth=$(echo "$domain" | grep -o "[.]" | wc -l)
if [ "$depth" -ge 2 ]; then
second_level_domain=$(echo "$domain" | cut -s -d '.' -f ${depth}-)
subdomain=$(echo "$domain" | cut -s -d '.' -f -$((depth - 1)))
fi
echo "second_level_domain = ${second_level_domain}"
echo "subdomain = ${subdomain}"
curl -fs -o /dev/null -X PUT -H "Content-Type: application/json" \
-H "X-Api-Key: ${password}" \
-d "{\"rrset_ttl\": ${ttl}, \"rrset_values\": [\"${ip}\"]}" \
"https://dns.api.gandi.net/api/v5/domains/${second_level_domain}/records/${subdomain}/A"