Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
getssl / usr / share / getssl / dns_scripts / dns_add_linode
Size: Mime:
#!/usr/bin/env bash

fulldomain="${1}"
token="${2}"
api_url="https://api.linode.com/v4"
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

# Get Domain List
response=$(curl --silent ${api_url}/domains \
  -H "User-Agent: getssl/0.1" -H "Authorization: Bearer ${api_key}")

# Get Domain ID for longest match
domain_root="$fulldomain"
domain=""

while [[ "$domain_root" == *.* ]] ; do
	domain_id=$(echo "$response" | jq ".data[]? | select (.domain==\"$domain_root\") | .id")
	if [[ "$domain_id" != "" ]] ; then
		break
	fi
	domain_root=${domain_root#*.}
	domain=${fulldomain%.$domain_root}
done

if [[ "$domain_id" == "" ]]; then
  echo "Failed to fetch DomainID"
  exit 1
fi

txtname="_acme-challenge${domain:+.$domain}"

# Create TXT record

response=$(curl --silent -X POST ${api_url}/domains/${domain_id}/records \
  -H "Content-Type: application/json" -H "User-Agent: getssl/0.1" -H "Authorization: Bearer ${api_key}" \
  -d '{"type": "TXT", "name": "'${txtname}'", "target": "'$token'", "ttl_sec": 30}')
errors=$(echo "$response" | jq ".errors[]?.reason")
if [[ "$errors" != "" ]]; then
    echo "Something went wrong: $errors"
    exit 1
fi