From c008231406e43f314a19a3d34c1218d06815dc8a Mon Sep 17 00:00:00 2001 From: David Timber Date: Mon, 9 Aug 2021 21:54:10 +1000 Subject: Impl proone-htbtclient txtrec mode ... * Relocate /src/data/proto/txtrec-*.sh to /src --- src/txtrec-set.sh | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 src/txtrec-set.sh (limited to 'src/txtrec-set.sh') diff --git a/src/txtrec-set.sh b/src/txtrec-set.sh new file mode 100755 index 0000000..50bb07d --- /dev/null +++ b/src/txtrec-set.sh @@ -0,0 +1,61 @@ +#!/bin/bash +set -e + +ARR_HOOKS=" + aws +" + +if [ $# -lt 2 ]; then + echo "Usage: $0 [TTL] +Hooks:" >&2 + for h in $ARR_HOOKS; do + echo -e "\t$h" + done + + exit 2 +fi + +HEAD_REC="$1" +HOOK="$2" +ZONE_ID="$3" +if [ -z "$4" ]; then + TTL=3600 +else + TTL="$4" +fi + +aws_param () { + cat << EOF +{ + "Changes": [ + { + "Action": "UPSERT", + "ResourceRecordSet": { + "Name": "$1", + "Type": "TXT", + "TTL": $TTL, + "ResourceRecords": [ + { "Value": "\"$2\"" } + ] + } + } + ] +} +EOF +} + +hook_aws () { + aws route53 change-resource-record-sets\ + --hosted-zone-id "$ZONE_ID"\ + --change-batch "$(aws_param "$1" "$2")" +} + +while read line; do + if [ -z "$line" ]; then + break; + fi + "hook_$HOOK" $line +done + +read line +"hook_$HOOK" "$HEAD_REC" "$line" -- cgit