Skip to content

Instantly share code, notes, and snippets.

@statianzo
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save statianzo/6461030aa2dace62bb2e to your computer and use it in GitHub Desktop.
Save statianzo/6461030aa2dace62bb2e to your computer and use it in GitHub Desktop.
etcd directory to env file, supports recursion
#!/bin/bash
set -eo pipefail
usage(){
echo "etcdenv - Recursively prints etcd dir as environment file"
echo "Usage: etcdenv rootdir"
exit 1
}
[ $# -eq 0 ] && usage
rootdir=$1
keys=$(etcdctl ls --recursive $rootdir)
for key in $keys; do
subname=${key#"$rootdir/"} #strip prefix
envname=${subname//\//_} #convert / to _
val="$(etcdctl get $key 2>/dev/null || exit 0)"
if [ -n "$val" ]; then
echo $envname=$val
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment