cdist-backup/bin/cdist-explorer-run
Nico Schottelius e168454d1b Revert "Revert "finish generic cdist-explorer-run""
Revert the reverts - now we're in the feature branch.

This reverts commit c429177db4.
2011-02-22 23:10:47 +01:00

65 lines
2.2 KiB
Bash
Executable file

#!/bin/sh
#
# 2010-2011 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
#
# FIXME: This script is ugly, should be either seperated into smaller ones,
# but definitely be cleaned up - PROOF OF CONCEPT CODE
#
. cdist-config
if [ $# -ne 5 ]; then
__cdist_usage "<target host> <local srcdir> <local dstdir> <remote srcdir> <remote dstdir>"
fi
set -ue
export __cdist_target_host="$1"; shift
export __cdist_local_src_dir="$1"; shift
export __cdist_local_dst_dir="$1"; shift
export __cdist_remote_src_dir="$1"; shift
export __cdist_remote_dst_dir="$1"; shift
################################################################################
# New code
#
# Create remote source and destination directory
ssh "${__cdist_remote_user}@${__cdist_target_host}" \
"mkdir -p \"${__cdist_remote_src_dir}\" \
\"${__cdist_remote_dst_dir}\""
# Ensure local destination directory exists
mkdir -p "$__cdist_local_dst_dir"
# FIXME: enable -q as soon as the code is cleaned up
cd "${__cdist_local_src_dir}"
for explorer in *; do
# Copy explorers to remote source directory
scp "${explorer}" \
"${__cdist_remote_user}@${__cdist_target_host}:${__cdist_remote_src_dir}"
# Execute explorers and save results in remote destination directory
ssh "${__cdist_remote_user}@${__cdist_target_host}" \
"\"${__cdist_remote_src_dir}/$explorer\" > \
\"${__cdist_remote_dst_dir}/${explorer}\""
# Copy results back to us
scp "${__cdist_remote_user}@${__cdist_target_host}:${__cdist_remote_dst_dir}/${explorer}" \
"$__cdist_local_dst_dir/$explorer"
done