mirror of
https://github.com/kvz/bash3boilerplate.git
synced 2024-12-24 00:32:21 +00:00
f57e37eb68
templater.sh now escapes the delimiter it uses for its sed magic within the environment variable content. the associated test uses a properly cleaned up temporary file instead of explicitly rm-ing its own mess.
37 lines
1.1 KiB
Bash
37 lines
1.1 KiB
Bash
#!/usr/bin/env bash
|
|
set -o pipefail
|
|
set -o errexit
|
|
set -o nounset
|
|
# set -o xtrace
|
|
|
|
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
|
|
__base="$(basename "${__file}" .sh)"
|
|
|
|
__root="$(cd "$(dirname "$(dirname "$(dirname "${__dir}")")")" && pwd)"
|
|
|
|
__templaterTmpFile=$(mktemp "${TMPDIR:-/tmp}/${__base}.XXXXXX")
|
|
function cleanup_before_exit () { rm "${__templaterTmpFile:?}"; }
|
|
trap cleanup_before_exit EXIT
|
|
|
|
echo "--"
|
|
env TARGET_HOST="127.0.0.1" bash "${__root}/src/templater.sh" ./app.template.cfg "${__templaterTmpFile}"
|
|
cat "${__templaterTmpFile}"
|
|
|
|
echo "--"
|
|
export TARGET_HOST="127.0.0.1"
|
|
|
|
# shellcheck source=src/templater.sh
|
|
source "${__root}/src/templater.sh"
|
|
|
|
templater ./app.template.cfg "${__templaterTmpFile}"
|
|
cat "${__templaterTmpFile}"
|
|
|
|
echo "--"
|
|
env ALLOW_REMAINDERS="1" TARGET_HOST="127.0.0.1" bash "${__root}/src/templater.sh" ./break.template.cfg "${__templaterTmpFile}"
|
|
cat "${__templaterTmpFile}"
|
|
|
|
echo "--"
|
|
env TARGET_HOST="127.0.0.1" bash "${__root}/src/templater.sh" ./break.template.cfg "${__templaterTmpFile}"
|
|
cat "${__templaterTmpFile}"
|