Skip to content

Instantly share code, notes, and snippets.

@LTGIV
Last active September 23, 2018 18:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LTGIV/2a666090073020c06397530b948f2277 to your computer and use it in GitHub Desktop.
Save LTGIV/2a666090073020c06397530b948f2277 to your computer and use it in GitHub Desktop.
DNSControl Compiler
#!/usr/bin/env bash
: <<'!COMMENT'
DNSControl Compiler v201712120445
Louis T. Getterman IV (@LTGIV)
https://Thad.Getterman.org/2017/12/11/dnscontrol-compiler
# DNSControl
https://github.com/StackExchange/dnscontrol
https://github.com/StackExchange/dnscontrol/blob/master/docs/getting-started.md
# Encrypt creds.json
https://www.agwa.name/projects/git-crypt/
https://github.com/StackExchange/blackbox
!COMMENT
################################################################################
SOURCE="${BASH_SOURCE[0]}" # Dave Dopson, Thank You! - http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
SCRIPTPATH="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$SCRIPTPATH/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
################################################################################
SCRIPTPATH="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SCRIPTNAME=`basename "$SOURCE"`
################################################################################
# Compile
: <<'!COMMENT'
https://github.com/StackExchange/dnscontrol/issues/51
https://stackoverflow.com/questions/24069173/recursive-cat-all-the-files-into-single-file
!COMMENT
DNSCONFIGJS="${SCRIPTPATH}/dnsconfig.js"
cat "${SCRIPTPATH}/global.js" > "${DNSCONFIGJS}"
find "${SCRIPTPATH}/domains" -type f -name '*.js' -exec cat {} \; >> "${DNSCONFIGJS}"
# Mode
COMMAND=${1-preview}
case "$COMMAND" in
"preview")
echo "You're in preview mode, ^C to abort."
echo "Please use '${SCRIPTNAME} push' when you're ready to save changes."
sleep 2
true
;;
"push")
echo "Saving changes."
true
;;
*)
: <<'!COMMENT'
Other modes offered by DNSControl, such as:
check
print-ir
version
create-domains
help
!COMMENT
false
;;
esac
# Pull
docker pull stackexchange/dnscontrol
# Run
docker \
run \
--rm \
-it \
-v "${DNSCONFIGJS}":/dns/dnsconfig.js \
-v "${SCRIPTPATH}/creds.json":/dns/creds.json \
stackexchange/dnscontrol \
dnscontrol ${COMMAND}
# Clean-up
rm -rf "${DNSCONFIGJS}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment