11#! /usr/bin/env bash
22
33fulldomain=" ${1} "
4- api_url=" https://api.linode.com/api/ "
4+ api_url=" https://api.linode.com/v4 "
55api_key=${LINODE_KEY:- ' ' }
66
77# Verify that required parameters are set
@@ -14,36 +14,33 @@ if [[ -z "$LINODE_KEY" ]]; then
1414 exit 1
1515fi
1616
17- domain_root=$( echo " $ fulldomain" | awk -F \. ' {print $(NF-1) FS $NF} ' )
17+ domain_root=${ fulldomain#* .}
1818domain=${fulldomain% .$domain_root }
1919txtname=" _acme-challenge.$domain "
2020
2121# Get Domain ID
22- response=$( curl --silent -X POST " $api_url " \
23- -H " Accept: application/json" -H " User-Agent: getssl/0.1" -H " application/x-www-form-urlencoded" \
24- -d " api_key=${api_key} &api_action=domain.list" )
25- domain_id=$( echo " $response " | egrep -o " {\" DOMAIN\" :\" $domain_root \" .*\" DOMAINID\" :([0-9]+)" | egrep -o " [0-9]+$" )
22+ response=$( curl --silent ${api_url} /domains \
23+ -H " User-Agent: getssl/0.1" -H " Authorization: Bearer ${api_key} " )
24+ domain_id=$( echo " $response " | jq " .data[] | select (.domain==\" $domain_root \" ) | .id" )
2625if [[ $domain_id == " " ]]; then
2726 echo " Failed to fetch DomainID"
2827 exit 1
2928fi
3029
3130# Get Resource ID
32- response=$( curl --silent -X POST " $api_url " \
33- -H " Accept: application/json" -H " User-Agent: getssl/0.1" -H " application/x-www-form-urlencoded" \
34- -d " api_key=${api_key} &api_action=domain.resource.list&DomainID=$domain_id " )
35- resource_id=$( echo " $response " | egrep -o " \" RESOURCEID\" :[0-9]+,\" TYPE\" :\" TXT\" ,\" NAME\" :\" $txtname \" " | egrep -o " \" RESOURCEID\" :[0-9]+" | egrep -o " [0-9]+$" )
31+ response=$( curl --silent ${api_url} /domains/${domain_id} /records \
32+ -H " User-Agent: getssl/0.1" -H " Authorization: Bearer ${api_key} " )
33+ resource_id=$( echo " $response " | jq " .data[] | select (.name==\" $txtname \" ) | .id" )
3634if [[ $resource_id == " " ]]; then
3735 echo " Failed to fetch ResourceID"
3836 exit 1
3937fi
4038
4139# Delete TXT record
42- response=$( curl --silent -X POST " $api_url " \
43- -H " Accept: application/json" -H " User-Agent: getssl/0.1" -H " application/x-www-form-urlencoded" \
44- -d " api_key=$api_key &api_action=domain.resource.delete&DomainID=$domain_id &ResourceID=$resource_id " )
45- errors=$( echo " $response " | egrep -o " \" ERRORARRAY\" :\[.*\]" )
46- if [[ $errors != " \" ERRORARRAY\" :[]" ]]; then
40+ response=$( curl --silent -X DELETE ${api_url} /domains/${domain_id} /records/${resource_id} \
41+ -H " User-Agent: getssl/0.1" -H " Authorization: Bearer ${api_key} " )
42+ errors=$( echo " $response " | jq " .errors[]?.reason" )
43+ if [[ $errors != " " ]]; then
4744 echo " Something went wrong: $errors "
4845 exit 1
4946fi
0 commit comments