Skip to content

Instantly share code, notes, and snippets.

@andrioid
Created May 21, 2015 17:48
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 andrioid/631be4220b9d06d4f5fd to your computer and use it in GitHub Desktop.
Save andrioid/631be4220b9d06d4f5fd to your computer and use it in GitHub Desktop.
Replace {{tags}} with environmental variables
for line in $(find . -iname '*.dtpl'); do
config=${line%.dtpl}
cp $line $config
echo "Replacing '$config'"
for key in $(cat $config | grep -o -P '({{[0-9a-z_-]+}})'); do
ukey=$(echo $key | sed 's/.*/\U&/' | sed -e "s/{{//" | sed -e "s/}}//")
val=$(eval "echo \$${ukey}")
#echo "Tag: $key $ukey $val"
if [ -n "$val" ]; then
echo "- Setting $key from environment."
sed -i -e "s/$key/$val/" $config
else
echo "- Setting $key to empty"
sed -i -e "s/$key//" $config
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment