|
|
|
@ -10,6 +10,12 @@ apikey=${DYNU_API_KEY:-''} |
|
|
|
# 2 - error within internal processing |
|
|
|
# 3 - error in result ( domain not found in dynu.com etc) |
|
|
|
|
|
|
|
# After deleting the TXT record from Dynu.com it takes over 30 minutes to add a new TXT record! |
|
|
|
# This doesn't happen when updating the TXT record, just for delete then add |
|
|
|
# As this is used for testing, changed the delete to a no-op. |
|
|
|
|
|
|
|
exit 0 |
|
|
|
|
|
|
|
fulldomain="${1}" |
|
|
|
|
|
|
|
API='https://api.dynu.com/v2/dns' |
|
|
|
@ -20,17 +26,18 @@ if [[ -z "$fulldomain" ]]; then |
|
|
|
exit 1 |
|
|
|
fi |
|
|
|
if [[ -z "$apikey" ]]; then |
|
|
|
echo "DNS script requires an apikey to be set" |
|
|
|
echo "DNS script requires apikey environment variable to be set" |
|
|
|
exit 1 |
|
|
|
fi |
|
|
|
|
|
|
|
curl_params=( -H "accept: application/json" -H "API-Key: $apikey" -H 'Content-Type: application/json' ) |
|
|
|
|
|
|
|
# Get domain id |
|
|
|
resp=$(curl --silent "${curl_params[@]}" -X GET "$API") |
|
|
|
# curl -X GET https://api.dynu.com/v2/dns/getroot/ubuntu-getssl.freeddns.org |
|
|
|
resp=$(curl --silent "${curl_params[@]}" -X GET "$API/getroot/${fulldomain}") |
|
|
|
|
|
|
|
# Match domain id |
|
|
|
re="\"id\":([^,]*),\"name\":\"getssl-testing.freeddns.org\"" |
|
|
|
re="\"id\":([^,]*),\"domainName\":\"${fulldomain}\"" |
|
|
|
if [[ "$resp" =~ $re ]]; then |
|
|
|
domain_id="${BASH_REMATCH[1]}" |
|
|
|
fi |
|
|
|
@ -40,7 +47,8 @@ if [[ -z "$domain_id" ]]; then |
|
|
|
exit 3 |
|
|
|
fi |
|
|
|
|
|
|
|
# Find existing _acme-challenge TXT record |
|
|
|
# Check for existing _acme-challenge TXT record |
|
|
|
# curl -X GET "https://api.dynu.com/v2/dns/record/_acme-challenge.ubuntu-getssl.freeddns.org?recordType=TXT" |
|
|
|
resp=$(curl --silent "${curl_params[@]}" -X GET "${API}/record/_acme-challenge.${fulldomain}?recordType=TXT") |
|
|
|
re="\"id\":([^,]*)" |
|
|
|
if [[ "$resp" =~ $re ]]; then |
|
|
|
@ -48,8 +56,8 @@ if [[ "$resp" =~ $re ]]; then |
|
|
|
fi |
|
|
|
|
|
|
|
if [[ -z "$record_id" ]]; then |
|
|
|
echo "No _acme-challenge TXT record found for $fulldomain" |
|
|
|
exit 3 |
|
|
|
echo "No _acme-challenge.${fulldomain} TXT record found" |
|
|
|
exit 0 |
|
|
|
fi |
|
|
|
|
|
|
|
resp=$(curl --silent \ |
|
|
|
@ -57,7 +65,7 @@ resp=$(curl --silent \ |
|
|
|
-X DELETE "${API}/${domain_id}/record/${record_id}") |
|
|
|
|
|
|
|
# If adding record failed (exception:) then print error message |
|
|
|
if [[ "${resp// }" == *'"exception"'* ]]; then |
|
|
|
if [[ "$resp" != *"\"statusCode\":200"* ]]; then |
|
|
|
echo "Error: DNS challenge not added: unknown error - ${resp}" |
|
|
|
exit 3 |
|
|
|
fi |