You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

48 lines
1.5 KiB

#!/usr/bin/env bash
fulldomain="${1}"
token="${2}"
api_url="https://dns.hetzner.com/api/v1"
api_key=${HETZNER_KEY:-''}
zone_id=${HETZNER_ZONE_ID:-''}
zone_name=${HETZNER_ZONE_NAME:-''}
# 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 "$HETZNER_KEY" ]]; then
echo "HETZNER_KEY variable not set"
exit 1
fi
if [ -z "$HETZNER_ZONE_ID" ] && [ -z "$HETZNER_ZONE_NAME" ] ; then
echo "HETZNER_ZONE_ID and HETZNER_ZONE_NAME variables not set"
exit 1
fi
# Get Zone ID if not set
if [ -z "$HETZNER_ZONE_ID" ] ; then
zone_id=$(curl --silent -X GET "$api_url/zones?name=$HETZNER_ZONE_NAME" -H 'Auth-API-Token: '"$api_key"'' | jq -r '.zones[0].id')
fi
# domain_root=$(echo "$fulldomain" | awk -F\. '{print $(NF-1) FS $NF FS}')
# domain=${fulldomain%.$domain_root}
txtname="_acme-challenge.$fulldomain."
echo $zone_id
# Create TXT record
response=$(curl --silent -X POST "$api_url/records" \
-H 'Content-Type: application/json' \
-H "Auth-API-Token: $api_key" \
-d '{"value": "'$token'","ttl": 60,"type": "TXT","name": "_acme-challenge.'$fulldomain'.","zone_id": "'$zone_id'"}')
echo "$response"
# errors=$(echo "$response" | egrep -o "\"ERRORARRAY\":\[.*\]")
# if [[ $errors != "\"ERRORARRAY\":[]" ]]; then
# echo "Something went wrong: $errors"
# exit 1
# fi