Commit 08a61cbb authored by intrigeri's avatar intrigeri
Browse files

Encode the biggest allocated mirror ID in the last.dl.amnesia.boum.org CNAME record.

This feels like a more robust way to track what's the highest allocated mirror
ID than the previous loop. And contrary to the previous implementation, it
doesn't rely on the fact that there is no hole in the range of the NNN.dl.a.b.o
we've allocated (which should be more robust against mistakes in the pool
management).
parent e982c38b
......@@ -6,18 +6,22 @@ set -o pipefail
function usage {
echo "Usage: $0 IP"
echo "Creates a NNN.dl.amnesia.boum.org A record pointing to IP"
echo "Creates a NNN.dl.amnesia.boum.org A record pointing to IP,"
echo "and updates the last.dl.amnesia.boum.org CNAME record to"
echo "point to that new host name."
exit 1
}
function next_free_mirror_id {
current=1
while host -t a "$current.dl.amnesia.boum.org" boum.org >/dev/null ; do
current=$(($current + 1))
done
echo $current
last_hostname=$(dig @boum.org last.dl.amnesia.boum.org CNAME +short \
| sed -e 's,\.$,,')
last_id=$(echo "$last_hostname" \
| perl -p -E 's,^(\d+)\.dl\.amnesia\.boum\.org$,$1,')
echo "$last_id" | grep -qs --line-regexp --extended-regexp '[0-9]+' || exit 2
echo $(($last_id + 1))
}
[ "$#" -eq 1 ] || usage
[ -z "$1" ] && usage
id=$(next_free_mirror_id)
......@@ -26,8 +30,12 @@ nsupdate -v -k ~/lizard-boum.key << EOF
server boum.org
zone amnesia.boum.org
prereq nxrrset $id.dl.amnesia.boum.org A
prereq yxdomain last.dl.amnesia.boum.org
prereq yxrrset last.dl.amnesia.boum.org CNAME
update add $id.dl.amnesia.boum.org 300 A $1
update delete last.dl.amnesia.boum.org 300 CNAME
update add last.dl.amnesia.boum.org 300 CNAME $id.dl.amnesia.boum.org
send
EOF
echo "Created $id.dl.amnesia.boum.org"
echo "Created $id.dl.amnesia.boum.org, and updated last.dl.amnesia.boum.org"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment