forked from ungleich-public/cdist
Merge pull request #771 from sideeffect42/quote-block
__block: Quote prefix/suffix
This commit is contained in:
commit
880f653ec2
1 changed files with 6 additions and 1 deletions
|
@ -18,6 +18,11 @@
|
||||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
# quote function from http://www.etalabs.net/sh_tricks.html
|
||||||
|
quote() {
|
||||||
|
printf '%s\n' "$1" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/'/"
|
||||||
|
}
|
||||||
|
|
||||||
file="$(cat "$__object/parameter/file" 2>/dev/null || echo "/$__object_id")"
|
file="$(cat "$__object/parameter/file" 2>/dev/null || echo "/$__object_id")"
|
||||||
state_should=$(cat "$__object/parameter/state")
|
state_should=$(cat "$__object/parameter/state")
|
||||||
prefix=$(cat "$__object/parameter/prefix" 2>/dev/null || echo "#cdist:__block/$__object_id")
|
prefix=$(cat "$__object/parameter/prefix" 2>/dev/null || echo "#cdist:__block/$__object_id")
|
||||||
|
@ -46,7 +51,7 @@ tmpfile=\$(mktemp ${file}.cdist.XXXXXXXXXX)
|
||||||
if [ -f "$file" ]; then
|
if [ -f "$file" ]; then
|
||||||
cp -p "$file" "\$tmpfile"
|
cp -p "$file" "\$tmpfile"
|
||||||
fi
|
fi
|
||||||
awk -v prefix="^$prefix\$" -v suffix="^$suffix\$" '
|
awk -v prefix=^$(quote "$prefix")\$ -v suffix=^$(quote "$suffix")\$ '
|
||||||
{
|
{
|
||||||
if (match(\$0,prefix)) {
|
if (match(\$0,prefix)) {
|
||||||
triggered=1
|
triggered=1
|
||||||
|
|
Loading…
Reference in a new issue