allow __file to read source file from stdin

Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
Steven Armstrong 2012-06-04 14:17:42 +02:00
parent 06649d3478
commit 7ae1a2bc52
2 changed files with 10 additions and 0 deletions

View file

@ -30,6 +30,9 @@ exists="$(cat "$__object/explorer/exists")"
if [ "$state_should" = "present" ]; then if [ "$state_should" = "present" ]; then
if [ -f "$__object/parameter/source" ]; then if [ -f "$__object/parameter/source" ]; then
source="$(cat "$__object/parameter/source")" source="$(cat "$__object/parameter/source")"
if [ "$source" = "-" ]; then
source="$__object/stdin"
fi
if [ -f "$source" ]; then if [ -f "$source" ]; then
local_cksum="$(cksum < "$source")" local_cksum="$(cksum < "$source")"

View file

@ -39,6 +39,7 @@ owner::
source:: source::
If supplied, copy this file from the host running cdist to the target. If supplied, copy this file from the host running cdist to the target.
If not supplied, an empty file or directory will be created. If not supplied, an empty file or directory will be created.
If source is '-' (dash), take what was written to stdin as the file content.
EXAMPLES EXAMPLES
@ -64,6 +65,12 @@ __file /etc/shadow --source "$__type/files/shadow" \
__file /home/frodo/.bashrc --source "/etc/skel/.bashrc" \ __file /home/frodo/.bashrc --source "/etc/skel/.bashrc" \
--state exists \ --state exists \
--owner frodo --mode 0600 --owner frodo --mode 0600
# Take file content from stdin
__file /tmp/whatever --owner root --group root --mode 644 --source - << DONE
Here goes the content for /tmp/whatever
DONE
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------