|
|
@ -18,7 +18,7 @@ dns_gcloud_add() { |
|
|
|
_dns_gcloud_start_tr || return $? |
|
|
|
_dns_gcloud_get_rrdatas || return $? |
|
|
|
echo "$rrdatas" | _dns_gcloud_remove_rrs || return $? |
|
|
|
echo -e "$rrdatas\n\"$txtvalue\"" | grep -v '^$' | _dns_gcloud_add_rrs || return $? |
|
|
|
printf "%s\n%s\n" "$rrdatas" "\"$txtvalue\"" | grep -v '^$' | _dns_gcloud_add_rrs || return $? |
|
|
|
_dns_gcloud_execute_tr || return $? |
|
|
|
|
|
|
|
_info "$fulldomain record added" |
|
|
@ -39,7 +39,7 @@ dns_gcloud_rm() { |
|
|
|
_dns_gcloud_start_tr || return $? |
|
|
|
_dns_gcloud_get_rrdatas || return $? |
|
|
|
echo "$rrdatas" | _dns_gcloud_remove_rrs || return $? |
|
|
|
echo "$rrdatas" | fgrep -v "\"$txtvalue\"" | _dns_gcloud_add_rrs || return $? |
|
|
|
echo "$rrdatas" | grep -F -v "\"$txtvalue\"" | _dns_gcloud_add_rrs || return $? |
|
|
|
_dns_gcloud_execute_tr || return $? |
|
|
|
|
|
|
|
_info "$fulldomain record added" |
|
|
@ -48,7 +48,7 @@ dns_gcloud_rm() { |
|
|
|
#################### Private functions below ################################## |
|
|
|
|
|
|
|
_dns_gcloud_start_tr() { |
|
|
|
if ! trd=`mktemp -d`; then |
|
|
|
if ! trd=$(mktemp -d); then |
|
|
|
_err "_dns_gcloud_start_tr: failed to create temporary directory" |
|
|
|
return 1 |
|
|
|
fi |
|
|
@ -68,19 +68,19 @@ _dns_gcloud_execute_tr() { |
|
|
|
if ! gcloud dns record-sets transaction execute \ |
|
|
|
--transaction-file="$tr" \ |
|
|
|
--zone="$managedZone"; then |
|
|
|
_debug tr "`cat \"$tr\"`" |
|
|
|
_debug tr "$(cat "$tr")" |
|
|
|
rm -r "$trd" |
|
|
|
_err "_dns_gcloud_execute_tr: failed to execute transaction" |
|
|
|
return 1 |
|
|
|
fi |
|
|
|
rm -r "$trd" |
|
|
|
|
|
|
|
for i in `seq 1 120`; do |
|
|
|
for i in $(seq 1 120); do |
|
|
|
if gcloud dns record-sets changes list \ |
|
|
|
--zone=lenart \ |
|
|
|
--filter='status != done' \ |
|
|
|
| grep -q '.*'; then |
|
|
|
_info "_dns_gcloud_execute_tr: waiting for transaction to be comitted ..." |
|
|
|
| grep -q '^.*'; then |
|
|
|
_info "_dns_gcloud_execute_tr: waiting for transaction to be comitted ($i/120)..." |
|
|
|
sleep 5 |
|
|
|
else |
|
|
|
return 0 |
|
|
@ -99,7 +99,7 @@ _dns_gcloud_remove_rrs() { |
|
|
|
--type=TXT \ |
|
|
|
--zone="$managedZone" \ |
|
|
|
--transaction-file="$tr"; then |
|
|
|
_debug tr "`cat \"$tr\"`" |
|
|
|
_debug tr "$(cat "$tr")" |
|
|
|
rm -r "$trd" |
|
|
|
_err "_dns_gcloud_remove_rrs: failed to remove RRs" |
|
|
|
return 1 |
|
|
@ -114,7 +114,7 @@ _dns_gcloud_add_rrs() { |
|
|
|
--type=TXT \ |
|
|
|
--zone="$managedZone" \ |
|
|
|
--transaction-file="$tr"; then |
|
|
|
_debug tr "`cat \"$tr\"`" |
|
|
|
_debug tr "$(cat "$tr")" |
|
|
|
rm -r "$trd" |
|
|
|
_err "_dns_gcloud_add_rrs: failed to add RRs" |
|
|
|
return 1 |
|
|
@ -129,7 +129,7 @@ _dns_gcloud_find_zone() { |
|
|
|
filter="dnsName=( " |
|
|
|
while [ "$part" != "" ]; do |
|
|
|
filter="$filter$part. " |
|
|
|
part="`echo \"$part\" | sed 's/[^.]*\.*//'`" |
|
|
|
part="$(echo "$part" | sed 's/[^.]*\.*//')" |
|
|
|
done |
|
|
|
filter="$filter)" |
|
|
|
_debug filter "$filter" |
|
|
@ -138,10 +138,10 @@ _dns_gcloud_find_zone() { |
|
|
|
if ! match=$(gcloud dns managed-zones list \ |
|
|
|
--format="value(name, dnsName)" \ |
|
|
|
--filter="$filter" \ |
|
|
|
| while read dnsName name; do |
|
|
|
echo -e "${#dnsName}\t$dnsName\t$name" |
|
|
|
| while read -r dnsName name; do |
|
|
|
printf "%s\t%s\t%s\n" "${#dnsName}" "$dnsName" "$name" |
|
|
|
done \ |
|
|
|
| sort -n -r | head -n1 | cut -f2,3 | grep '.*'); then |
|
|
|
| sort -n -r | head -n1 | cut -f2,3 | grep '^.*'); then |
|
|
|
_err "_dns_gcloud_find_zone: Can't find a matching managed zone! Perhaps wrong project or gcloud credentials?" |
|
|
|
return 1 |
|
|
|
fi |
|
|
|