From 12ff8d66ec88528d2c07dd9c80a0234db10d1b41 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 25 Feb 2011 01:28:50 +0100 Subject: [PATCH] add template for cdist-remote-code-run Signed-off-by: Nico Schottelius --- bin/{cdist-exec-run => cdist-code-run} | 0 bin/cdist-remote-code-run | 74 ++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) rename bin/{cdist-exec-run => cdist-code-run} (100%) create mode 100755 bin/cdist-remote-code-run diff --git a/bin/cdist-exec-run b/bin/cdist-code-run similarity index 100% rename from bin/cdist-exec-run rename to bin/cdist-code-run diff --git a/bin/cdist-remote-code-run b/bin/cdist-remote-code-run new file mode 100755 index 00000000..7064a323 --- /dev/null +++ b/bin/cdist-remote-code-run @@ -0,0 +1,74 @@ +#!/bin/sh +# +# 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 . +# +# +# This binary is executed on the remote side to execute explorers +# +# It supports different variables names to be used, so __explorers +# and __type_explorers can be submitted :-) +# + +. cdist-config +if [ $# -ne 3 ]; then + __cdist_usage " " +fi +set -ue + +# Variable that defines the home of the explorers +__cdist_variable_name="$1"; shift + +# Find explorers here +__cdist_explorer_dir="$1"; shift + +# Write output here +__cdist_my_out_dir="$1"; shift + +# cd to this dir +__cdist_work_dir="$__cdist_remote_base_dir" + +# Setup environment +export $__cdist_variable_name="$__cdist_explorer_dir" +cd "${__cdist_work_dir}" +mkdir -p "$__cdist_my_out_dir" + +# Ensure there is at least one explorer +num="$(ls -1 "$__cdist_explorer_dir" | wc -l)" +if [ "$num" -lt 1 ]; then + __cdist_exit_err "${__cdist_explorer_dir}: Contains no explorers" +fi + +# Execute all explorers +for explorer in "$__cdist_explorer_dir/"*; do + explorer_name="${explorer##*/}" + + 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 + "$explorer" "$@" > "${__cdist_my_out_dir}/$explorer_name" + else + if [ -e "$explorer" ]; then + echo "Explorer \"$explorer\" exists, but is not a file." + continue + fi + fi +done