From 4450b2f573c50d317097dd1c465cb6750c485be7 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 4 Feb 2011 14:38:17 +0100 Subject: [PATCH] continue to integrate new explorer idea Signed-off-by: Nico Schottelius --- bin/cdist-build-explorer | 39 ------------------- bin/cdist-config | 9 +++++ bin/cdist-explorer-coordinator | 5 ++- bin/cdist-explorer-run | 68 ++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 41 deletions(-) delete mode 100755 bin/cdist-build-explorer create mode 100755 bin/cdist-explorer-run diff --git a/bin/cdist-build-explorer b/bin/cdist-build-explorer deleted file mode 100755 index 48ea38c8..00000000 --- a/bin/cdist-build-explorer +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/sh -# -# 2010 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 . -# -# - -. cdist-config - -find "${CDIST_LIBDIR}" -type f -name cdist_explore\*.sh > "${CDIST_TMP}" - -# first load all functions -while read funcfull; do - cat "${funcfull}" -done < "${CDIST_TMP}" - -# then execute functions -while read funcfull; do - sh="${funcfull##*/}" - func="${sh%.sh}" - var="__$func" - - echo "$var=\"\$($func)\"" - echo "echo $var=\\\"\$$var\\\"" -done < "${CDIST_TMP}" diff --git a/bin/cdist-config b/bin/cdist-config index 1e3b2392..4a7506ab 100755 --- a/bin/cdist-config +++ b/bin/cdist-config @@ -33,6 +33,15 @@ : ${__cdist_cache_hosts:=$__cdist_cache_dir/hosts} : ${__cdist_cache_bin:=$__cdist_cache_dir/bin} +: ${__cdist_explorer_dir:=$__cdist_config/explorers} + +# Paths used on the target - must be kind of secure.... +: ${__cdist_remote_base_dir:=/var/lib/cdist} +: ${__cdist_remote_explorer_dir:=$__cdist_remote_base/explorers} +: ${__cdist_remote_cache_dir:=$__cdist_remote_base/cache} +: ${__cdist_remote_cache_explorer:=$__cdist_remote_base/cache} +: ${__cdist_remote_cache_bin:=$__cdist_remote_base/bin} + # create basedir + tempfile for direct usage # FIXME: remove on exit : ${__cdist_tmp_dir:=$(mktemp -d "/tmp/cdist.XXXXXXXXXXXX")} diff --git a/bin/cdist-explorer-coordinator b/bin/cdist-explorer-coordinator index 9d3c270a..8556dbd9 100755 --- a/bin/cdist-explorer-coordinator +++ b/bin/cdist-explorer-coordinator @@ -18,7 +18,7 @@ # along with cdist. If not, see . # # -# Coordinate run of explorers on target +# Coordinate run of explorers on target (this script runs on the target) # . cdist-config @@ -32,4 +32,5 @@ result_dir="$1"; shift cd "${explorer_dir}" for explorer in *; do - ./$explorer > "${result_dir}/${explorer}" + "./$explorer" > "${result_dir}/${explorer}" +done diff --git a/bin/cdist-explorer-run b/bin/cdist-explorer-run new file mode 100755 index 00000000..49e79de0 --- /dev/null +++ b/bin/cdist-explorer-run @@ -0,0 +1,68 @@ +#!/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 . +# +# + +. cdist-config + +set -e + +# Transfer all explorers to the target dir - must be one level above, so +# coyping it multiple times works: a -> remote:/base/ = remote:/base/a vs. +# a -> remote:/base/a = remote:/base/a/a (second copy) +scp -r "${__cdist_explorer_dir}" \ + "root@${__cdist_target_host}:${__cdist_remote_cache_dir}" + +# Transfer explorer coordinator +scp "$(which cdist-explorer-coordinator)" \ + "root@${__cdist_target_host}:${__cdist_remote_cache_bin}" + +# Execute explorer coordinator, which will save results on target +ssh root@${__cdist_target_host} "\"${__cdist_remote_cache_bin}/cdist-explorer-coordinator\" \ + \"${__cdist_remote_explorer_dir}\" \"${__cdist_remote_cache_explorer}\"" + + +# Transfer back all results +scp -r "root@${__cdist_target_host}:${__cdist_remote_dir}" + + +exit 0 + +# -------------------------------------------------------------------------------- +# old idea with shell scripts (also sexy) +# Keep until above version successfully works + + +cd "${__cdist_explorer_dir}" +ls > "${__cdist_tmp_file}" + +# first load all functions +while read funcfull; do + cat "${funcfull}" +done < "${__cdist_tmp_file}" + +# then execute functions +while read funcfull; do + sh="${funcfull##*/}" + func="${sh%.sh}" + var="__$func" + + echo "$var=\"\$($func)\"" + echo "echo $var=\\\"\$$var\\\"" +done < "${CDIST_TMP}"