Last active
September 23, 2018 18:48
-
-
Save LTGIV/2a666090073020c06397530b948f2277 to your computer and use it in GitHub Desktop.
DNSControl Compiler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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