#!/bin/bash

# need to add your Token for duckdns below
token=${DUCKDNS_TOKEN:-}

if [ -z "$token" ]; then
    echo "DUCKDNS_TOKEN not set"
    exit 1
fi

domain="$1"
txtvalue="$2"

response=$(curl --silent "https://www.duckdns.org/update?domains=${domain}&token=${token}&txt=${txtvalue}")
if [ "$response" != "OK" ]; then
    echo "Failed to update TXT record for ${domain} at duckdns.org (is the TOKEN valid?)"
    echo "Response: $response"
    exit 1
fi
