commit 48993f0e4d35533239256be2502d8710671b693f Author: Jack Jackson Date: Fri Aug 19 16:51:47 2022 -0700 First commit diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..cf9ee16 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,37 @@ +FROM debian:buster + +###### +## Install cloudflared tool +###### + +# Instructions from https://pkg.cloudflare.com/ +RUN apt update && apt -y upgrade +# These two utilities are required but are (understandably) not listed +# in pkg.cloudflare.com's instructions +RUN apt install -y curl ca-certificates +# This utility is required for installation of yq - but we put it earlier +# to maximize build cache hits +RUN apt install -y wget + +RUN mkdir -p --mode=0755 /usr/share/keyrings +RUN curl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg\ + | tee /usr/share/keyrings/cloudflare-main.gpg >/dev/null +# Do not try to line-break in the middle of the quoted string! +RUN echo 'deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared buster main' \ + | tee /etc/apt/sources.list.d/cloudflared.list + +RUN apt update && apt install cloudflared + +###### +## Install yq (for parsing YAML) +###### + +# https://github.com/mikefarah/yq - I tried switching to `curl -o -` but that gave no output? +RUN wget https://github.com/mikefarah/yq/releases/download/v4.18.1/yq_linux_arm64.tar.gz -O - 2>/dev/null |\ + tar xz && mv yq_linux_arm64 /usr/bin/yq + +###### +## Install own script +###### + +COPY dns_update.sh . diff --git a/dns_update.sh b/dns_update.sh new file mode 100755 index 0000000..cc040e9 --- /dev/null +++ b/dns_update.sh @@ -0,0 +1,27 @@ +#!/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 +