No longer try to use gsed in templater on OSX thanks to .bak workaround

This commit is contained in:
Kevin van Zonneveld 2016-02-17 13:44:28 +01:00
parent 0917b75cb9
commit d43cecf24a

View File

@ -30,10 +30,6 @@
# Copyright (c) 2016 Kevin van Zonneveld (http://kvz.io)
function templater() {
sed=""
[ -n "$(which sed)" ] && sed="$(which sed)"
[ -n "$(which gsed)" ] && sed="$(which gsed)"
ALLOW_REMAINDERS="${ALLOW_REMAINDERS:-0}"
templateSrc="${1:-}"
@ -50,14 +46,14 @@ function templater() {
cp -f "${templateSrc}" "${templateDst}"
for var in $(env |awk -F= '{print $1}' |egrep '^[A-Z0-9_]+$'); do
${sed} -i.bak -e "s#\${${var}}#${!var}#g" "${templateDst}"
sed -i.bak -e "s#\${${var}}#${!var}#g" "${templateDst}"
# this .bak dance is done for BSD/GNU portability: http://stackoverflow.com/a/22084103/151666
rm -f "${templateDst}.bak"
done
# cat "${templateDst}"
if grep '${' ${templateDst} && [ "${ALLOW_REMAINDERS}" = "0" ]; then
if grep '${' "${templateDst}" && [ "${ALLOW_REMAINDERS}" = "0" ]; then
echo "ERROR: Unable to replace the above template vars"
exit 1
fi