cloudflaredtunneldns/dns_update.sh
2022-08-19 16:51:47 -07:00

28 lines
967 B
Bash
Executable File

#!/bin/sh
# 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
if [ $# -gt 1 ]; then
ROOT_DOMAIN=$2;
yq ".ingress[].hostname | select(. != null) | select (. == \"*$ROOT_DOMAIN\")" $CONFIG_FILE_LOCATION | xargs -I {} echo "Would process {}";
else
yq '.ingress[].hostname | select(. != null)' $CONFIG_FILE_LOCATION | xargs -I {} echo "Would process {}";
fi