-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdns_add_acme_dns
executable file
·52 lines (36 loc) · 1.05 KB
/
dns_add_acme_dns
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
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env bash
# acme-dns configuration
api_url=${ACME_DNS_API_URL:-''}
username=${ACME_DNS_USERNAME:-''}
password=${ACME_DNS_PASSWORD:-''}
subdomain=${ACME_DNS_SUBDOMAIN:-''}
fulldomain="${1}"
token="${2}"
curl_params=( -H "X-Api-User: $username" -H "X-Api-Key: $password" )
data='{"subdomain": "'$subdomain'", "txt": "'$token'"}'
if [[ ${_USE_DEBUG} -eq 1 ]]; then
echo "Calling ${api_url} with data ${data}"
fi
tempfile=$(mktemp)
http_code=$(curl --silent "${curl_params[@]}" -X POST --write-out '%{http_code}' -o ${tempfile} -d "${data}" \
"${api_url}/update")
if [ $? -ne 0 ]; then
echo "Curl failed to fetch $api_url" >&2
rm -f $tempfile
exit 1
fi
resp=$(cat $tempfile)
rm -f $tempfile
error=$(echo $resp | sed -n 's/.*"error": *"\([^"]*\)*".*/\1/p')
if [ ! -z "$error" ]; then
echo "Error adding DNS record: $error" >&2
exit 1
fi
if [ "${http_code}" -gt 399 ]; then
echo "Curl got http error code ${http_code} from $api_url" >&2
exit 1
fi
if [[ ${_USE_DEBUG} -eq 1 ]]; then
echo response $resp
fi
exit 0