Skip to content

Instantly share code, notes, and snippets.

@scalp42
Forked from seeder/fetch-tmpl-content
Created May 27, 2017 00:13
Show Gist options
  • Save scalp42/e233c853cb0fc49424a8ced2bbda567a to your computer and use it in GitHub Desktop.
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
#!/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