cloudflaredtunneldns/dns_update.sh

31 lines
1.0 KiB
Bash
Executable File

#!/bin/sh
set -eux
# First argument is cloudflared config file
# TODO - make this optional, and check standard locations if absent.
# Not doing it now because that would require me to remember how to
# do named arguments with bash (I think it's `getopt`?), and ain't
# nobody got time for that.
if [ $# -lt 1 ]; then
echo "Requires an argument pointing to the config file";
exit 1;
fi
CONFIG_FILE_LOCATION=$1
if [ ! -f $CONFIG_FILE_LOCATION ]; then
echo "File \"$CONFIG_FILE_LOCATION\" does not exist";
exit 1;
fi
# Second argument is "root domain".
# If set, only try to update DNS for names that are subdomains of this domain.
# If not set, try to update all names
TUNNEL_NAME=$(yq ".tunnel" $CONFIG_FILE_LOCATION);
if [ $# -gt 1 ]; then
ROOT_DOMAIN=$2;
yq ".ingress[].hostname | select(. != null) | select (. == \"*$ROOT_DOMAIN\")" $CONFIG_FILE_LOCATION | xargs -I {} cloudflared tunnel route dns $TUNNEL_NAME {};
else
yq '.ingress[].hostname | select(. != null)' $CONFIG_FILE_LOCATION | xargs -I {} cloudflared tunnel route dns $TUNNEL_NAME {};
fi