Skip to content

Instantly share code, notes, and snippets.

@adrienthebo
Created January 24, 2012 00:49
Show Gist options
  • Save adrienthebo/1667034 to your computer and use it in GitHub Desktop.
Save adrienthebo/1667034 to your computer and use it in GitHub Desktop.
Attempts to add braces around quoted interpolated strings in puppet.
#!/bin/sh
#
# Attempts to add braces around quoted interpolated strings in puppet.
#
# Caveats
#
# This is a lot of sed and duct tape. It is not very smart. It's probably the
# most horrible regex I've ever written.
# I'm sorry.
if [[ $# == 0 ]]; then
echo "usage: $0 manifest.pp [manifest.pp ...]"
exit 1
fi
trap 'exit 1' SIGINT SIGTERM
for manifest in $@; do
sed -i.bak -e \
":BEGIN
/\"[^\"']*[^\\]\$[[:alnum:]_:].*\"/ \
s/\(\"[^\"]*\)\$\([[:alnum:]_:][[:alnum:]_:]*\)\([^\"]*\"\)/\1$\{\2\}\3/
t BEGIN" $manifest
diff "${manifest}.bak" $manifest 2>/dev/null 1>/dev/null
if [[ $? == 1 ]]; then
echo "Patched manifest ${manifest}"
diff -U 1 "${manifest}.bak" $manifest
echo "Validating manifest syntax"
puppet parser validate $manifest
else
rm ${manifest}.bak
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment