Created
May 4, 2016 18:45
-
-
Save jdhuntington/4515c2af01e4c6119eb18609643ee176 to your computer and use it in GitHub Desktop.
templating with bash
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
Top of file { | |
foo; | |
bar; | |
} | |
serverlist { | |
__SERVERLIST__ | |
} | |
And more stuff...% |
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
#!/bin/bash | |
set -uex | |
COMPILED_SERVER_LIST="" | |
NEWLINE=$'\\n' | |
for var in ${@} | |
do | |
NEXT_LINE="upstream_server ${var};" | |
COMPILED_SERVER_LIST="${COMPILED_SERVER_LIST}${NEXT_LINE}${NEWLINE}" | |
done | |
cat nginx.conf | sed -e "s/__SERVERLIST__/${COMPILED_SERVER_LIST}/g" > nginx.conf.compiled | |
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
./setup.sh foo 10.0.0.4 10.0.0.5 10.0.0.6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment