#!/bin/bash set -xeuo pipefail if dig txt _acme-challenge.$CERTBOT_DOMAIN | grep certbot.rfc2136.sijanec.eu > /dev/null then CREATE_DOMAIN="certbot.rfc2136.sijanec.eu." KEYFILE=/etc/bind/keyfile-rfc2136.conf MASTER=ns1.sijanec.org else CREATE_DOMAIN=_acme-challenge.$CERTBOT_DOMAIN for i in {1..10} do DOMENA=$(echo $CERTBOT_DOMAIN | cut -d. -f$i-) if [ x$DOMENA = x ] then break fi KEYFILE=`grep ddns-key.$DOMENA /etc/bind/keyfile-*.conf /etc/hostname | cut -d: -f1` || continue MASTER=`dig $DOMENA soa +short | cut -d\ -f1` break done if [ $MASTER = ns1.sijanec.org ] then echo MASTER se ni spremenil >&2 exit 1 fi if [ x$MASTER = x ] then echo MASTER je prazen >&2 exit 1 fi fi # update delete $CREATE_DOMAIN TXT echo " server $MASTER update add $CREATE_DOMAIN 1 TXT $CERTBOT_VALIDATION send " | tee /dev/stderr | nsupdate -k $KEYFILE if [ $CERTBOT_REMAINING_CHALLENGES -eq 0 ] then rndc reload sleep 3 fi