forked from srvrco/getssl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdns_add_linode
executable file
·44 lines (39 loc) · 1.41 KB
/
dns_add_linode
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
#!/bin/bash
fulldomain="${1}"
token="${2}"
api_url="https://api.linode.com/api/"
api_key=${LINODE_KEY:-''}
# Verify that required parameters are set
if [[ -z "$fulldomain" ]]; then
echo "DNS script requires full domain name as first parameter"
exit 1
fi
if [[ -z "$token" ]]; then
echo "DNS script requires challenge token as second parameter"
exit 1
fi
if [[ -z "$LINODE_KEY" ]]; then
echo "LINODE_KEY variable not set"
exit 1
fi
domain_root=$(echo "$fulldomain" | awk -F\. '{print $(NF-1) FS $NF}')
domain=${fulldomain%.$domain_root}
txtname="_acme-challenge.$domain"
# Get Domain ID
response=$(curl --silent -X POST "$api_url" \
-H "Accept: application/json" -H "User-Agent: getssl/0.1" -H "application/x-www-form-urlencoded" \
-d "api_key=${api_key}&api_action=domain.list" )
domain_id=$(echo "$response" | egrep -o "{\"DOMAIN\":\"$domain_root\".*\"DOMAINID\":([0-9]+)" | egrep -o "[0-9]+$")
if [[ $domain_id == "" ]]; then
echo "Failed to fetch DomainID"
exit 1
fi
# Create TXT record
response=$(curl --silent -X POST "$api_url" \
-H "Accept: application/json" -H "User-Agent: getssl/0.1" -H "application/x-www-form-urlencoded" \
-d "api_key=$api_key&api_action=domain.resource.create&DomainID=$domain_id&Type=TXT&Name=$txtname&Target=$token" )
errors=$(echo "$response" | egrep -o "\"ERRORARRAY\":\[.*\]")
if [[ $errors != "\"ERRORARRAY\":[]" ]]; then
echo "Something went wrong: $errors"
exit 1
fi