Skip to content

Commit 44b0c3f

Browse files
author
srvrco
committed
adding linode dns
1 parent cb77791 commit 44b0c3f

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

dns_scripts/dns_add_linode

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
3+
fulldomain="${1}"
4+
token="${2}"
5+
api_url="https://api.linode.com/api/"
6+
api_key=${LINODE_KEY:-''}
7+
8+
# Verify that required parameters are set
9+
if [[ -z "$fulldomain" ]]; then
10+
echo "DNS script requires full domain name as first parameter"
11+
exit 1
12+
fi
13+
if [[ -z "$token" ]]; then
14+
echo "DNS script requires challenge token as second parameter"
15+
exit 1
16+
fi
17+
if [[ -z "$LINODE_KEY" ]]; then
18+
echo "LINODE_KEY variable not set"
19+
exit 1
20+
fi
21+
22+
domain_root=$(echo "$fulldomain" | awk -F\. '{print $(NF-1) FS $NF}')
23+
domain=${fulldomain%.$domain_root}
24+
txtname="_acme-challenge.$domain"
25+
26+
# Get Domain ID
27+
response=$(curl --silent -X POST "$api_url" \
28+
-H "Accept: application/json" -H "User-Agent: getssl/0.1" -H "application/x-www-form-urlencoded" \
29+
-d "api_key=${api_key}&api_action=domain.list" )
30+
domain_id=$(echo "$response" | egrep -o "{\"DOMAIN\":\"$domain_root\".*\"DOMAINID\":([0-9]+)" | egrep -o "[0-9]+$")
31+
if [[ $domain_id == "" ]]; then
32+
echo "Failed to fetch DomainID"
33+
exit 1
34+
fi
35+
36+
# Create TXT record
37+
response=$(curl --silent -X POST "$api_url" \
38+
-H "Accept: application/json" -H "User-Agent: getssl/0.1" -H "application/x-www-form-urlencoded" \
39+
-d "api_key=$api_key&api_action=domain.resource.create&DomainID=$domain_id&Type=TXT&Name=$txtname&Target=$token" )
40+
errors=$(echo "$response" | egrep -o "\"ERRORARRAY\":\[.*\]")
41+
if [[ $errors != "\"ERRORARRAY\":[]" ]]; then
42+
echo "Something went wrong: $errors"
43+
exit 1
44+
fi

dns_scripts/dns_del_linode

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
3+
fulldomain="${1}"
4+
api_url="https://api.linode.com/api/"
5+
api_key=${LINODE_KEY:-''}
6+
7+
# Verify that required parameters are set
8+
if [[ -z "$fulldomain" ]]; then
9+
echo "DNS script requires full domain name as first parameter"
10+
exit 1
11+
fi
12+
if [[ -z "$LINODE_KEY" ]]; then
13+
echo "LINODE_KEY variable not set"
14+
exit 1
15+
fi
16+
17+
domain_root=$(echo "$fulldomain" | awk -F\. '{print $(NF-1) FS $NF}')
18+
domain=${fulldomain%.$domain_root}
19+
txtname="_acme-challenge.$domain"
20+
21+
# 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]+$")
26+
if [[ $domain_id == "" ]]; then
27+
echo "Failed to fetch DomainID"
28+
exit 1
29+
fi
30+
31+
# 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]+$")
36+
if [[ $resource_id == "" ]]; then
37+
echo "Failed to fetch ResourceID"
38+
exit 1
39+
fi
40+
41+
# 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
47+
echo "Something went wrong: $errors"
48+
exit 1
49+
fi

0 commit comments

Comments
 (0)