Last active
February 13, 2018 08:17
-
-
Save fmoessbauer/3695a4c32a825f9f9ea9dc6a754d5e24 to your computer and use it in GitHub Desktop.
Revisions
-
fmoessbauer revised this gist
Feb 13, 2018 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ #!/bin/bash # Trivial solution to replace placeholders in config files # Finds all .tpl files, replaces keys and stores the result # without .tpl # @@ -13,9 +13,10 @@ function replace_in_file { FILENAME=${1//.tpl/} [[ $FILENAME == $1 ]] && exit 1 echo "Process $FILENAME" cp $1 $FILENAME while read p; do KEYVAL=(${p//=/ }) sed -i -e "s/<<${KEYVAL[0]}>>/${KEYVAL[1]}/g" $FILENAME done < $2 } -
fmoessbauer created this gist
Feb 12, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ #!/bin/bash # Trivial solution to substitute placeholders in config files # Finds all .tpl files, replaces keys and stores the result # without .tpl # # Usage: replacer.sh <keyfile> # # Keyfile format: # key=value # key2=value2 function replace_in_file { FILENAME=${1//.tpl/} [[ $FILENAME == $1 ]] && exit 1 echo "Process $FILENAME" while read p; do KEYVAL=(${p//=/ }) sed -e "s/<<${KEYVAL[0]}>>/${KEYVAL[1]}/g" $1 > $FILENAME done < $2 } [ -e "$1" ] || exit 1 echo "Secrets file: $1" find . -iname "*.tpl" | while read p; do replace_in_file $p $1 done