#!/usr/bin/env bash

# based on https://github.com/lukas2511/dehydrated/wiki/example-dns-01-nsupdate-script

set -e
set -u
set -o pipefail

case "$1" in
	"deploy_challenge")
        echo ""
        echo "Adding the following TXT record to ${2} using azure-cli:"
		echo "_acme-challenge.${2}. IN TXT \"${4}\""
		echo ""
		echo -n "Press enter to continue..."
		read tmp
        az network dns record-set TXT add-record -g webtech -z ${2} -n _acme-challenge -v "${4}"
        echo ""
		echo -n "Press enter to continue..."
		read tmp
	;;
	"clean_challenge")
		echo ""
		echo "Removing the TXT record from ${2}..."
        az network dns record-set TXT remove-record -g webtech -z ${2} -n _acme-challenge -v "${4}"
		echo ""
	;;
	"sync_cert")
		# do nothing for now
	;;
	"deploy_cert")
		# do nothing for now
	;;
	"unchanged_cert")
		# do nothing for now
	;;
	"exit_hook")
		echo "${2:-}"
	;;
	*)
		echo "Unknown hook \"${1}\""
	;;
esac

exit 0
