Created
February 13, 2014 02:56
-
-
Save KylePDavis/8968931 to your computer and use it in GitHub Desktop.
A template for shell-based templates. Good for generalizing config files and the like.
This file contains hidden or 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
#!/bin/bash | |
# Template bash script using given script file as source for variable values | |
if [ -f "$1" ]; then source "$1" || echo "#! ERROR: Unable to read variables from script: $1!" 1>&2 && exit 1; fi | |
(awk '/TMPL$/,/^TMPL/{print}' "$0" | grep -Eio '(^|[^\])\${?[A-Z][A-Z0-9_]*}?' | cut -c3- | tr -d '{}' | sort -u) | grep -v -w -F "$(env | cut -f1 -d= | sort)" | sed 's/^/ERROR: need tmpl var: /' | grep . && exit 123 || true | |
############################################################################### | |
cat<<TMPL | |
# Config generated on $(date) | |
HOST=$SOME_HOST | |
FILES="$(ls -1 | paste -sd,)" | |
TMPL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment