From 360a03a34940b59fdf2fa449f184f225d059a6fd Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Thu, 3 Nov 2011 17:21:14 +0100 Subject: [PATCH] add examples for __remote_{copy,exec} scripts Signed-off-by: Steven Armstrong --- other/examples/remote/README | 2 ++ other/examples/remote/chroot/copy | 28 +++++++++++++++++++++++++ other/examples/remote/chroot/exec | 35 +++++++++++++++++++++++++++++++ other/examples/remote/ssh/copy | 10 +++++++++ other/examples/remote/ssh/exec | 10 +++++++++ 5 files changed, 85 insertions(+) create mode 100644 other/examples/remote/README create mode 100755 other/examples/remote/chroot/copy create mode 100755 other/examples/remote/chroot/exec create mode 100755 other/examples/remote/ssh/copy create mode 100755 other/examples/remote/ssh/exec diff --git a/other/examples/remote/README b/other/examples/remote/README new file mode 100644 index 00000000..288fc293 --- /dev/null +++ b/other/examples/remote/README @@ -0,0 +1,2 @@ +Some examples of using alternative __remote_copy and __remote_exec prefixes. +This allows you to change how cdist interacts with the target host (or directory, or whatever :-) diff --git a/other/examples/remote/chroot/copy b/other/examples/remote/chroot/copy new file mode 100755 index 00000000..eb284ced --- /dev/null +++ b/other/examples/remote/chroot/copy @@ -0,0 +1,28 @@ +#!/bin/sh +# +# __remote_copy script to run cdist against a local chroot instead of via ssh +# to a remote target host. +# +# Usage: +# __remote_copy="/path/to/this/script /path/to/your/chroot" cdist config target-id +# + +log() { + #echo "$@" | logger -t "cdist-chroot-copy" + : +} + +chroot="$1"; shift +target_host="$__target_host" + +# replace target_host with chroot location +code="$(echo "$@" | sed "s|$target_host:|$chroot|g")" + +log "$@" +log "target_host: $target_host" +log "$code" + +# copy files into chroot +cp $code + +log "-----" diff --git a/other/examples/remote/chroot/exec b/other/examples/remote/chroot/exec new file mode 100755 index 00000000..21efe421 --- /dev/null +++ b/other/examples/remote/chroot/exec @@ -0,0 +1,35 @@ +#!/bin/sh +# +# __remote_exec script to run cdist against a local chroot instead of via ssh +# on a remote target host. +# +# Usage: +# __remote_exec="/path/to/this/script /path/to/your/chroot" cdist config target-id +# + +log() { + #echo "$@" | logger -t "cdist-chroot-exec" + : +} + +chroot="$1"; shift +target_host="$1"; shift +script=$(mktemp "${chroot}/tmp/chroot-${0##*/}.XXXXXXXXXX") +trap cleanup INT TERM EXIT +cleanup() { + [ $__cdist_debug ] || rm "$script" +} + +log "$script" +log "$@" +echo "#!/bin/sh -l" > "$script" +echo "$@" >> "$script" +chmod +x "$script" + +relative_script="${script#$chroot}" +log "relative_script: $relative_script" + +# run in chroot +chroot "$chroot" "$relative_script" + +log "-----" diff --git a/other/examples/remote/ssh/copy b/other/examples/remote/ssh/copy new file mode 100755 index 00000000..76c0b2c8 --- /dev/null +++ b/other/examples/remote/ssh/copy @@ -0,0 +1,10 @@ +#!/bin/sh +# +# same as cdist default +# +# Usage: +# __remote_copy="/path/to/this/script" cdist config target_host +# + +#echo "$@" | logger -t "cdist-ssh-copy" +scp -o User=root -q $@ diff --git a/other/examples/remote/ssh/exec b/other/examples/remote/ssh/exec new file mode 100755 index 00000000..63994973 --- /dev/null +++ b/other/examples/remote/ssh/exec @@ -0,0 +1,10 @@ +#!/bin/sh +# +# same as cdist default +# +# Usage: +# __remote_exec="/path/to/this/script" cdist config target_host +# + +#echo "$@" | logger -t "cdist-ssh-exec" +ssh -o User=root -q $@