finish bin/cdist-dir-push

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

View file

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# 2010-2011 Nico Schottelius (nico-cdist at schottelius.org) # 2011 Nico Schottelius (nico-cdist at schottelius.org)
# #
# This file is part of cdist. # This file is part of cdist.
# #
@ -18,64 +18,31 @@
# along with cdist. If not, see <http://www.gnu.org/licenses/>. # along with cdist. If not, see <http://www.gnu.org/licenses/>.
# #
# #
# FIXME: Replace * references: * breaks if there is no explorer # Push a directory to a target, both sides have the same name (i.e. explorers)
# or FIXME: check that there is at least one explorer?
# #
. cdist-config . cdist-config
if [ $# -lt 5 ]; then if [ $# -lt 3 ]; then
__cdist_usage "<target host> <local srcdir> <local dstdir> <remote srcdir> <remote dstdir> [explorer args]" __cdist_usage "<target host> <local src dir> <remote dst dir>"
fi fi
set -ue set -ue
__cdist_target_host="$1"; shift __cdist_target_host="$1"; shift
__cdist_local_src_dir="$1"; shift __cdist_local_src_dir="$1"; shift
__cdist_local_dst_dir="$1"; shift
__cdist_remote_src_dir="$1"; shift
__cdist_remote_dst_dir="$1"; shift __cdist_remote_dst_dir="$1"; shift
# Create remote source and destination directory # This will be the destination directory, so no subdirectories
ssh "${__cdist_remote_user}@${__cdist_target_host}" \ # of the same name are created, if the directory is already existing
"mkdir -p \"${__cdist_remote_src_dir}\" \ __cdist_remote_top_dir="${__cdist_remote_dst_dir%/*}"
\"${__cdist_remote_dst_dir}\""
# Ensure local destination directory exists # The directory name itself
mkdir -p "$__cdist_local_dst_dir" __cdist_remote_base_dir="${__cdist_remote_dst_dir##*/}"
# FIXME: enable -q as soon as the code is cleaned up # Create remote destination directory
cd "${__cdist_local_src_dir}" ssh "${__cdist_remote_user}@${__cdist_target_host}" \
"mkdir -p \"${__cdist_remote_dst_dir}\""
# Ensure there is at least one explorer # The actual transfer
num="$(ls -1 | wc -l)" scp -r "$__cdist_local_src_dir" \
if [ "$num" -lt 1 ]; then "${__cdist_remote_user}@${__cdist_target_host}:${__cdist_remote_top_dir}"
__cdist_exit_err "${__cdist_local_src_dir}: Contains no explorers"
fi
# Copy all explorers to remote source directory
scp * "${__cdist_remote_user}@${__cdist_target_host}:${__cdist_remote_src_dir}"
# Execute all explorers
for explorer in *; do
if [ -f "$explorer" ]; then
if [ ! -x "$explorer" ]; then
echo "Explorer \"$explorer\" exists, but is not executable."
continue
fi
# Execute explorers and save results in remote destination directory
ssh "${__cdist_remote_user}@${__cdist_target_host}" \
"cd \"${__cdist_remote_src_dir}\" && \"./$explorer\" > \
\"${__cdist_remote_dst_dir}/${explorer}\"" "$@"
else
if [ -e "$explorer" ]; then
echo "Explorer \"$explorer\" exists, but is not a file."
continue
fi
fi
done
# Copy results back to us
scp "${__cdist_remote_user}@${__cdist_target_host}:${__cdist_remote_dst_dir}/*" \
"$__cdist_local_dst_dir"