Merge pull request #19470 from rmilecki/ddns-scripts-code-cleanup
[feed/packages.git] / net / ddns-scripts / files / usr / lib / ddns / update_gandi_net.sh
1 #!/bin/sh
2 # Thanks goes to Alex Griffin who provided this script.
3
4 . /usr/share/libubox/jshn.sh
5
6 local __TTL=600
7 local __RRTYPE
8 local __ENDPOINT="https://api.gandi.net/v5/livedns"
9 local __STATUS
10
11 [ -z "$username" ] && write_log 14 "Service section not configured correctly! Missing subdomain as 'username'"
12 [ -z "$password" ] && write_log 14 "Service section not configured correctly! Missing API Key as 'password'"
13
14 [ $use_ipv6 -ne 0 ] && __RRTYPE="AAAA" || __RRTYPE="A"
15
16 # Construct JSON payload
17 json_init
18 json_add_int rrset_ttl "$__TTL"
19 json_add_array rrset_values
20 json_add_string "" "$__IP"
21 json_close_array
22
23 __STATUS=$(curl -s -X PUT "$__ENDPOINT/domains/$domain/records/$username/$__RRTYPE" \
24 -H "Authorization: Apikey $password" \
25 -H "Content-Type: application/json" \
26 -d "$(json_dump)" \
27 -w "%{http_code}\n" -o $DATFILE 2>$ERRFILE)
28
29 if [ $? -ne 0 ]; then
30 write_log 14 "Curl failed: $(cat $ERRFILE)"
31 return 1
32 elif [ -z $__STATUS ] || [ $__STATUS != 201 ]; then
33 write_log 14 "LiveDNS failed: $__STATUS \ngandi.net answered: $(cat $DATFILE)"
34 return 1
35 fi
36
37 write_log 7 "gandi.net answered: $(cat $DATFILE)"
38
39 return 0