superseed cdist-dir-push with cdist-dir

Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
Nico Schottelius 2011-02-23 15:50:33 +01:00
parent d8cb6d58f7
commit 5d881f226a

View file

@ -19,30 +19,36 @@
#
#
# Push a directory to a target, both sides have the same name (i.e. explorers)
# or
# Pull a directory from a target, both sides have the same name (i.e. explorers)
#
. cdist-config
if [ $# -lt 3 ]; then
__cdist_usage "<target host> <local src dir> <remote dst dir>"
__cdist_usage "<target host> <push|pull> <src dir> <dst dir>"
fi
set -ue
__cdist_target_host="$1"; shift
__cdist_local_src_dir="$1"; shift
__cdist_remote_dst_dir="$1"; shift
__cdist_action="$1"; shift
__cdist_src_dir="$1"; shift
__cdist_dst_dir="$1"; shift
# This will be the destination directory, so no subdirectories
# of the same name are created, if the directory is already existing
__cdist_remote_top_dir="${__cdist_remote_dst_dir%/*}"
__cdist_top_dir="${__cdist_dst_dir%/*}"
# The directory name itself
__cdist_remote_base_dir="${__cdist_remote_dst_dir##*/}"
# Create remote destination directory
ssh "${__cdist_remote_user}@${__cdist_target_host}" \
"mkdir -p \"${__cdist_remote_dst_dir}\""
# The actual transfer
scp -r "$__cdist_local_src_dir" \
"${__cdist_remote_user}@${__cdist_target_host}:${__cdist_remote_top_dir}"
if [ "$__cdist_action" = "push" ]; then
ssh "${__cdist_remote_user}@${__cdist_target_host}" \
"mkdir -p \"${__cdist_dst_dir}\""
scp -r "$__cdist_src_dir" \
"${__cdist_remote_user}@${__cdist_target_host}:${__cdist_top_dir}"
elif [ "$__cdist_action" = "pull" ]; then
mkdir -p "${__cdist_dst_dir}"
scp -r "${__cdist_remote_user}@${__cdist_target_host}:${__cdist_src_dir}" \
"${__cdist_top_dir}"
else
__cdist_exit_err "Unknown action $__cdist_action"
fi