diff --git a/bin/cdist-dir-push b/bin/cdist-dir similarity index 57% rename from bin/cdist-dir-push rename to bin/cdist-dir index 5a2a9fcf..3c8433d3 100755 --- a/bin/cdist-dir-push +++ b/bin/cdist-dir @@ -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 " " + __cdist_usage " " 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