-
-
Save scalp42/e233c853cb0fc49424a8ced2bbda567a to your computer and use it in GitHub Desktop.
Used for fetching templates from consul for use in consul-template as plugin
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/sh | |
TMPL=$1 | |
DESTINATION=/config/consultemplate/template/$TMPL | |
TMPDESTINATION=/tmp/$DESTINATION | |
LOGS=/logs/$HOSTNAME | |
mkdir -p $LOGS | |
mkdir -p "`dirname $DESTINATION`" | |
mkdir -p "`dirname $TMPDESTINATION`" | |
if curl -f -sS "$CONSUL_HTTP_ADDR/v1/kv/$TMPL?raw&token=$CONSUL_TOKEN" -o $TMPDESTINATION --stderr $LOGS/fetch.log | |
then | |
if ! grep -s "rpc error" $TMPDESTINATION | |
then | |
mv $TMPDESTINATION $DESTINATION | |
else | |
echo "$TMPDESTINATION rpc error, not overwriting files" >> $LOGS/fetch.log | |
fi | |
else | |
echo "$TMPDESTINATION curl failed, not overwriting files" >> $LOGS/fetch.log | |
fi | |
sha256sum $DESTINATION | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment