From 630fced69db6c40ced8ab6717517fcf9284d21bf Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 14 Jun 2011 00:12:15 +0200 Subject: [PATCH 001/110] begin experiement: move cdist-dir to core lib Signed-off-by: Nico Schottelius --- bin/cdist-dir => core/__cdist_dir | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename bin/cdist-dir => core/__cdist_dir (100%) diff --git a/bin/cdist-dir b/core/__cdist_dir similarity index 100% rename from bin/cdist-dir rename to core/__cdist_dir From abe6e695bc76cb4c10c0fb309082fc23884afe03 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 14 Jun 2011 00:17:31 +0200 Subject: [PATCH 002/110] load __cdist_dir from core Signed-off-by: Nico Schottelius --- bin/cdist-config | 15 +++++++++++++++ core/__cdist_dir | 46 ++++++++++++++++++++++++---------------------- 2 files changed, 39 insertions(+), 22 deletions(-) diff --git a/bin/cdist-config b/bin/cdist-config index f7fb5ac0..de21d717 100644 --- a/bin/cdist-config +++ b/bin/cdist-config @@ -111,6 +111,7 @@ __cdist_tmp_file=$(mktemp "$__cdist_tmp_dir/cdist.XXXXXXXXXXXX") : ${__cdist_local_base_cache_dir:=$__cdist_abs_mydir/../$__cdist_name_cache} : ${__cdist_conf_dir:="$(cd "$__cdist_abs_mydir/../conf" && pwd -P)"} +: ${__cdist_core_dir:="$(cd "$__cdist_abs_mydir/../core" && pwd -P)"} : ${__cdist_explorer_dir:=$__cdist_conf_dir/$__cdist_name_explorer} : ${__cdist_manifest_dir:=$__cdist_conf_dir/$__cdist_name_manifest} @@ -149,6 +150,15 @@ __cdist_tmp_file=$(mktemp "$__cdist_tmp_dir/cdist.XXXXXXXXXXXX") ################################################################################ # Internal functions # + +# *NEW* Load functions from library +for __cdist_lib in $__cdist_core_dir/*; do + echo Loading $__cdist_lib ... + . "$__cdist_lib" +done + +exit 0 + __cdist_echo() { __cdist_echo_type="$1"; shift @@ -208,6 +218,11 @@ __cdist_usage() __cdist_exit_err "$__cdist_myname: $@" } +___cdist_lib_path() +{ + echo $_ +} + __cdist_init_deploy() { __cdist_echo info "Creating clean directory structure " diff --git a/core/__cdist_dir b/core/__cdist_dir index 0d30e14a..7799d03e 100755 --- a/core/__cdist_dir +++ b/core/__cdist_dir @@ -24,28 +24,30 @@ # -. cdist-config -[ $# -eq 4 ] || __cdist_usage " " -set -ue +__cdist_dir() +{ + [ $# -eq 4 ] || __cdist_usage " " + set -ue -__cdist_action="$1"; shift -__cdist_target_host="$1"; shift -__cdist_src_dir="$1"; shift -__cdist_dst_dir="$1"; shift + __cdist_action="$1"; shift + __cdist_target_host="$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_top_dir="${__cdist_dst_dir%/*}" + # This will be the destination directory, so no subdirectories + # of the same name are created, if the directory is already existing + __cdist_top_dir="${__cdist_dst_dir%/*}" -if [ "$__cdist_action" = "push" ]; then - ssh "${__cdist_remote_user}@${__cdist_target_host}" \ - "mkdir -p \"${__cdist_dst_dir}\"" - scp -qr "$__cdist_src_dir" \ - "${__cdist_remote_user}@${__cdist_target_host}:${__cdist_top_dir}" -elif [ "$__cdist_action" = "pull" ]; then - mkdir -p "${__cdist_dst_dir}" - scp -qr "${__cdist_remote_user}@${__cdist_target_host}:${__cdist_src_dir}" \ - "${__cdist_top_dir}" -else - __cdist_exit_err "Unknown action $__cdist_action" -fi + if [ "$__cdist_action" = "push" ]; then + ssh "${__cdist_remote_user}@${__cdist_target_host}" \ + "mkdir -p \"${__cdist_dst_dir}\"" + scp -qr "$__cdist_src_dir" \ + "${__cdist_remote_user}@${__cdist_target_host}:${__cdist_top_dir}" + elif [ "$__cdist_action" = "pull" ]; then + mkdir -p "${__cdist_dst_dir}" + scp -qr "${__cdist_remote_user}@${__cdist_target_host}:${__cdist_src_dir}" \ + "${__cdist_top_dir}" + else + __cdist_exit_err "Unknown action $__cdist_action" + fi +} From e6d2a301c9bd35ae20725d721a3080e47ba8df79 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 14 Jun 2011 00:19:57 +0200 Subject: [PATCH 003/110] replace usage of cdist-dir and use new syntax Signed-off-by: Nico Schottelius --- bin/cdist-deploy-to | 3 +-- bin/cdist-explorer-run-global | 6 ++---- bin/cdist-object-explorer-run | 7 +++---- bin/cdist-object-push | 3 +-- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/bin/cdist-deploy-to b/bin/cdist-deploy-to index bf5614bc..b28afbf2 100755 --- a/bin/cdist-deploy-to +++ b/bin/cdist-deploy-to @@ -48,8 +48,7 @@ __cdist_init_deploy "$__cdist_target_host" # Transfer cdist executables __cdist_echo info "Transferring cdist binaries to the target host " -cdist-dir push "$__cdist_target_host" \ - "${__cdist_abs_mydir}" "${__cdist_remote_bin_dir}" +__cdist_dir push "${__cdist_abs_mydir}" "${__cdist_remote_bin_dir}" cdist-explorer-run-global "$__cdist_target_host" cdist-manifest-run-init "$__cdist_target_host" cdist-object-all "$__cdist_target_host" cdist-object-prepare diff --git a/bin/cdist-explorer-run-global b/bin/cdist-explorer-run-global index b0c024f2..09b088f5 100755 --- a/bin/cdist-explorer-run-global +++ b/bin/cdist-explorer-run-global @@ -30,8 +30,7 @@ __cdist_target_host="$1"; shift __cdist_echo info "Running global explorers " # copy the explorers -cdist-dir push "$__cdist_target_host" \ - "${__cdist_explorer_dir}" "${__cdist_remote_explorer_dir}" +__cdist_dir push "${__cdist_explorer_dir}" "${__cdist_remote_explorer_dir}" # run the initial explorers remotely cdist-run-remote "${__cdist_target_host}" cdist-remote-explorer-run \ @@ -39,5 +38,4 @@ cdist-run-remote "${__cdist_target_host}" cdist-remote-explorer-run \ "$__cdist_remote_out_explorer_dir" # retrieve the results -cdist-dir pull "$__cdist_target_host" \ - "${__cdist_remote_out_explorer_dir}" "${__cdist_out_explorer_dir}" +__cdist_dir pull "${__cdist_remote_out_explorer_dir}" "${__cdist_out_explorer_dir}" diff --git a/bin/cdist-object-explorer-run b/bin/cdist-object-explorer-run index b65c5cc1..8bdf50ce 100755 --- a/bin/cdist-object-explorer-run +++ b/bin/cdist-object-explorer-run @@ -40,13 +40,13 @@ if [ "$__cdist_has_explorer" ]; then src_dir="$(__cdist_type_explorer_dir "$__cdist_type")" dst_dir="$(__cdist_remote_type_explorer_dir "$__cdist_type")" __cdist_echo info "Transfering explorers for $__cdist_type " - cdist-dir push "$__cdist_target_host" "$src_dir" "$dst_dir" + __cdist_dir push "$src_dir" "$dst_dir" __cdist_type_explorer_pushed_add "$__cdist_type" fi __cdist_echo info "Running explorers" # Copy object parameters - cdist-dir push "$__cdist_target_host" \ + __cdist_dir push \ "$(__cdist_object_parameter_dir "$__cdist_object_self")" \ "$(__cdist_remote_object_parameter_dir "$__cdist_object_self")" @@ -61,7 +61,6 @@ if [ "$__cdist_has_explorer" ]; then "$(__cdist_remote_object_type_explorer_dir "$__cdist_object_self")" # Copy back results - cdist-dir pull "$__cdist_target_host" \ - "$(__cdist_remote_object_type_explorer_dir "$__cdist_object_self")" \ + __cdist_dir pull "$(__cdist_remote_object_type_explorer_dir "$__cdist_object_self")" \ "$(__cdist_object_type_explorer_dir "$__cdist_object_self")" fi diff --git a/bin/cdist-object-push b/bin/cdist-object-push index 62b00cb2..8c2c935c 100755 --- a/bin/cdist-object-push +++ b/bin/cdist-object-push @@ -30,6 +30,5 @@ __cdist_target_host="$1"; shift __cdist_object_self="$1"; shift __cdist_echo info "Transferring object" -cdist-dir push "$__cdist_target_host" \ - "$(__cdist_object_dir "$__cdist_object_self")" \ +__cdist_dir push "$(__cdist_object_dir "$__cdist_object_self")" \ "$(__cdist_remote_object_dir "$__cdist_object_self")" From 7fbc4b8b77238fd17f46abc477f2ae6b25ea9b16 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 14 Jun 2011 00:20:51 +0200 Subject: [PATCH 004/110] introduce first (and only?) global variable __cdist_target_host Signed-off-by: Nico Schottelius --- doc/dev/logs/2011-06-14.library_for_user | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/dev/logs/2011-06-14.library_for_user b/doc/dev/logs/2011-06-14.library_for_user index 325150e2..5c0eb6f0 100644 --- a/doc/dev/logs/2011-06-14.library_for_user +++ b/doc/dev/logs/2011-06-14.library_for_user @@ -17,3 +17,6 @@ run_code_from_user() load_lib . file_from_user } + +Introduce global variables: + __cdist_target_host From 6a500d55702c7b462c272211742af1dfa6218b83 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 14 Jun 2011 00:21:15 +0200 Subject: [PATCH 005/110] and run again Signed-off-by: Nico Schottelius --- bin/cdist-config | 2 -- 1 file changed, 2 deletions(-) diff --git a/bin/cdist-config b/bin/cdist-config index de21d717..13d2c0a4 100644 --- a/bin/cdist-config +++ b/bin/cdist-config @@ -157,8 +157,6 @@ for __cdist_lib in $__cdist_core_dir/*; do . "$__cdist_lib" done -exit 0 - __cdist_echo() { __cdist_echo_type="$1"; shift From cf88f9cacb51a89748d556994c441882978bd276 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 14 Jun 2011 00:28:08 +0200 Subject: [PATCH 006/110] finished migration of cdist-dir to __cdist_dir Signed-off-by: Nico Schottelius --- bin/cdist-config | 4 +++- bin/cdist-deploy-to | 7 ++++++- core/__cdist_dir | 30 ++++++++++++++---------------- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/bin/cdist-config b/bin/cdist-config index 13d2c0a4..942b4ea7 100644 --- a/bin/cdist-config +++ b/bin/cdist-config @@ -44,6 +44,7 @@ __cdist_abs_myname="$__cdist_abs_mydir/$__cdist_myname" : ${__cdist_name_cache:=cache} : ${__cdist_name_code:=code} : ${__cdist_name_conf_dir:=conf} +: ${__cdist_name_core_dir:=core} : ${__cdist_name_dot_cdist:=.cdist} : ${__cdist_name_explorer:=explorer} : ${__cdist_name_gencode:=gencode} @@ -111,7 +112,7 @@ __cdist_tmp_file=$(mktemp "$__cdist_tmp_dir/cdist.XXXXXXXXXXXX") : ${__cdist_local_base_cache_dir:=$__cdist_abs_mydir/../$__cdist_name_cache} : ${__cdist_conf_dir:="$(cd "$__cdist_abs_mydir/../conf" && pwd -P)"} -: ${__cdist_core_dir:="$(cd "$__cdist_abs_mydir/../core" && pwd -P)"} +: ${__cdist_core_dir:="$(cd "$__cdist_abs_mydir/../$__cdist_name_core_dir" && pwd -P)"} : ${__cdist_explorer_dir:=$__cdist_conf_dir/$__cdist_name_explorer} : ${__cdist_manifest_dir:=$__cdist_conf_dir/$__cdist_name_manifest} @@ -135,6 +136,7 @@ __cdist_tmp_file=$(mktemp "$__cdist_tmp_dir/cdist.XXXXXXXXXXXX") : ${__cdist_remote_base_dir:=/var/lib/cdist} : ${__cdist_remote_bin_dir:=$__cdist_remote_base_dir/$__cdist_name_bin} : ${__cdist_remote_conf_dir:=$__cdist_remote_base_dir/$__cdist_name_conf_dir} +: ${__cdist_remote_core_dir:=$__cdist_remote_base_dir/$__cdist_name_core_dir} : ${__cdist_remote_explorer_dir:=$__cdist_remote_conf_dir/$__cdist_name_explorer} : ${__cdist_remote_type_dir:=$__cdist_remote_conf_dir/$__cdist_name_type} diff --git a/bin/cdist-deploy-to b/bin/cdist-deploy-to index b28afbf2..d94cf460 100755 --- a/bin/cdist-deploy-to +++ b/bin/cdist-deploy-to @@ -37,6 +37,9 @@ export $__cdist_name_var_target_user="$__cdist_remote_user" # Export variables for core, which others do not reset export __cdist_local_base_dir +# Load library always from the checkout +export __cdist_core_dir + __cdist_echo info "cdist $__cdist_version: Configuring $__cdist_target_host " ################################################################################ @@ -47,8 +50,10 @@ __cdist_echo info "cdist $__cdist_version: Configuring $__cdist_target_host " __cdist_init_deploy "$__cdist_target_host" # Transfer cdist executables -__cdist_echo info "Transferring cdist binaries to the target host " +__cdist_echo info "Transferring cdist binaries/functions to the target host " __cdist_dir push "${__cdist_abs_mydir}" "${__cdist_remote_bin_dir}" +__cdist_dir push "${__cdist_core_dir}" "${__cdist_remote_core_dir}" + cdist-explorer-run-global "$__cdist_target_host" cdist-manifest-run-init "$__cdist_target_host" cdist-object-all "$__cdist_target_host" cdist-object-prepare diff --git a/core/__cdist_dir b/core/__cdist_dir index 7799d03e..2f08a95c 100755 --- a/core/__cdist_dir +++ b/core/__cdist_dir @@ -26,28 +26,26 @@ __cdist_dir() { - [ $# -eq 4 ] || __cdist_usage " " - set -ue + [ $# -eq 3 ] || __cdist_usage " " - __cdist_action="$1"; shift - __cdist_target_host="$1"; shift - __cdist_src_dir="$1"; shift - __cdist_dst_dir="$1"; shift + __cdist_dir_action="$1"; shift + __cdist_dir_src="$1"; shift + __cdist_dir_dst="$1"; shift # This will be the destination directory, so no subdirectories # of the same name are created, if the directory is already existing - __cdist_top_dir="${__cdist_dst_dir%/*}" + __cdist_dir_top="${__cdist_dir_dst%/*}" - if [ "$__cdist_action" = "push" ]; then + if [ "$__cdist_dir_action" = "push" ]; then ssh "${__cdist_remote_user}@${__cdist_target_host}" \ - "mkdir -p \"${__cdist_dst_dir}\"" - scp -qr "$__cdist_src_dir" \ - "${__cdist_remote_user}@${__cdist_target_host}:${__cdist_top_dir}" - elif [ "$__cdist_action" = "pull" ]; then - mkdir -p "${__cdist_dst_dir}" - scp -qr "${__cdist_remote_user}@${__cdist_target_host}:${__cdist_src_dir}" \ - "${__cdist_top_dir}" + "mkdir -p \"${__cdist_dir_dst}\"" + scp -qr "$__cdist_dir_src" \ + "${__cdist_remote_user}@${__cdist_target_host}:${__cdist_dir_top}" + elif [ "$__cdist_dir_action" = "pull" ]; then + mkdir -p "${__cdist_dir_dst}" + scp -qr "${__cdist_remote_user}@${__cdist_target_host}:${__cdist_dir_src}" \ + "${__cdist_dir_top}" else - __cdist_exit_err "Unknown action $__cdist_action" + __cdist_exit_err "Unknown action $__cdist_dir_action" fi } From 0603322bbd7f78de715f55337ca8a07e4e7451be Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 14 Jun 2011 00:30:22 +0200 Subject: [PATCH 007/110] begin to make cdist-object-gencode-run a function Signed-off-by: Nico Schottelius --- bin/cdist-object-gencode-run => core/__cdist_object_gencode_run | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename bin/cdist-object-gencode-run => core/__cdist_object_gencode_run (100%) diff --git a/bin/cdist-object-gencode-run b/core/__cdist_object_gencode_run similarity index 100% rename from bin/cdist-object-gencode-run rename to core/__cdist_object_gencode_run From 152cc930e1ba3eab0b634beacdb37230cbd9124d Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 14 Jun 2011 00:41:52 +0200 Subject: [PATCH 008/110] also migrate cdist-object-gencode Signed-off-by: Nico Schottelius --- bin/cdist-config | 2 +- bin/cdist-object-gencode | 62 ------------------------------ bin/cdist-object-run | 2 +- core/__cdist_object_gencode | 67 +++++++++++++++++++++++++++++++++ core/__cdist_object_gencode_run | 20 +++++----- 5 files changed, 78 insertions(+), 75 deletions(-) delete mode 100755 bin/cdist-object-gencode create mode 100755 core/__cdist_object_gencode diff --git a/bin/cdist-config b/bin/cdist-config index 942b4ea7..b120392e 100644 --- a/bin/cdist-config +++ b/bin/cdist-config @@ -82,7 +82,7 @@ __cdist_abs_myname="$__cdist_abs_mydir/$__cdist_myname" ################################################################################ -# Exported variable names (usable for non core +# Exported variable names (usable for non core) # : ${__cdist_name_var_explorer:=__$__cdist_name_explorer} : ${__cdist_name_var_type_explorer:=__$__cdist_name_type_explorer} diff --git a/bin/cdist-object-gencode b/bin/cdist-object-gencode deleted file mode 100755 index e21568a3..00000000 --- a/bin/cdist-object-gencode +++ /dev/null @@ -1,62 +0,0 @@ -#!/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 . -# -# -# Generate code from one object (object must be relative path!) -# WARNING: OUTPUT ON STDOUT, ERRORS NEED TO BE ON STDERR! -# - -. cdist-config -[ $# -eq 3 ] || __cdist_usage "" "" "" -set -eu - -__cdist_target_host="$1"; shift -__cdist_object_self="$1"; shift -__cdist_gencode_type="$1"; shift - -__cdist_type="$(__cdist_type_from_object "$__cdist_object_self")" -__cdist_type_gencode="$(__cdist_type_gencode "$__cdist_type" "$__cdist_gencode_type")" -__cdist_code_output="$(__cdist_object_code "$__cdist_object_self" "$__cdist_gencode_type")" - -# export variables for the gencode script -export __object_id="$(__cdist_object_id_from_object "$__cdist_object_self")" -export __object="$(__cdist_object_dir "$__cdist_object_self")" -export __global="$__cdist_out_dir" - -if [ -x "$__cdist_type_gencode" ]; then - __cdist_exec_fail_on_error "$__cdist_type_gencode" > "$__cdist_tmp_file" -else - if [ -e "$__cdist_type_gencode" ]; then - __cdist_exit_err "$__cdist_type_gencode exists, but is not executable" - fi - - # Ensure it's empty, if there is no gencode - : > "$__cdist_tmp_file" -fi - -# Only create code, if gencode created output -if [ "$(wc -l < "$__cdist_tmp_file")" -gt 0 ]; then - cat - "$__cdist_tmp_file" << eof > "$__cdist_code_output" -# -# The following code was generated by $__cdist_type_gencode -# - -eof - chmod u+x "${__cdist_code_output}" -fi diff --git a/bin/cdist-object-run b/bin/cdist-object-run index 4f40e7c1..f96462d7 100755 --- a/bin/cdist-object-run +++ b/bin/cdist-object-run @@ -56,7 +56,7 @@ if [ ! -f "$__cdist_object_finished" ]; then done fi - cdist-object-gencode-run "$__cdist_target_host" "$__cdist_object_self" + __cdist_object_gencode_run "$__cdist_object_self" cdist-object-push "$__cdist_target_host" "$__cdist_object_self" cdist-object-code-run "$__cdist_target_host" "$__cdist_object_self" diff --git a/core/__cdist_object_gencode b/core/__cdist_object_gencode new file mode 100755 index 00000000..585c9d9d --- /dev/null +++ b/core/__cdist_object_gencode @@ -0,0 +1,67 @@ +#!/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 . +# +# +# Generate code from one object (object must be relative path!) +# WARNING: OUTPUT ON STDOUT, ERRORS NEED TO BE ON STDERR! +# + +# FIXME: check variable names: +# either prefix or use global or use functions directly +# functions looks good, they are cheap anyway! + +__cdist_object_gencode() +{ + __cdist_myname="foo" + [ $# -eq 2 ] || __cdist_usage "" "" + + __cdist_object_self="$1"; shift + __cdist_gencode_type="$1"; shift + + __cdist_type="$(__cdist_type_from_object "$__cdist_object_self")" + __cdist_type_gencode="$(__cdist_type_gencode "$__cdist_type" "$__cdist_gencode_type")" + __cdist_code_output="$(__cdist_object_code "$__cdist_object_self" "$__cdist_gencode_type")" + + # export variables for the gencode script + export __object_id="$(__cdist_object_id_from_object "$__cdist_object_self")" + export __object="$(__cdist_object_dir "$__cdist_object_self")" + export __global="$__cdist_out_dir" + + if [ -x "$__cdist_type_gencode" ]; then + __cdist_exec_fail_on_error "$__cdist_type_gencode" > "$__cdist_tmp_file" + else + if [ -e "$__cdist_type_gencode" ]; then + __cdist_exit_err "$__cdist_type_gencode exists, but is not executable" + fi + + # Ensure it's empty, if there is no gencode + : > "$__cdist_tmp_file" + fi + + # Only create code, if gencode created output + if [ "$(wc -l < "$__cdist_tmp_file")" -gt 0 ]; then + cat - "$__cdist_tmp_file" << eof > "$__cdist_code_output" +# +# The following code was generated by $__cdist_type_gencode +# + +eof + chmod u+x "${__cdist_code_output}" + fi +} diff --git a/core/__cdist_object_gencode_run b/core/__cdist_object_gencode_run index 254ac1e4..308f5f33 100755 --- a/core/__cdist_object_gencode_run +++ b/core/__cdist_object_gencode_run @@ -22,17 +22,15 @@ # For the given object create the code to be executed on the target. # -. cdist-config -[ $# -eq 2 ] || __cdist_usage " " -set -eu +__cdist_object_gencode_run() +{ + __cdist_object_gencode_run_object="$1"; shift -__cdist_target_host="$1"; shift -__cdist_object_self="$1"; shift + __cdist_echo info "Generating local code " + __cdist_object_gencode "$__cdist_object_gencode_run_object" \ + "${__cdist_name_gencode_local}" -__cdist_echo info "Generating local code " -cdist-object-gencode "$__cdist_target_host" "$__cdist_object_self" \ - "${__cdist_name_gencode_local}" - -__cdist_echo info "Generating remote code " -cdist-object-gencode "$__cdist_target_host" "$__cdist_object_self" \ + __cdist_echo info "Generating remote code " + __cdist_object_gencode "$__cdist_object_gencode_run_object" \ "${__cdist_name_gencode_remote}" +} From 580b5da688cfcc21bc25ac3285552e8dae7b9a04 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 14 Jun 2011 00:47:24 +0200 Subject: [PATCH 009/110] remove obsolete cdist-object-push Signed-off-by: Nico Schottelius --- bin/cdist-object-push | 34 ---------------------------------- bin/cdist-object-run | 3 ++- 2 files changed, 2 insertions(+), 35 deletions(-) delete mode 100755 bin/cdist-object-push diff --git a/bin/cdist-object-push b/bin/cdist-object-push deleted file mode 100755 index 8c2c935c..00000000 --- a/bin/cdist-object-push +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/sh -# -# 2010 Nico Schottelius (nico-cdist at schottelius.org) -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) -# -# 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 . -# -# -# Transfer the given object to the target host. -# - -. cdist-config -[ $# -eq 2 ] || __cdist_usage " " -set -eu - -__cdist_target_host="$1"; shift -__cdist_object_self="$1"; shift - -__cdist_echo info "Transferring object" -__cdist_dir push "$(__cdist_object_dir "$__cdist_object_self")" \ - "$(__cdist_remote_object_dir "$__cdist_object_self")" diff --git a/bin/cdist-object-run b/bin/cdist-object-run index f96462d7..012be584 100755 --- a/bin/cdist-object-run +++ b/bin/cdist-object-run @@ -57,7 +57,8 @@ if [ ! -f "$__cdist_object_finished" ]; then fi __cdist_object_gencode_run "$__cdist_object_self" - cdist-object-push "$__cdist_target_host" "$__cdist_object_self" + __cdist_dir push "$(__cdist_object_dir "$__cdist_object_self")" \ + "$(__cdist_remote_object_dir "$__cdist_object_self")" cdist-object-code-run "$__cdist_target_host" "$__cdist_object_self" # Mark this object as done From 9e246b18ed1e5d9270047ae6210200a1b8f8003b Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 14 Jun 2011 00:48:07 +0200 Subject: [PATCH 010/110] -debug message for library loading Signed-off-by: Nico Schottelius --- bin/cdist-config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/cdist-config b/bin/cdist-config index b120392e..fb5b4be9 100644 --- a/bin/cdist-config +++ b/bin/cdist-config @@ -155,7 +155,7 @@ __cdist_tmp_file=$(mktemp "$__cdist_tmp_dir/cdist.XXXXXXXXXXXX") # *NEW* Load functions from library for __cdist_lib in $__cdist_core_dir/*; do - echo Loading $__cdist_lib ... + # echo Loading $__cdist_lib ... . "$__cdist_lib" done From 27a810705e3863c18c355b1bbf76baed1a8814fe Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 14 Jun 2011 00:54:52 +0200 Subject: [PATCH 011/110] cdist-object-code-run -> ../core/__cdist_object_code_run Signed-off-by: Nico Schottelius --- bin/cdist-object-run | 2 +- .../__cdist_object_code_run | 21 +++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) rename bin/cdist-object-code-run => core/__cdist_object_code_run (67%) diff --git a/bin/cdist-object-run b/bin/cdist-object-run index 012be584..737c962b 100755 --- a/bin/cdist-object-run +++ b/bin/cdist-object-run @@ -59,7 +59,7 @@ if [ ! -f "$__cdist_object_finished" ]; then __cdist_object_gencode_run "$__cdist_object_self" __cdist_dir push "$(__cdist_object_dir "$__cdist_object_self")" \ "$(__cdist_remote_object_dir "$__cdist_object_self")" - cdist-object-code-run "$__cdist_target_host" "$__cdist_object_self" + __cdist_object_code_run "$__cdist_object_self" # Mark this object as done touch "$__cdist_object_finished" diff --git a/bin/cdist-object-code-run b/core/__cdist_object_code_run similarity index 67% rename from bin/cdist-object-code-run rename to core/__cdist_object_code_run index fa63aaba..cecb6659 100755 --- a/bin/cdist-object-code-run +++ b/core/__cdist_object_code_run @@ -22,17 +22,16 @@ # Exec the code for the given object locally and remote # -. cdist-config -[ $# -eq 2 ] || __cdist_usage " " -set -e +__cdist_object_code_run() +{ -__cdist_target_host="$1"; shift -__cdist_object="$1"; shift + __cdist_object_code_run_object="$1"; shift -# Code local -export __cdist_out_object_dir="$__cdist_out_object_dir" -cdist-code-run "$__cdist_object" "${__cdist_name_gencode_local}" + # Code local + export __cdist_out_object_dir="$__cdist_out_object_dir" + cdist-code-run "$__cdist_object_code_run_object" "${__cdist_name_gencode_local}" -# Code remote -cdist-run-remote "$__cdist_target_host" \ - "cdist-code-run" "$__cdist_object" "${__cdist_name_gencode_remote}" + # Code remote + cdist-run-remote "$__cdist_target_host" \ + "cdist-code-run" "$__cdist_object_code_run_object" "${__cdist_name_gencode_remote}" +} From ef2336cb1e6c64ce641b1f8d5a5bbfc44b42e2a8 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 14 Jun 2011 01:00:55 +0200 Subject: [PATCH 012/110] cdist-object-run -> ../core/__cdist_object_run Signed-off-by: Nico Schottelius --- bin/cdist-deploy-to | 2 +- bin/cdist-object-run | 66 ----------------------------------------- core/__cdist_object_run | 66 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 67 deletions(-) delete mode 100755 bin/cdist-object-run create mode 100755 core/__cdist_object_run diff --git a/bin/cdist-deploy-to b/bin/cdist-deploy-to index d94cf460..c512bd88 100755 --- a/bin/cdist-deploy-to +++ b/bin/cdist-deploy-to @@ -57,7 +57,7 @@ __cdist_dir push "${__cdist_core_dir}" "${__cdist_remote_core_dir}" cdist-explorer-run-global "$__cdist_target_host" cdist-manifest-run-init "$__cdist_target_host" cdist-object-all "$__cdist_target_host" cdist-object-prepare -cdist-object-all "$__cdist_target_host" cdist-object-run +cdist-object-all "$__cdist_target_host" __cdist_object_run cdist-cache "$__cdist_target_host" __cdist_echo info "cdist $__cdist_version: Successfully finished run" diff --git a/bin/cdist-object-run b/bin/cdist-object-run deleted file mode 100755 index 737c962b..00000000 --- a/bin/cdist-object-run +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/sh -# -# 2011 Nico Schottelius (nico-cdist at schottelius.org) -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) -# -# 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 . -# -# -# For the given object: -# - run type explorers -# - run type manifest -# - generate code -# - copy object to target -# - execute code on target -# - -. cdist-config -[ $# -eq 2 ] || __cdist_usage " " -set -eu - -__cdist_target_host="$1"; shift -__cdist_object_self="$1"; shift -__cdist_object_dir="$(__cdist_object_dir "$__cdist_object_self")" -[ -d "$__cdist_object_dir" ] || __cdist_exit_err "Object undefined" - -# Export to non-core for use in manifest and gencode scripts -export $__cdist_name_var_self=$__cdist_object_self - -__cdist_object_finished="$(__cdist_object_finished "$__cdist_object_self")" -if [ ! -f "$__cdist_object_finished" ]; then - # Resolve dependencies, if any - __cdist_object_require="$(__cdist_object_require "$__cdist_object_self")" - if [ -f "$__cdist_object_require" ]; then - # NEED TO CREATE ARRAY, SSH DESTROYS WHILE READ LOOP - while read __cdist_requirement; do - set -- "$@" "$__cdist_requirement" - done < "$__cdist_object_require" - - while [ $# -gt 0 ]; do - __cdist_requirement="$1"; shift - __cdist_echo info "Resolving requirement $__cdist_requirement" - cdist-object-run "$__cdist_target_host" "$__cdist_requirement" - done - fi - - __cdist_object_gencode_run "$__cdist_object_self" - __cdist_dir push "$(__cdist_object_dir "$__cdist_object_self")" \ - "$(__cdist_remote_object_dir "$__cdist_object_self")" - __cdist_object_code_run "$__cdist_object_self" - - # Mark this object as done - touch "$__cdist_object_finished" -fi diff --git a/core/__cdist_object_run b/core/__cdist_object_run new file mode 100755 index 00000000..5da7aa1e --- /dev/null +++ b/core/__cdist_object_run @@ -0,0 +1,66 @@ +#!/bin/sh +# +# 2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 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 . +# +# +# For the given object: +# - run type explorers +# - run type manifest +# - generate code +# - copy object to target +# - execute code on target +# + +__cdist_object_run() +{ + [ $# -eq 1 ] || __cdist_usage "" + + __cdist_object_self="$1"; shift + __cdist_object_dir="$(__cdist_object_dir "$__cdist_object_self")" + [ -d "$__cdist_object_dir" ] || __cdist_exit_err "Object undefined" + + # Export to non-core for use in manifest and gencode scripts + export $__cdist_name_var_self=$__cdist_object_self + + __cdist_object_finished="$(__cdist_object_finished "$__cdist_object_self")" + if [ ! -f "$__cdist_object_finished" ]; then + # Resolve dependencies, if any + __cdist_object_require="$(__cdist_object_require "$__cdist_object_self")" + if [ -f "$__cdist_object_require" ]; then + # NEED TO CREATE ARRAY, SSH DESTROYS WHILE READ LOOP + while read __cdist_requirement; do + set -- "$@" "$__cdist_requirement" + done < "$__cdist_object_require" + + while [ $# -gt 0 ]; do + __cdist_requirement="$1"; shift + __cdist_echo info "Resolving requirement $__cdist_requirement" + __cdist_object_run "$__cdist_target_host" "$__cdist_requirement" + done + fi + + __cdist_object_gencode_run "$__cdist_object_self" + __cdist_dir push "$(__cdist_object_dir "$__cdist_object_self")" \ + "$(__cdist_remote_object_dir "$__cdist_object_self")" + __cdist_object_code_run "$__cdist_object_self" + + # Mark this object as done + touch "$__cdist_object_finished" + fi +} From cc7da0c264786051611244f54d2813b0508bdaeb Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 14 Jun 2011 01:05:26 +0200 Subject: [PATCH 013/110] ../bin/cdist-object-all -> __cdist_object_all Signed-off-by: Nico Schottelius --- bin/cdist-deploy-to | 4 +-- bin/cdist-object-all | 56 ----------------------------------------- core/__cdist_object_all | 56 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 58 deletions(-) delete mode 100755 bin/cdist-object-all create mode 100755 core/__cdist_object_all diff --git a/bin/cdist-deploy-to b/bin/cdist-deploy-to index c512bd88..3711fac5 100755 --- a/bin/cdist-deploy-to +++ b/bin/cdist-deploy-to @@ -56,8 +56,8 @@ __cdist_dir push "${__cdist_core_dir}" "${__cdist_remote_core_dir}" cdist-explorer-run-global "$__cdist_target_host" cdist-manifest-run-init "$__cdist_target_host" -cdist-object-all "$__cdist_target_host" cdist-object-prepare -cdist-object-all "$__cdist_target_host" __cdist_object_run +__cdist_object_all cdist-object-prepare +__cdist_object_all __cdist_object_run cdist-cache "$__cdist_target_host" __cdist_echo info "cdist $__cdist_version: Successfully finished run" diff --git a/bin/cdist-object-all b/bin/cdist-object-all deleted file mode 100755 index 391c9cc7..00000000 --- a/bin/cdist-object-all +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/sh -# -# 2011 Nico Schottelius (nico-cdist at schottelius.org) -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) -# -# 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 . -# -# -# Run the given command for each created object. -# - -. cdist-config -[ $# -eq 2 ] || __cdist_usage " " -set -eu - -__cdist_target_host="$1"; shift -__cdist_command="$1"; shift - -__cdist_objects="$__cdist_tmp_dir/objects" - -# Ensure object dir exists, so marker can be created -mkdir -p "${__cdist_out_object_dir}" - -# Loop until we do not create new objects anymore -# which is equal to all objects have been run -touch "$__cdist_objects_created" -while [ -f "$__cdist_objects_created" ]; do - # Assume we're done after this run - rm "$__cdist_objects_created" - - # Get listing of objects - __cdist_object_list "$__cdist_out_object_dir" > "$__cdist_objects" - - # NEED TO CREATE ARRAY, SSH DESTROYS WHILE READ LOOP - while read __cdist_object; do - set -- "$@" "$__cdist_object" - done < "$__cdist_objects" - - while [ $# -gt 0 ]; do - __cdist_object="$1"; shift - $__cdist_command "$__cdist_target_host" "$__cdist_object" - done -done diff --git a/core/__cdist_object_all b/core/__cdist_object_all new file mode 100755 index 00000000..52661073 --- /dev/null +++ b/core/__cdist_object_all @@ -0,0 +1,56 @@ +#!/bin/sh +# +# 2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 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 . +# +# +# Run the given command for each created object. +# + +__cdist_object_all() +{ + [ $# -eq 1 ] || __cdist_usage "" + + __cdist_command="$1"; shift + + __cdist_objects="$__cdist_tmp_dir/objects" + + # Ensure object dir exists, so marker can be created + mkdir -p "${__cdist_out_object_dir}" + + # Loop until we do not create new objects anymore + # which is equal to all objects have been run + touch "$__cdist_objects_created" + while [ -f "$__cdist_objects_created" ]; do + # Assume we're done after this run + rm "$__cdist_objects_created" + + # Get listing of objects + __cdist_object_list "$__cdist_out_object_dir" > "$__cdist_objects" + + # NEED TO CREATE ARRAY, SSH DESTROYS WHILE READ LOOP + while read __cdist_object; do + set -- "$@" "$__cdist_object" + done < "$__cdist_objects" + + while [ $# -gt 0 ]; do + __cdist_object="$1"; shift + $__cdist_command "$__cdist_object" + done + done +} From 0e2c221b43d9c3bf8c56880d2a194f602289f53d Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 14 Jun 2011 01:07:56 +0200 Subject: [PATCH 014/110] ../bin/cdist-object-prepare -> __cdist_object_prepare Signed-off-by: Nico Schottelius --- bin/cdist-deploy-to | 4 +-- .../__cdist_object_prepare | 36 ++++++++++--------- 2 files changed, 21 insertions(+), 19 deletions(-) rename bin/cdist-object-prepare => core/__cdist_object_prepare (50%) diff --git a/bin/cdist-deploy-to b/bin/cdist-deploy-to index 3711fac5..9d5573f3 100755 --- a/bin/cdist-deploy-to +++ b/bin/cdist-deploy-to @@ -56,8 +56,8 @@ __cdist_dir push "${__cdist_core_dir}" "${__cdist_remote_core_dir}" cdist-explorer-run-global "$__cdist_target_host" cdist-manifest-run-init "$__cdist_target_host" -__cdist_object_all cdist-object-prepare -__cdist_object_all __cdist_object_run +__cdist_object_all __cdist_object_prepare +__cdist_object_all __cdist_object_run cdist-cache "$__cdist_target_host" __cdist_echo info "cdist $__cdist_version: Successfully finished run" diff --git a/bin/cdist-object-prepare b/core/__cdist_object_prepare similarity index 50% rename from bin/cdist-object-prepare rename to core/__cdist_object_prepare index d21d8a63..edb38e12 100755 --- a/bin/cdist-object-prepare +++ b/core/__cdist_object_prepare @@ -24,24 +24,26 @@ # - run type manifest # -. cdist-config -[ $# -eq 2 ] || __cdist_usage " " -set -eu +__cdist_object_prepare() +{ + [ $# -eq 1 ] || __cdist_usage "" + set -eu -__cdist_target_host="$1"; shift -__cdist_object_self="$1"; shift -__cdist_object_dir="$(__cdist_object_dir "$__cdist_object_self")" -[ -d "$__cdist_object_dir" ] || __cdist_exit_err "Object undefined" + __cdist_target_host="$1"; shift + __cdist_object_self="$1"; shift + __cdist_object_dir="$(__cdist_object_dir "$__cdist_object_self")" + [ -d "$__cdist_object_dir" ] || __cdist_exit_err "Object undefined" -# Export to non-core for use in manifest and gencode scripts -export $__cdist_name_var_self=$__cdist_object_self + # Export to non-core for use in manifest and gencode scripts + export $__cdist_name_var_self=$__cdist_object_self -__cdist_object_prepared="$(__cdist_object_prepared "$__cdist_object_self")" -if [ ! -f "$__cdist_object_prepared" ]; then - __cdist_echo info "Preparing object" - cdist-object-explorer-run "$__cdist_target_host" "$__cdist_object_self" - cdist-object-manifest-run "$__cdist_target_host" "$__cdist_object_self" + __cdist_object_prepared="$(__cdist_object_prepared "$__cdist_object_self")" + if [ ! -f "$__cdist_object_prepared" ]; then + __cdist_echo info "Preparing object" + cdist-object-explorer-run "$__cdist_target_host" "$__cdist_object_self" + cdist-object-manifest-run "$__cdist_target_host" "$__cdist_object_self" - # Mark this object as prepared - touch "$__cdist_object_prepared" -fi + # Mark this object as prepared + touch "$__cdist_object_prepared" + fi +} From 95ce60637ca36956d43f0719ba10b0d8de5a0148 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 14 Jun 2011 01:08:52 +0200 Subject: [PATCH 015/110] enhance for use as function cdist-deploy-to localhost 1.38s user 1.28s system 69% cpu 3.842 total Signed-off-by: Nico Schottelius --- core/__cdist_object_prepare | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/__cdist_object_prepare b/core/__cdist_object_prepare index edb38e12..e2c682b1 100755 --- a/core/__cdist_object_prepare +++ b/core/__cdist_object_prepare @@ -27,9 +27,7 @@ __cdist_object_prepare() { [ $# -eq 1 ] || __cdist_usage "" - set -eu - __cdist_target_host="$1"; shift __cdist_object_self="$1"; shift __cdist_object_dir="$(__cdist_object_dir "$__cdist_object_self")" [ -d "$__cdist_object_dir" ] || __cdist_exit_err "Object undefined" From 5c378dcb1bdfef02ac4af3d53f16549a6c5d8805 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 14 Jun 2011 01:11:12 +0200 Subject: [PATCH 016/110] ++todo Signed-off-by: Nico Schottelius --- doc/dev/todo/TAKEME | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/dev/todo/TAKEME b/doc/dev/todo/TAKEME index d626493d..c4da3df3 100644 --- a/doc/dev/todo/TAKEME +++ b/doc/dev/todo/TAKEME @@ -5,6 +5,8 @@ Feel free to pick one! CORE ---- +- Fix warnings / __cdist_usage in core/* + -> __cdist_usage prints $0! not function name! - Inconsistent error messages if object is not existing! -> always use "Object undefined" - Add echo function / beautify output From f7138c292130670f16255e0f5e450bcecb577b70 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 14 Jun 2011 01:13:01 +0200 Subject: [PATCH 017/110] bin/cdist-object-explorer-run -> core/__cdist_object_explorer_run Signed-off-by: Nico Schottelius --- bin/cdist-object-explorer-run | 66 -------------------------------- core/__cdist_object_explorer_run | 65 +++++++++++++++++++++++++++++++ core/__cdist_object_prepare | 2 +- 3 files changed, 66 insertions(+), 67 deletions(-) delete mode 100755 bin/cdist-object-explorer-run create mode 100755 core/__cdist_object_explorer_run diff --git a/bin/cdist-object-explorer-run b/bin/cdist-object-explorer-run deleted file mode 100755 index 8bdf50ce..00000000 --- a/bin/cdist-object-explorer-run +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/sh -# -# 2010-2011 Nico Schottelius (nico-cdist at schottelius.org) -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) -# -# 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 . -# -# -# Run the explorers for the given object on the target host. -# - -. cdist-config -[ $# -eq 2 ] || __cdist_usage " " -set -eu - -__cdist_target_host="$1"; shift -__cdist_object_self="$1"; shift - -__cdist_object_id="$(__cdist_object_id_from_object "$__cdist_object_self")" -__cdist_type="$(__cdist_type_from_object "$__cdist_object_self")" - -# Check if type of object has >= 1 explorer -__cdist_has_explorer="$(__cdist_type_has_explorer "$__cdist_type")" -# Run the type explorers for the current object if any -if [ "$__cdist_has_explorer" ]; then - if ! __cdist_type_explorer_pushed "$__cdist_type"; then - src_dir="$(__cdist_type_explorer_dir "$__cdist_type")" - dst_dir="$(__cdist_remote_type_explorer_dir "$__cdist_type")" - __cdist_echo info "Transfering explorers for $__cdist_type " - __cdist_dir push "$src_dir" "$dst_dir" - __cdist_type_explorer_pushed_add "$__cdist_type" - fi - - __cdist_echo info "Running explorers" - # Copy object parameters - __cdist_dir push \ - "$(__cdist_object_parameter_dir "$__cdist_object_self")" \ - "$(__cdist_remote_object_parameter_dir "$__cdist_object_self")" - - # Execute explorers - cdist-run-remote "$__cdist_target_host" \ - "$__cdist_name_var_object=\"$(__cdist_remote_object_dir "$__cdist_object_self")\"" \ - "$__cdist_name_var_object_id=\"$__cdist_object_id\"" \ - "$__cdist_name_var_self=\"$__cdist_object_self\"" \ - cdist-remote-explorer-run \ - "$__cdist_name_var_type_explorer" \ - "$(__cdist_remote_type_explorer_dir "$__cdist_type")" \ - "$(__cdist_remote_object_type_explorer_dir "$__cdist_object_self")" - - # Copy back results - __cdist_dir pull "$(__cdist_remote_object_type_explorer_dir "$__cdist_object_self")" \ - "$(__cdist_object_type_explorer_dir "$__cdist_object_self")" -fi diff --git a/core/__cdist_object_explorer_run b/core/__cdist_object_explorer_run new file mode 100755 index 00000000..f11c6786 --- /dev/null +++ b/core/__cdist_object_explorer_run @@ -0,0 +1,65 @@ +#!/bin/sh +# +# 2010-2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 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 . +# +# +# Run the explorers for the given object on the target host. +# + +__cdist_object_explorer_run() +{ + __cdist_object_self="$1"; shift + + __cdist_object_id="$(__cdist_object_id_from_object "$__cdist_object_self")" + __cdist_type="$(__cdist_type_from_object "$__cdist_object_self")" + + # Check if type of object has >= 1 explorer + __cdist_has_explorer="$(__cdist_type_has_explorer "$__cdist_type")" + # Run the type explorers for the current object if any + if [ "$__cdist_has_explorer" ]; then + if ! __cdist_type_explorer_pushed "$__cdist_type"; then + # FIXME: variables! + src_dir="$(__cdist_type_explorer_dir "$__cdist_type")" + dst_dir="$(__cdist_remote_type_explorer_dir "$__cdist_type")" + __cdist_echo info "Transfering explorers for $__cdist_type " + __cdist_dir push "$src_dir" "$dst_dir" + __cdist_type_explorer_pushed_add "$__cdist_type" + fi + + __cdist_echo info "Running explorers" + # Copy object parameters + __cdist_dir push \ + "$(__cdist_object_parameter_dir "$__cdist_object_self")" \ + "$(__cdist_remote_object_parameter_dir "$__cdist_object_self")" + + # Execute explorers + cdist-run-remote "$__cdist_target_host" \ + "$__cdist_name_var_object=\"$(__cdist_remote_object_dir "$__cdist_object_self")\"" \ + "$__cdist_name_var_object_id=\"$__cdist_object_id\"" \ + "$__cdist_name_var_self=\"$__cdist_object_self\"" \ + cdist-remote-explorer-run \ + "$__cdist_name_var_type_explorer" \ + "$(__cdist_remote_type_explorer_dir "$__cdist_type")" \ + "$(__cdist_remote_object_type_explorer_dir "$__cdist_object_self")" + + # Copy back results + __cdist_dir pull "$(__cdist_remote_object_type_explorer_dir "$__cdist_object_self")" \ + "$(__cdist_object_type_explorer_dir "$__cdist_object_self")" + fi +} diff --git a/core/__cdist_object_prepare b/core/__cdist_object_prepare index e2c682b1..53616487 100755 --- a/core/__cdist_object_prepare +++ b/core/__cdist_object_prepare @@ -38,7 +38,7 @@ __cdist_object_prepare() __cdist_object_prepared="$(__cdist_object_prepared "$__cdist_object_self")" if [ ! -f "$__cdist_object_prepared" ]; then __cdist_echo info "Preparing object" - cdist-object-explorer-run "$__cdist_target_host" "$__cdist_object_self" + __cdist_object_explorer_run "$__cdist_object_self" cdist-object-manifest-run "$__cdist_target_host" "$__cdist_object_self" # Mark this object as prepared From 5dff2157e2a550165c2da438f26c61468bc48fca Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 14 Jun 2011 01:15:50 +0200 Subject: [PATCH 018/110] bin/cdist-object-manifest-run -> core/__cdist_object_manifest_run Signed-off-by: Nico Schottelius --- bin/cdist-object-manifest-run | 58 ------------------------------- core/__cdist_object_manifest_run | 59 ++++++++++++++++++++++++++++++++ core/__cdist_object_prepare | 2 +- 3 files changed, 60 insertions(+), 59 deletions(-) delete mode 100755 bin/cdist-object-manifest-run create mode 100755 core/__cdist_object_manifest_run diff --git a/bin/cdist-object-manifest-run b/bin/cdist-object-manifest-run deleted file mode 100755 index 34d4f867..00000000 --- a/bin/cdist-object-manifest-run +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/sh -# -# 2010 Nico Schottelius (nico-cdist at schottelius.org) -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) -# -# 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 . -# -# -# Run the manifest for the given object. -# - -. cdist-config -[ $# -eq 2 ] || __cdist_usage " " -set -eu - -__cdist_target_host="$1"; shift -__cdist_object_self="$1"; shift - -# FIXME: rename to __cdist_object_dir (everywhere!) -__cdist_cur_object_dir="$(__cdist_object_dir "$__cdist_object_self")" -__cdist_object_id="$(__cdist_object_id_from_object "$__cdist_object_self")" - -__cdist_echo info "Checking manifest " - -__cdist_type="$(__cdist_type_from_object "$__cdist_object_self")" -__cdist_manifest="$(__cdist_type_manifest "$__cdist_type")" - -if [ -f "$__cdist_manifest" ]; then - if [ -x "$__cdist_manifest" ]; then - # Make __cdist_manifest available for cdist-type-emulator - export __cdist_manifest - - __cdist_echo info "Executing manifest " - export $__cdist_name_var_object="$__cdist_cur_object_dir" - export $__cdist_name_var_object_id="$__cdist_object_id" - export $__cdist_name_var_type="$(__cdist_type_dir "$__cdist_type")" - - cdist-manifest-run "$__cdist_target_host" "$__cdist_manifest" - - # Tell cdist-object-run-all that there may be new objects - touch "$__cdist_objects_created" - else - __cdist_exit_err "${__cdist_manifest} needs to be executable." - fi -fi diff --git a/core/__cdist_object_manifest_run b/core/__cdist_object_manifest_run new file mode 100755 index 00000000..630d5d8b --- /dev/null +++ b/core/__cdist_object_manifest_run @@ -0,0 +1,59 @@ +#!/bin/sh +# +# 2010 Nico Schottelius (nico-cdist at schottelius.org) +# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 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 . +# +# +# Run the manifest for the given object. +# + + +__cdist_object_manifest_run() +{ + [ $# -eq 1 ] || __cdist_usage "" + + __cdist_object_self="$1"; shift + + # FIXME: rename to __cdist_object_dir (everywhere!) + __cdist_cur_object_dir="$(__cdist_object_dir "$__cdist_object_self")" + __cdist_object_id="$(__cdist_object_id_from_object "$__cdist_object_self")" + + __cdist_echo info "Checking manifest " + + __cdist_type="$(__cdist_type_from_object "$__cdist_object_self")" + __cdist_manifest="$(__cdist_type_manifest "$__cdist_type")" + + if [ -f "$__cdist_manifest" ]; then + if [ -x "$__cdist_manifest" ]; then + # Make __cdist_manifest available for cdist-type-emulator + export __cdist_manifest + + __cdist_echo info "Executing manifest " + export $__cdist_name_var_object="$__cdist_cur_object_dir" + export $__cdist_name_var_object_id="$__cdist_object_id" + export $__cdist_name_var_type="$(__cdist_type_dir "$__cdist_type")" + + cdist-manifest-run "$__cdist_target_host" "$__cdist_manifest" + + # Tell cdist-object-run-all that there may be new objects + touch "$__cdist_objects_created" + else + __cdist_exit_err "${__cdist_manifest} needs to be executable." + fi + fi +} diff --git a/core/__cdist_object_prepare b/core/__cdist_object_prepare index 53616487..24039be0 100755 --- a/core/__cdist_object_prepare +++ b/core/__cdist_object_prepare @@ -39,7 +39,7 @@ __cdist_object_prepare() if [ ! -f "$__cdist_object_prepared" ]; then __cdist_echo info "Preparing object" __cdist_object_explorer_run "$__cdist_object_self" - cdist-object-manifest-run "$__cdist_target_host" "$__cdist_object_self" + __cdist_object_manifest_run "$__cdist_object_self" # Mark this object as prepared touch "$__cdist_object_prepared" From 0167f4a9f3264e8f47321325ac63b1432d82ec63 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 14 Jun 2011 01:18:55 +0200 Subject: [PATCH 019/110] ../core/__cdist_manifest_run Signed-off-by: Nico Schottelius --- bin/cdist-manifest-run | 56 ------------------------------ bin/cdist-manifest-run-init | 2 +- core/__cdist_manifest_run | 58 ++++++++++++++++++++++++++++++++ core/__cdist_object_manifest_run | 2 +- 4 files changed, 60 insertions(+), 58 deletions(-) delete mode 100755 bin/cdist-manifest-run create mode 100755 core/__cdist_manifest_run diff --git a/bin/cdist-manifest-run b/bin/cdist-manifest-run deleted file mode 100755 index d4ea18bb..00000000 --- a/bin/cdist-manifest-run +++ /dev/null @@ -1,56 +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 . -# -# -# Let's build a cconfig tree from a configuration -# And save it into the cache tree -# - -. cdist-config -[ $# -eq 2 ] || __cdist_usage " " -set -u - -__cdist_target_host="$1"; shift -__cdist_manifest="$1"; shift - -################################################################################ -# Export information for cdist-type-emulator or manifest -# - -# Config dir should not get reset - FIXME: why did I do this? -export __cdist_conf_dir - -# Used to record the source in the object -export __cdist_manifest - -# Export information for manifests - __cdist_out_dir comes from cdist-config -export __global="$__cdist_out_dir" - -################################################################################ -# The actual run -# - -# Ensure binaries exist and are up-to-date -cdist-type-build-emulation "${__cdist_out_type_bin_dir}" \ - || __cdist_exit_err "Failed to build type emulation binaries" - -# prepend our path, so all cdist tools come before other tools -export PATH="${__cdist_out_type_bin_dir}:$PATH" - -__cdist_exec_fail_on_error "${__cdist_manifest}" diff --git a/bin/cdist-manifest-run-init b/bin/cdist-manifest-run-init index 28acc623..787d2315 100755 --- a/bin/cdist-manifest-run-init +++ b/bin/cdist-manifest-run-init @@ -31,4 +31,4 @@ __cdist_target_host="$1"; shift eval export $__cdist_name_var_manifest=\"\$__cdist_manifest_dir\" __cdist_echo info "Running initial manifest for $__cdist_target_host " -cdist-manifest-run "$__cdist_target_host" "$__cdist_manifest_init" +__cdist_manifest_run "$__cdist_manifest_init" diff --git a/core/__cdist_manifest_run b/core/__cdist_manifest_run new file mode 100755 index 00000000..f2283f85 --- /dev/null +++ b/core/__cdist_manifest_run @@ -0,0 +1,58 @@ +#!/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 . +# +# +# Let's build a cconfig tree from a configuration +# And save it into the cache tree +# + +__cdist_manifest_run() +{ + + [ $# -eq 1 ] || __cdist_usage "" + set -u + + __cdist_manifest="$1"; shift + + ################################################################################ + # Export information for cdist-type-emulator or manifest + # + + # Config dir should not get reset - FIXME: why did I do this? + export __cdist_conf_dir + + # Used to record the source in the object + export __cdist_manifest + + # Export information for manifests - __cdist_out_dir comes from cdist-config + export __global="$__cdist_out_dir" + + ################################################################################ + # The actual run + # + + # Ensure binaries exist and are up-to-date + cdist-type-build-emulation "${__cdist_out_type_bin_dir}" \ + || __cdist_exit_err "Failed to build type emulation binaries" + + # prepend our path, so all cdist tools come before other tools + export PATH="${__cdist_out_type_bin_dir}:$PATH" + + __cdist_exec_fail_on_error "${__cdist_manifest}" +} diff --git a/core/__cdist_object_manifest_run b/core/__cdist_object_manifest_run index 630d5d8b..40413726 100755 --- a/core/__cdist_object_manifest_run +++ b/core/__cdist_object_manifest_run @@ -48,7 +48,7 @@ __cdist_object_manifest_run() export $__cdist_name_var_object_id="$__cdist_object_id" export $__cdist_name_var_type="$(__cdist_type_dir "$__cdist_type")" - cdist-manifest-run "$__cdist_target_host" "$__cdist_manifest" + __cdist_manifest_run "$__cdist_target_host" "$__cdist_manifest" # Tell cdist-object-run-all that there may be new objects touch "$__cdist_objects_created" From da9974b9ce921e37239f5d2d44ca427ddfdf1e69 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 14 Jun 2011 01:19:58 +0200 Subject: [PATCH 020/110] -bug :-) Signed-off-by: Nico Schottelius --- core/__cdist_object_manifest_run | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/__cdist_object_manifest_run b/core/__cdist_object_manifest_run index 40413726..efc85539 100755 --- a/core/__cdist_object_manifest_run +++ b/core/__cdist_object_manifest_run @@ -48,7 +48,7 @@ __cdist_object_manifest_run() export $__cdist_name_var_object_id="$__cdist_object_id" export $__cdist_name_var_type="$(__cdist_type_dir "$__cdist_type")" - __cdist_manifest_run "$__cdist_target_host" "$__cdist_manifest" + __cdist_manifest_run "$__cdist_manifest" # Tell cdist-object-run-all that there may be new objects touch "$__cdist_objects_created" From 47c32d1b535db2e53acdfd985e630c01d28cb2c0 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 14 Jun 2011 01:22:51 +0200 Subject: [PATCH 021/110] ../core/__cdist_manifest_run_init Signed-off-by: Nico Schottelius --- bin/cdist-deploy-to | 2 +- core/__cdist_manifest_run | 2 -- .../__cdist_manifest_run_init | 15 ++++++--------- 3 files changed, 7 insertions(+), 12 deletions(-) rename bin/cdist-manifest-run-init => core/__cdist_manifest_run_init (74%) diff --git a/bin/cdist-deploy-to b/bin/cdist-deploy-to index 9d5573f3..6b3f2ee1 100755 --- a/bin/cdist-deploy-to +++ b/bin/cdist-deploy-to @@ -55,7 +55,7 @@ __cdist_dir push "${__cdist_abs_mydir}" "${__cdist_remote_bin_dir}" __cdist_dir push "${__cdist_core_dir}" "${__cdist_remote_core_dir}" cdist-explorer-run-global "$__cdist_target_host" -cdist-manifest-run-init "$__cdist_target_host" +__cdist_manifest_run_init "$__cdist_target_host" __cdist_object_all __cdist_object_prepare __cdist_object_all __cdist_object_run cdist-cache "$__cdist_target_host" diff --git a/core/__cdist_manifest_run b/core/__cdist_manifest_run index f2283f85..0ba5f515 100755 --- a/core/__cdist_manifest_run +++ b/core/__cdist_manifest_run @@ -24,9 +24,7 @@ __cdist_manifest_run() { - [ $# -eq 1 ] || __cdist_usage "" - set -u __cdist_manifest="$1"; shift diff --git a/bin/cdist-manifest-run-init b/core/__cdist_manifest_run_init similarity index 74% rename from bin/cdist-manifest-run-init rename to core/__cdist_manifest_run_init index 787d2315..2d694900 100755 --- a/bin/cdist-manifest-run-init +++ b/core/__cdist_manifest_run_init @@ -22,13 +22,10 @@ # And save it into the cache tree # -. cdist-config -[ $# -eq 1 ] || __cdist_usage "" -set -e +__cdist_manifest_run_init() +{ + eval export $__cdist_name_var_manifest=\"\$__cdist_manifest_dir\" -__cdist_target_host="$1"; shift - -eval export $__cdist_name_var_manifest=\"\$__cdist_manifest_dir\" - -__cdist_echo info "Running initial manifest for $__cdist_target_host " -__cdist_manifest_run "$__cdist_manifest_init" + __cdist_echo info "Running initial manifest for $__cdist_target_host " + __cdist_manifest_run "$__cdist_manifest_init" +} From 9a86b392dca714e31497f9f39db9b54789dc49a3 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 14 Jun 2011 01:27:53 +0200 Subject: [PATCH 022/110] ../core/__cdist_code_run and ../core/__cdist_type_build_emulation Signed-off-by: Nico Schottelius --- bin/cdist-code-run => core/__cdist_code_run | 40 ++++++++++--------- core/__cdist_manifest_run | 3 +- core/__cdist_object_code_run | 2 +- .../__cdist_type_build_emulation | 34 ++++++++-------- 4 files changed, 41 insertions(+), 38 deletions(-) rename bin/cdist-code-run => core/__cdist_code_run (50%) rename bin/cdist-type-build-emulation => core/__cdist_type_build_emulation (57%) diff --git a/bin/cdist-code-run b/core/__cdist_code_run similarity index 50% rename from bin/cdist-code-run rename to core/__cdist_code_run index 3d7499bf..6a1b916b 100755 --- a/bin/cdist-code-run +++ b/core/__cdist_code_run @@ -21,30 +21,32 @@ # This binary is executed on the remote side to execute code # -. cdist-config -[ $# -eq 2 ] || __cdist_usage " " -set -ue +__cdist_code_run() +{ -__cdist_object_self="$1"; shift -__cdist_code_type="$1"; shift + [ $# -eq 2 ] || __cdist_usage " " -if [ ! -d "$(__cdist_object_dir "$__cdist_object_self")" ]; then - __cdist_exit_err "Object undefined" -fi + __cdist_object_self="$1"; shift + __cdist_code_type="$1"; shift -__cdist_code="$(__cdist_object_code "$__cdist_object_self" "${__cdist_code_type}")" + if [ ! -d "$(__cdist_object_dir "$__cdist_object_self")" ]; then + __cdist_exit_err "Object undefined" + fi -__cdist_echo info "Checking code-${__cdist_code_type}" + __cdist_code="$(__cdist_object_code "$__cdist_object_self" "${__cdist_code_type}")" -if [ -e "$__cdist_code" ]; then - if [ -f "$__cdist_code" ]; then - if [ -x "$__cdist_code" ]; then - __cdist_echo info "Executing code-${__cdist_code_type}" - __cdist_exec_fail_on_error "$__cdist_code" + __cdist_echo info "Checking code-${__cdist_code_type}" + + if [ -e "$__cdist_code" ]; then + if [ -f "$__cdist_code" ]; then + if [ -x "$__cdist_code" ]; then + __cdist_echo info "Executing code-${__cdist_code_type}" + __cdist_exec_fail_on_error "$__cdist_code" + else + __cdist_exit_err "$__cdist_code exists, but is not executable." + fi else - __cdist_exit_err "$__cdist_code exists, but is not executable." + __cdist_exit_err "$__cdist_code exists, but is not a file." fi - else - __cdist_exit_err "$__cdist_code exists, but is not a file." fi -fi +} diff --git a/core/__cdist_manifest_run b/core/__cdist_manifest_run index 0ba5f515..76d0a934 100755 --- a/core/__cdist_manifest_run +++ b/core/__cdist_manifest_run @@ -46,7 +46,8 @@ __cdist_manifest_run() # # Ensure binaries exist and are up-to-date - cdist-type-build-emulation "${__cdist_out_type_bin_dir}" \ + # FIXME: do only once! no need to check for every manifest! + __cdist_type_build_emulation "${__cdist_out_type_bin_dir}" \ || __cdist_exit_err "Failed to build type emulation binaries" # prepend our path, so all cdist tools come before other tools diff --git a/core/__cdist_object_code_run b/core/__cdist_object_code_run index cecb6659..d25d1dca 100755 --- a/core/__cdist_object_code_run +++ b/core/__cdist_object_code_run @@ -29,7 +29,7 @@ __cdist_object_code_run() # Code local export __cdist_out_object_dir="$__cdist_out_object_dir" - cdist-code-run "$__cdist_object_code_run_object" "${__cdist_name_gencode_local}" + __cdist_code_run "$__cdist_object_code_run_object" "${__cdist_name_gencode_local}" # Code remote cdist-run-remote "$__cdist_target_host" \ diff --git a/bin/cdist-type-build-emulation b/core/__cdist_type_build_emulation similarity index 57% rename from bin/cdist-type-build-emulation rename to core/__cdist_type_build_emulation index 51c2f5b4..a6cfcaa6 100755 --- a/bin/cdist-type-build-emulation +++ b/core/__cdist_type_build_emulation @@ -20,24 +20,24 @@ # Build pseudo binaries for type emulation # -. cdist-config -[ $# -eq 1 ] || __cdist_usage "" -set -eu +__cdist_type_build_emulation() +{ + [ $# -eq 1 ] || __cdist_usage "" -__cdist_output_dir="$1"; shift + __cdist_output_dir="$1"; shift + __cdist_type_emulator="$__cdist_abs_mydir/cdist-type-emulator" -__cdist_type_emulator="$__cdist_abs_mydir/cdist-type-emulator" + if [ ! -d "${__cdist_type_dir}" ]; then + __cdist_exit_err "$__cdist_type_dir must exist and contain available types" + fi -if [ ! -d "${__cdist_type_dir}" ]; then - __cdist_exit_err "$__cdist_type_dir must exist and contain available types" -fi + # Get Types + cd "${__cdist_type_dir}" + ls -1 > "${__cdist_tmp_file}" -# Get Types -cd "${__cdist_type_dir}" -ls -1 > "${__cdist_tmp_file}" - -# Create binaries -mkdir -p "${__cdist_output_dir}" -while read type; do - ln -sf "${__cdist_type_emulator}" "${__cdist_output_dir}/${type}" -done < "${__cdist_tmp_file}" + # Create binaries + mkdir -p "${__cdist_output_dir}" + while read type; do + ln -sf "${__cdist_type_emulator}" "${__cdist_output_dir}/${type}" + done < "${__cdist_tmp_file}" +} From 1565c73559e834cfa031db24e98050de0150079b Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 14 Jun 2011 01:36:13 +0200 Subject: [PATCH 023/110] no target host needed anymore Signed-off-by: Nico Schottelius --- core/__cdist_object_run | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/__cdist_object_run b/core/__cdist_object_run index 5da7aa1e..07461b23 100755 --- a/core/__cdist_object_run +++ b/core/__cdist_object_run @@ -51,7 +51,7 @@ __cdist_object_run() while [ $# -gt 0 ]; do __cdist_requirement="$1"; shift __cdist_echo info "Resolving requirement $__cdist_requirement" - __cdist_object_run "$__cdist_target_host" "$__cdist_requirement" + __cdist_object_run "$__cdist_requirement" done fi From 2f5b416a33d5a9bb959e58c7380f65c07c8dce0a Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 14 Jun 2011 01:37:52 +0200 Subject: [PATCH 024/110] +marker Signed-off-by: Nico Schottelius --- doc/dev/todo/niconext | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/dev/todo/niconext b/doc/dev/todo/niconext index 5ba529ad..ce89c643 100644 --- a/doc/dev/todo/niconext +++ b/doc/dev/todo/niconext @@ -1 +1,5 @@ +- run-remote does not work anymore, because there is no binary :-) + either make functions available on the other side or + put logic on the server side. + Catch broken instances in cdist-mass-deploy -p and report broken deployements at the end! From 188afa2777615335c42e1a2498ef8779cd8f4ab6 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 14 Jun 2011 01:44:40 +0200 Subject: [PATCH 025/110] add wrapper script to execute functions remotely Signed-off-by: Nico Schottelius --- bin/cdist-remote | 68 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100755 bin/cdist-remote diff --git a/bin/cdist-remote b/bin/cdist-remote new file mode 100755 index 00000000..d95913ba --- /dev/null +++ b/bin/cdist-remote @@ -0,0 +1,68 @@ +#!/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 +[ $# -eq 3 ] || __cdist_usage " " +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 + +# Setup environment +export $__cdist_variable_name="$__cdist_explorer_dir" +export __global="$__cdist_remote_out_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 + __cdist_exit_err "Explorer \"$explorer\" exists, but is not executable." + fi + + # Execute explorers and save results in remote destination directory + "$explorer" > "${__cdist_my_out_dir}/$explorer_name" + else + if [ -e "$explorer" ]; then + __cdist_exit_err "Explorer \"$explorer\" exists, but is not a file." + fi + fi +done From 9e94bb56a2f333fdda4239a73d46e92b26113fcf Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 14 Jun 2011 01:47:26 +0200 Subject: [PATCH 026/110] core/__cdist_run_remote Signed-off-by: Nico Schottelius --- bin/cdist-deploy-to | 4 +- bin/cdist-explorer-run-global | 3 +- bin/cdist-remote | 46 +------------------ core/__cdist_object_code_run | 4 +- core/__cdist_object_explorer_run | 2 +- .../__cdist_run_remote | 18 ++++---- 6 files changed, 18 insertions(+), 59 deletions(-) rename bin/cdist-run-remote => core/__cdist_run_remote (70%) diff --git a/bin/cdist-deploy-to b/bin/cdist-deploy-to index 6b3f2ee1..baeff220 100755 --- a/bin/cdist-deploy-to +++ b/bin/cdist-deploy-to @@ -55,9 +55,9 @@ __cdist_dir push "${__cdist_abs_mydir}" "${__cdist_remote_bin_dir}" __cdist_dir push "${__cdist_core_dir}" "${__cdist_remote_core_dir}" cdist-explorer-run-global "$__cdist_target_host" -__cdist_manifest_run_init "$__cdist_target_host" +__cdist_manifest_run_init __cdist_object_all __cdist_object_prepare __cdist_object_all __cdist_object_run -cdist-cache "$__cdist_target_host" +__cdist_cache __cdist_echo info "cdist $__cdist_version: Successfully finished run" diff --git a/bin/cdist-explorer-run-global b/bin/cdist-explorer-run-global index 09b088f5..51052627 100755 --- a/bin/cdist-explorer-run-global +++ b/bin/cdist-explorer-run-global @@ -33,9 +33,10 @@ __cdist_echo info "Running global explorers " __cdist_dir push "${__cdist_explorer_dir}" "${__cdist_remote_explorer_dir}" # run the initial explorers remotely -cdist-run-remote "${__cdist_target_host}" cdist-remote-explorer-run \ +__cdist_run_remote "${__cdist_target_host}" cdist-remote-explorer-run \ "$__cdist_name_var_explorer" "$__cdist_remote_explorer_dir" \ "$__cdist_remote_out_explorer_dir" + # retrieve the results __cdist_dir pull "${__cdist_remote_out_explorer_dir}" "${__cdist_out_explorer_dir}" diff --git a/bin/cdist-remote b/bin/cdist-remote index d95913ba..0a730a6e 100755 --- a/bin/cdist-remote +++ b/bin/cdist-remote @@ -18,51 +18,9 @@ # 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 :-) +# This scripts runs functions or binaries remotely # . cdist-config -[ $# -eq 3 ] || __cdist_usage " " -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 - -# Setup environment -export $__cdist_variable_name="$__cdist_explorer_dir" -export __global="$__cdist_remote_out_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 - __cdist_exit_err "Explorer \"$explorer\" exists, but is not executable." - fi - - # Execute explorers and save results in remote destination directory - "$explorer" > "${__cdist_my_out_dir}/$explorer_name" - else - if [ -e "$explorer" ]; then - __cdist_exit_err "Explorer \"$explorer\" exists, but is not a file." - fi - fi -done +"$@" diff --git a/core/__cdist_object_code_run b/core/__cdist_object_code_run index d25d1dca..c07505fe 100755 --- a/core/__cdist_object_code_run +++ b/core/__cdist_object_code_run @@ -32,6 +32,6 @@ __cdist_object_code_run() __cdist_code_run "$__cdist_object_code_run_object" "${__cdist_name_gencode_local}" # Code remote - cdist-run-remote "$__cdist_target_host" \ - "cdist-code-run" "$__cdist_object_code_run_object" "${__cdist_name_gencode_remote}" + __cdist_run_remote "$__cdist_target_host" \ + "__cdist_code_run" "$__cdist_object_code_run_object" "${__cdist_name_gencode_remote}" } diff --git a/core/__cdist_object_explorer_run b/core/__cdist_object_explorer_run index f11c6786..eb62401e 100755 --- a/core/__cdist_object_explorer_run +++ b/core/__cdist_object_explorer_run @@ -49,7 +49,7 @@ __cdist_object_explorer_run() "$(__cdist_remote_object_parameter_dir "$__cdist_object_self")" # Execute explorers - cdist-run-remote "$__cdist_target_host" \ + __cdist_run_remote \ "$__cdist_name_var_object=\"$(__cdist_remote_object_dir "$__cdist_object_self")\"" \ "$__cdist_name_var_object_id=\"$__cdist_object_id\"" \ "$__cdist_name_var_self=\"$__cdist_object_self\"" \ diff --git a/bin/cdist-run-remote b/core/__cdist_run_remote similarity index 70% rename from bin/cdist-run-remote rename to core/__cdist_run_remote index 4a4452a2..697a1d68 100755 --- a/bin/cdist-run-remote +++ b/core/__cdist_run_remote @@ -21,13 +21,13 @@ # Run a cdist binary on the remote side # -. cdist-config -[ $# -ge 2 ] || __cdist_usage " [opts]" -set -ue +__cdist_run_remote() +{ + [ $# -ge 1 ] || __cdist_usage " [opts]" -__cdist_target_host="$1"; shift - -ssh "${__cdist_remote_user}@${__cdist_target_host}" \ - "export PATH=\"${__cdist_remote_bin_dir}:\$PATH\";" \ - "export __cdist_out_object_dir=\"$__cdist_remote_out_object_dir\";" \ - "$@" + ssh "${__cdist_remote_user}@${__cdist_target_host}" \ + "export PATH=\"${__cdist_remote_bin_dir}:\$PATH\";" \ + "export __cdist_out_object_dir=\"$__cdist_remote_out_object_dir\";" \ + ". cdist-config;" \ + "$@" +} From 00bbadef789c99ed03ad7494e32b9d1996ce703f Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 14 Jun 2011 01:49:43 +0200 Subject: [PATCH 027/110] fix first bugs in remotely running code Signed-off-by: Nico Schottelius --- bin/cdist-explorer-run-global | 2 +- core/__cdist_object_code_run | 4 ++-- core/__cdist_run_remote | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/bin/cdist-explorer-run-global b/bin/cdist-explorer-run-global index 51052627..b13b898f 100755 --- a/bin/cdist-explorer-run-global +++ b/bin/cdist-explorer-run-global @@ -33,7 +33,7 @@ __cdist_echo info "Running global explorers " __cdist_dir push "${__cdist_explorer_dir}" "${__cdist_remote_explorer_dir}" # run the initial explorers remotely -__cdist_run_remote "${__cdist_target_host}" cdist-remote-explorer-run \ +__cdist_run_remote cdist-remote-explorer-run \ "$__cdist_name_var_explorer" "$__cdist_remote_explorer_dir" \ "$__cdist_remote_out_explorer_dir" diff --git a/core/__cdist_object_code_run b/core/__cdist_object_code_run index c07505fe..48b6514d 100755 --- a/core/__cdist_object_code_run +++ b/core/__cdist_object_code_run @@ -32,6 +32,6 @@ __cdist_object_code_run() __cdist_code_run "$__cdist_object_code_run_object" "${__cdist_name_gencode_local}" # Code remote - __cdist_run_remote "$__cdist_target_host" \ - "__cdist_code_run" "$__cdist_object_code_run_object" "${__cdist_name_gencode_remote}" + __cdist_run_remote "__cdist_code_run" \ + "$__cdist_object_code_run_object" "${__cdist_name_gencode_remote}" } diff --git a/core/__cdist_run_remote b/core/__cdist_run_remote index 697a1d68..3af7c540 100755 --- a/core/__cdist_run_remote +++ b/core/__cdist_run_remote @@ -28,6 +28,5 @@ __cdist_run_remote() ssh "${__cdist_remote_user}@${__cdist_target_host}" \ "export PATH=\"${__cdist_remote_bin_dir}:\$PATH\";" \ "export __cdist_out_object_dir=\"$__cdist_remote_out_object_dir\";" \ - ". cdist-config;" \ - "$@" + "cdist-remote" "$@" } From 022db229246322f3f2c0213272c5576981afd102 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 14 Jun 2011 10:57:33 +0200 Subject: [PATCH 028/110] +debug Signed-off-by: Nico Schottelius --- bin/cdist-remote-explorer-run | 73 +++++++++++++++++++---------------- core/__cdist_code_run | 4 +- core/__cdist_object_gencode | 1 - core/__cdist_object_run | 5 +++ 4 files changed, 47 insertions(+), 36 deletions(-) diff --git a/bin/cdist-remote-explorer-run b/bin/cdist-remote-explorer-run index d95913ba..040e36a2 100755 --- a/bin/cdist-remote-explorer-run +++ b/bin/cdist-remote-explorer-run @@ -24,45 +24,50 @@ # and __type_explorers can be submitted :-) # -. cdist-config -[ $# -eq 3 ] || __cdist_usage " " -set -ue +# FIXME: cleanup! +__cdist_remote_explorer_run() +{ + [ $# -eq 3 ] || __cdist_usage " " + set -ue -# Variable that defines the home of the explorers -__cdist_variable_name="$1"; shift + "$__cdist_name_var_object=\"$(__cdist_remote_object_dir "$__cdist_object_self")\"" -# Find explorers here -__cdist_explorer_dir="$1"; shift + # Variable that defines the home of the explorers + __cdist_variable_name="$1"; shift -# Write output here -__cdist_my_out_dir="$1"; shift + # Find explorers here + __cdist_explorer_dir="$1"; shift -# Setup environment -export $__cdist_variable_name="$__cdist_explorer_dir" -export __global="$__cdist_remote_out_dir" + # Write output here + __cdist_my_out_dir="$1"; shift -mkdir -p "$__cdist_my_out_dir" + # Setup environment + export $__cdist_variable_name="$__cdist_explorer_dir" + export __global="$__cdist_remote_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 + mkdir -p "$__cdist_my_out_dir" -# Execute all explorers -for explorer in "$__cdist_explorer_dir/"*; do - explorer_name="${explorer##*/}" - - if [ -f "$explorer" ]; then - if [ ! -x "$explorer" ]; then - __cdist_exit_err "Explorer \"$explorer\" exists, but is not executable." - fi - - # Execute explorers and save results in remote destination directory - "$explorer" > "${__cdist_my_out_dir}/$explorer_name" - else - if [ -e "$explorer" ]; then - __cdist_exit_err "Explorer \"$explorer\" exists, but is not a file." - fi + # 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 -done + + # Execute all explorers + for explorer in "$__cdist_explorer_dir/"*; do + explorer_name="${explorer##*/}" + + if [ -f "$explorer" ]; then + if [ ! -x "$explorer" ]; then + __cdist_exit_err "Explorer \"$explorer\" exists, but is not executable." + fi + + # Execute explorers and save results in remote destination directory + "$explorer" > "${__cdist_my_out_dir}/$explorer_name" + else + if [ -e "$explorer" ]; then + __cdist_exit_err "Explorer \"$explorer\" exists, but is not a file." + fi + fi + done +} diff --git a/core/__cdist_code_run b/core/__cdist_code_run index 6a1b916b..ca73b02d 100755 --- a/core/__cdist_code_run +++ b/core/__cdist_code_run @@ -23,7 +23,6 @@ __cdist_code_run() { - [ $# -eq 2 ] || __cdist_usage " " __cdist_object_self="$1"; shift @@ -49,4 +48,7 @@ __cdist_code_run() __cdist_exit_err "$__cdist_code exists, but is not a file." fi fi + + # Exit gracefully if nothing is todo + true } diff --git a/core/__cdist_object_gencode b/core/__cdist_object_gencode index 585c9d9d..1024f2c5 100755 --- a/core/__cdist_object_gencode +++ b/core/__cdist_object_gencode @@ -28,7 +28,6 @@ __cdist_object_gencode() { - __cdist_myname="foo" [ $# -eq 2 ] || __cdist_usage "" "" __cdist_object_self="$1"; shift diff --git a/core/__cdist_object_run b/core/__cdist_object_run index 07461b23..7f08f192 100755 --- a/core/__cdist_object_run +++ b/core/__cdist_object_run @@ -38,6 +38,8 @@ __cdist_object_run() # Export to non-core for use in manifest and gencode scripts export $__cdist_name_var_self=$__cdist_object_self + # FIXME: BUG: should be named differently! + # FIXME: BUG: I can be called recursively! -> variables are probably already set / overwritten! __cdist_object_finished="$(__cdist_object_finished "$__cdist_object_self")" if [ ! -f "$__cdist_object_finished" ]; then # Resolve dependencies, if any @@ -52,9 +54,12 @@ __cdist_object_run() __cdist_requirement="$1"; shift __cdist_echo info "Resolving requirement $__cdist_requirement" __cdist_object_run "$__cdist_requirement" + echo "done run" done fi + echo "after done" + __cdist_object_gencode_run "$__cdist_object_self" __cdist_dir push "$(__cdist_object_dir "$__cdist_object_self")" \ "$(__cdist_remote_object_dir "$__cdist_object_self")" From cda6c24799dea202e135498fbee0058adbb49d2a Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 14 Jun 2011 11:10:58 +0200 Subject: [PATCH 029/110] new: core/__cdist_remote_explorer_run Signed-off-by: Nico Schottelius --- bin/cdist-explorer-run-global | 4 ++-- .../__cdist_remote_explorer_run | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) rename bin/cdist-remote-explorer-run => core/__cdist_remote_explorer_run (98%) diff --git a/bin/cdist-explorer-run-global b/bin/cdist-explorer-run-global index b13b898f..5e9c5a09 100755 --- a/bin/cdist-explorer-run-global +++ b/bin/cdist-explorer-run-global @@ -23,7 +23,7 @@ . cdist-config [ $# -eq 1 ] || __cdist_usage "" -set -ue +set -uex __cdist_target_host="$1"; shift @@ -33,7 +33,7 @@ __cdist_echo info "Running global explorers " __cdist_dir push "${__cdist_explorer_dir}" "${__cdist_remote_explorer_dir}" # run the initial explorers remotely -__cdist_run_remote cdist-remote-explorer-run \ +__cdist_run_remote __cdist_remote_explorer_run \ "$__cdist_name_var_explorer" "$__cdist_remote_explorer_dir" \ "$__cdist_remote_out_explorer_dir" diff --git a/bin/cdist-remote-explorer-run b/core/__cdist_remote_explorer_run similarity index 98% rename from bin/cdist-remote-explorer-run rename to core/__cdist_remote_explorer_run index 040e36a2..a7958a41 100755 --- a/bin/cdist-remote-explorer-run +++ b/core/__cdist_remote_explorer_run @@ -24,11 +24,9 @@ # and __type_explorers can be submitted :-) # -# FIXME: cleanup! __cdist_remote_explorer_run() { [ $# -eq 3 ] || __cdist_usage " " - set -ue "$__cdist_name_var_object=\"$(__cdist_remote_object_dir "$__cdist_object_self")\"" From 0e7d822d16959581789e75a73649b8500bd86d3c Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 14 Jun 2011 11:14:24 +0200 Subject: [PATCH 030/110] re-add set -e to cdist-config Signed-off-by: Nico Schottelius --- bin/cdist-config | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bin/cdist-config b/bin/cdist-config index fb5b4be9..dc901295 100644 --- a/bin/cdist-config +++ b/bin/cdist-config @@ -24,6 +24,9 @@ __cdist_version="1.7.0" # Fail if something bogus is going on set -u +# Fail if exited non-zero as well +set -e + ################################################################################ # cconf standard vars prefixed with cdist From 0fa95a5adcbe1ee02945f35c41055f1a52ebec20 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 16 Jun 2011 23:58:31 +0200 Subject: [PATCH 031/110] more to fix Signed-off-by: Nico Schottelius --- bin/cdist-explorer-run-global | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/cdist-explorer-run-global b/bin/cdist-explorer-run-global index 5e9c5a09..d578fece 100755 --- a/bin/cdist-explorer-run-global +++ b/bin/cdist-explorer-run-global @@ -33,7 +33,7 @@ __cdist_echo info "Running global explorers " __cdist_dir push "${__cdist_explorer_dir}" "${__cdist_remote_explorer_dir}" # run the initial explorers remotely -__cdist_run_remote __cdist_remote_explorer_run \ +__cdist_run_remote __cdist_remote_explorer_run # FIXME: add object_self!!!! \ "$__cdist_name_var_explorer" "$__cdist_remote_explorer_dir" \ "$__cdist_remote_out_explorer_dir" From 7050342d90eca2e46a3f9ee52310df017e7d3ecb Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 17 Jun 2011 10:30:23 +0200 Subject: [PATCH 032/110] ../bin/cdist-cache -> __cdist_cache Signed-off-by: Nico Schottelius --- bin/cdist-cache => core/__cdist_cache | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) rename bin/cdist-cache => core/__cdist_cache (60%) diff --git a/bin/cdist-cache b/core/__cdist_cache similarity index 60% rename from bin/cdist-cache rename to core/__cdist_cache index ee27ffb4..44c60125 100755 --- a/bin/cdist-cache +++ b/core/__cdist_cache @@ -18,22 +18,17 @@ # along with cdist. If not, see . # # -# Let's build a cconfig tree from a configuration -# And save it into the cache tree +# Save the configuration tree into the local cache # -. cdist-config -[ $# -eq 1 ] || __cdist_usage "" -set -u +__cdist_cache() +{ + # Create base to move into + mkdir -p "${__cdist_local_base_cache_dir}" -__cdist_target_host="$1"; shift - -# Create base to move into -mkdir -p "${__cdist_local_base_cache_dir}" - -# Now determine absolute path -__cdist_ddir="$(__cdist_host_cache_dir "$__cdist_target_host")" - -__cdist_echo info "Saving cache to $__cdist_ddir " -rm -rf "$__cdist_ddir" -mv "$__cdist_local_base_dir" "$__cdist_ddir" + __cdist_echo info \ + "Saving cache to $(__cdist_host_cache_dir "$__cdist_target_host")" + rm -rf "$(__cdist_host_cache_dir "$__cdist_target_host")" + mv "$__cdist_local_base_dir" \ + "$(__cdist_host_cache_dir "$__cdist_target_host")" +} From 1132ec875603e3148a2d9b938461e590a1d73f29 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 17 Jun 2011 10:32:09 +0200 Subject: [PATCH 033/110] cdist-explorer-run-global -> ../core/__cdist_explorer_run_global Signed-off-by: Nico Schottelius --- .../__cdist_explorer_run_global | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) rename bin/cdist-explorer-run-global => core/__cdist_explorer_run_global (57%) diff --git a/bin/cdist-explorer-run-global b/core/__cdist_explorer_run_global similarity index 57% rename from bin/cdist-explorer-run-global rename to core/__cdist_explorer_run_global index d578fece..8a590164 100755 --- a/bin/cdist-explorer-run-global +++ b/core/__cdist_explorer_run_global @@ -21,22 +21,19 @@ # Copy & run the global explorers, i.e. not bound to types # -. cdist-config -[ $# -eq 1 ] || __cdist_usage "" -set -uex +__cdist_explorer_run_global() +{ + __cdist_echo info "Running global explorers " -__cdist_target_host="$1"; shift + # copy the explorers + __cdist_dir push "${__cdist_explorer_dir}" "${__cdist_remote_explorer_dir}" -__cdist_echo info "Running global explorers " - -# copy the explorers -__cdist_dir push "${__cdist_explorer_dir}" "${__cdist_remote_explorer_dir}" - -# run the initial explorers remotely -__cdist_run_remote __cdist_remote_explorer_run # FIXME: add object_self!!!! \ - "$__cdist_name_var_explorer" "$__cdist_remote_explorer_dir" \ - "$__cdist_remote_out_explorer_dir" + # run the initial explorers remotely + __cdist_run_remote __cdist_remote_explorer_run # FIXME: add object_self!!!! \ + "$__cdist_name_var_explorer" "$__cdist_remote_explorer_dir" \ + "$__cdist_remote_out_explorer_dir" -# retrieve the results -__cdist_dir pull "${__cdist_remote_out_explorer_dir}" "${__cdist_out_explorer_dir}" + # retrieve the results + __cdist_dir pull "${__cdist_remote_out_explorer_dir}" "${__cdist_out_explorer_dir}" +} From d680c8a5f1474426a924b59c2ff0ffbc1905cdcd Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 17 Jun 2011 10:34:52 +0200 Subject: [PATCH 034/110] corelib will go into cdist 1.8.0, if at all Signed-off-by: Nico Schottelius --- bin/cdist-config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/cdist-config b/bin/cdist-config index dc901295..84593948 100644 --- a/bin/cdist-config +++ b/bin/cdist-config @@ -19,7 +19,7 @@ # # -__cdist_version="1.7.0" +__cdist_version="1.8.0" # Fail if something bogus is going on set -u From 7d6b1b523612a9550d46124d17374c17c0e958d5 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 17 Jun 2011 10:36:44 +0200 Subject: [PATCH 035/110] ../bin/cdist-config -> core/__cdist_init_deploy Signed-off-by: Nico Schottelius --- bin/cdist-config | 15 --------------- core/__cdist_init_deploy | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 15 deletions(-) create mode 100755 core/__cdist_init_deploy diff --git a/bin/cdist-config b/bin/cdist-config index 84593948..13cba8c5 100644 --- a/bin/cdist-config +++ b/bin/cdist-config @@ -226,21 +226,6 @@ ___cdist_lib_path() echo $_ } -__cdist_init_deploy() -{ - __cdist_echo info "Creating clean directory structure " - - # Ensure there is no old stuff, neither local nor remote - rm -rf "$__cdist_local_base_dir" - ssh "${__cdist_remote_user}@$1" "rm -rf ${__cdist_remote_base_dir}" - - # Init base - mkdir -p "$__cdist_local_base_dir" - ssh "${__cdist_remote_user}@$1" "mkdir -p ${__cdist_remote_base_dir}" - - # Link configuration source directory - consistent with remote - ln -sf "$__cdist_conf_dir" "$__cdist_local_base_dir/$__cdist_name_conf_dir" -} ################################################################################ # Cache diff --git a/core/__cdist_init_deploy b/core/__cdist_init_deploy new file mode 100755 index 00000000..88545f59 --- /dev/null +++ b/core/__cdist_init_deploy @@ -0,0 +1,38 @@ +#!/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 . +# +# +# Prepare deployment +# + +__cdist_init_deploy() +{ + __cdist_echo info "Creating clean directory structure " + + # Ensure there is no old stuff, neither local nor remote + rm -rf "$__cdist_local_base_dir" + ssh "${__cdist_remote_user}@$1" "rm -rf ${__cdist_remote_base_dir}" + + # Init base + mkdir -p "$__cdist_local_base_dir" + ssh "${__cdist_remote_user}@$1" "mkdir -p ${__cdist_remote_base_dir}" + + # Link configuration source directory - consistent with remote + ln -sf "$__cdist_conf_dir" "$__cdist_local_base_dir/$__cdist_name_conf_dir" +} From 75bff0b13fa7fcbe50d217af08d3c964788f8b28 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 17 Jun 2011 10:40:28 +0200 Subject: [PATCH 036/110] +cleanup Signed-off-by: Nico Schottelius --- core/__cdist_init_deploy | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/__cdist_init_deploy b/core/__cdist_init_deploy index 88545f59..4ac3168c 100755 --- a/core/__cdist_init_deploy +++ b/core/__cdist_init_deploy @@ -27,11 +27,13 @@ __cdist_init_deploy() # Ensure there is no old stuff, neither local nor remote rm -rf "$__cdist_local_base_dir" - ssh "${__cdist_remote_user}@$1" "rm -rf ${__cdist_remote_base_dir}" + ssh "${__cdist_remote_user}@${__cdist_target_host}" \ + "rm -rf ${__cdist_remote_base_dir}" # Init base mkdir -p "$__cdist_local_base_dir" - ssh "${__cdist_remote_user}@$1" "mkdir -p ${__cdist_remote_base_dir}" + ssh "${__cdist_remote_user}@${__cdist_target_host}" \ + "mkdir -p ${__cdist_remote_base_dir}" # Link configuration source directory - consistent with remote ln -sf "$__cdist_conf_dir" "$__cdist_local_base_dir/$__cdist_name_conf_dir" From f3a88ef98d156bbbbc5fa5f07fc71cef7e58d9e5 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 17 Jun 2011 12:31:00 +0200 Subject: [PATCH 037/110] ../bin/cdist-config -> __cdist_echo Signed-off-by: Nico Schottelius --- bin/cdist-config | 35 --------------------------- bin/cdist-deploy-to | 4 ++-- core/__cdist_echo | 58 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 37 deletions(-) create mode 100755 core/__cdist_echo diff --git a/bin/cdist-config b/bin/cdist-config index 13cba8c5..74d9eed7 100644 --- a/bin/cdist-config +++ b/bin/cdist-config @@ -162,41 +162,6 @@ for __cdist_lib in $__cdist_core_dir/*; do . "$__cdist_lib" done -__cdist_echo() -{ - __cdist_echo_type="$1"; shift - - set +u - if [ "$__cdist_object_self" ]; then - __cdist_echo_prefix="${__cdist_object_self}:" - else - __cdist_echo_prefix="core: " - fi - set -u - - case "$__cdist_echo_type" in - debug) - set +u - if [ "$__cdist_debug" ]; then - echo $__cdist_echo_prefix "Debug: $@" - fi - set -u - ;; - info) - echo $__cdist_echo_prefix "$@" - ;; - warn) - echo $__cdist_echo_prefix "Warning: $@" - ;; - error) - echo $__cdist_echo_prefix "Error: $@" >&2 - ;; - *) - echo "CORE BUG, who created the broken commit in $0?" >&2 - exit 23 - ;; - esac -} __cdist_exec_fail_on_error() { diff --git a/bin/cdist-deploy-to b/bin/cdist-deploy-to index baeff220..cf286564 100755 --- a/bin/cdist-deploy-to +++ b/bin/cdist-deploy-to @@ -36,8 +36,6 @@ export $__cdist_name_var_target_user="$__cdist_remote_user" # Export variables for core, which others do not reset export __cdist_local_base_dir - -# Load library always from the checkout export __cdist_core_dir __cdist_echo info "cdist $__cdist_version: Configuring $__cdist_target_host " @@ -49,6 +47,8 @@ __cdist_echo info "cdist $__cdist_version: Configuring $__cdist_target_host " # Prepare local and remote directories __cdist_init_deploy "$__cdist_target_host" +FIXME: stopped here! + # Transfer cdist executables __cdist_echo info "Transferring cdist binaries/functions to the target host " __cdist_dir push "${__cdist_abs_mydir}" "${__cdist_remote_bin_dir}" diff --git a/core/__cdist_echo b/core/__cdist_echo new file mode 100755 index 00000000..2fcc93f0 --- /dev/null +++ b/core/__cdist_echo @@ -0,0 +1,58 @@ +#!/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 . +# +# +# echo / syslog alike function +# + +__cdist_echo() +{ + __cdist_echo_type="$1"; shift + + set +u + if [ "$__cdist_object_self" ]; then + __cdist_echo_prefix="${__cdist_object_self}:" + else + __cdist_echo_prefix="core: " + fi + set -u + + case "$__cdist_echo_type" in + debug) + set +u + if [ "$__cdist_debug" ]; then + echo $__cdist_echo_prefix "Debug: $@" + fi + set -u + ;; + info) + echo $__cdist_echo_prefix "$@" + ;; + warn) + echo $__cdist_echo_prefix "Warning: $@" + ;; + error) + echo $__cdist_echo_prefix "Error: $@" >&2 + ;; + *) + echo "CORE BUG, who created the broken commit in $0?" >&2 + exit 23 + ;; + esac +} From c474317a6aee84152a7b39762c3bc070225d89e6 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 17 Jun 2011 12:34:40 +0200 Subject: [PATCH 038/110] migrate more stuff from cdist-config to core/ Signed-off-by: Nico Schottelius --- bin/cdist-config | 24 ---------------------- core/__cdist_exec_fail_on_error | 35 +++++++++++++++++++++++++++++++++ core/__cdist_exit_err | 28 ++++++++++++++++++++++++++ core/__cdist_usage | 27 +++++++++++++++++++++++++ 4 files changed, 90 insertions(+), 24 deletions(-) create mode 100755 core/__cdist_exec_fail_on_error create mode 100755 core/__cdist_exit_err create mode 100755 core/__cdist_usage diff --git a/bin/cdist-config b/bin/cdist-config index 74d9eed7..a8f32dc1 100644 --- a/bin/cdist-config +++ b/bin/cdist-config @@ -162,30 +162,6 @@ for __cdist_lib in $__cdist_core_dir/*; do . "$__cdist_lib" done - -__cdist_exec_fail_on_error() -{ - set +e - sh -e "$@" - if [ "$?" -ne 0 ]; then - __cdist_echo error "$1 exited non-zero" - __cdist_echo warn "Faulty code:" - cat "$1" - __cdist_exit_err "Aborting due to non-zero exit code." - fi -} - -__cdist_exit_err() -{ - __cdist_echo error "$@" - exit 1 -} - -__cdist_usage() -{ - __cdist_exit_err "$__cdist_myname: $@" -} - ___cdist_lib_path() { echo $_ diff --git a/core/__cdist_exec_fail_on_error b/core/__cdist_exec_fail_on_error new file mode 100755 index 00000000..96e5f056 --- /dev/null +++ b/core/__cdist_exec_fail_on_error @@ -0,0 +1,35 @@ +#!/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 . +# +# +# Exit if an error occurs +# + +__cdist_exec_fail_on_error() +{ + set +e + sh -e "$@" + if [ "$?" -ne 0 ]; then + __cdist_echo error "$1 exited non-zero" + __cdist_echo warn "Faulty code:" + cat "$1" + __cdist_exit_err "Aborting due to non-zero exit code." + fi + set -e +} diff --git a/core/__cdist_exit_err b/core/__cdist_exit_err new file mode 100755 index 00000000..303dbf20 --- /dev/null +++ b/core/__cdist_exit_err @@ -0,0 +1,28 @@ +#!/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 . +# +# +# Print error and exit (perror() alike) +# + +__cdist_exit_err() +{ + __cdist_echo error "$@" + exit 1 +} diff --git a/core/__cdist_usage b/core/__cdist_usage new file mode 100755 index 00000000..9dfa30e4 --- /dev/null +++ b/core/__cdist_usage @@ -0,0 +1,27 @@ +#!/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 . +# +# +# Print error and exit (perror() alike) +# + +__cdist_usage() +{ + __cdist_exit_err "$__cdist_myname: $@" +} From 29450e5e99ca4d7ece84d93aa863b52dfd0376cf Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 17 Jun 2011 12:49:02 +0200 Subject: [PATCH 039/110] add __cdist_explorer_run, which should replace __cdist_remote_explorer_run Signed-off-by: Nico Schottelius --- core/__cdist_explorer_run | 71 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100755 core/__cdist_explorer_run diff --git a/core/__cdist_explorer_run b/core/__cdist_explorer_run new file mode 100755 index 00000000..a7958a41 --- /dev/null +++ b/core/__cdist_explorer_run @@ -0,0 +1,71 @@ +#!/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_remote_explorer_run() +{ + [ $# -eq 3 ] || __cdist_usage " " + + "$__cdist_name_var_object=\"$(__cdist_remote_object_dir "$__cdist_object_self")\"" + + # 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 + + # Setup environment + export $__cdist_variable_name="$__cdist_explorer_dir" + export __global="$__cdist_remote_out_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 + __cdist_exit_err "Explorer \"$explorer\" exists, but is not executable." + fi + + # Execute explorers and save results in remote destination directory + "$explorer" > "${__cdist_my_out_dir}/$explorer_name" + else + if [ -e "$explorer" ]; then + __cdist_exit_err "Explorer \"$explorer\" exists, but is not a file." + fi + fi + done +} From a277d5a4d4e00f57628227fc24f2d982952768d4 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 17 Jun 2011 13:00:50 +0200 Subject: [PATCH 040/110] some ideas about future design Signed-off-by: Nico Schottelius --- doc/dev/logs/2011-06-17.design-ideas | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 doc/dev/logs/2011-06-17.design-ideas diff --git a/doc/dev/logs/2011-06-17.design-ideas b/doc/dev/logs/2011-06-17.design-ideas new file mode 100644 index 00000000..0a59b743 --- /dev/null +++ b/doc/dev/logs/2011-06-17.design-ideas @@ -0,0 +1,7 @@ +Should __run_remote be used or should the workflow more be +"I'm working here, part of it is executed remote?" + +Indirect call to functions like __cdist_remote_explorer_run are +partly hard to debug / think about. + +Setting up variables is needed for non-core (i.e. explorers) From 4fbe2a26766ebd30380b22e2a4de3a21b25d7bba Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 17 Jun 2011 13:01:03 +0200 Subject: [PATCH 041/110] begin work on __cdist_explorer_run Signed-off-by: Nico Schottelius --- bin/cdist-deploy-to | 4 +--- core/__cdist_explorer_run | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/bin/cdist-deploy-to b/bin/cdist-deploy-to index cf286564..dc20b971 100755 --- a/bin/cdist-deploy-to +++ b/bin/cdist-deploy-to @@ -47,14 +47,12 @@ __cdist_echo info "cdist $__cdist_version: Configuring $__cdist_target_host " # Prepare local and remote directories __cdist_init_deploy "$__cdist_target_host" -FIXME: stopped here! - # Transfer cdist executables __cdist_echo info "Transferring cdist binaries/functions to the target host " __cdist_dir push "${__cdist_abs_mydir}" "${__cdist_remote_bin_dir}" __cdist_dir push "${__cdist_core_dir}" "${__cdist_remote_core_dir}" -cdist-explorer-run-global "$__cdist_target_host" +__cdist_explorer_run_global __cdist_manifest_run_init __cdist_object_all __cdist_object_prepare __cdist_object_all __cdist_object_run diff --git a/core/__cdist_explorer_run b/core/__cdist_explorer_run index a7958a41..4a6a011d 100755 --- a/core/__cdist_explorer_run +++ b/core/__cdist_explorer_run @@ -24,7 +24,7 @@ # and __type_explorers can be submitted :-) # -__cdist_remote_explorer_run() +__cdist_explorer_run() { [ $# -eq 3 ] || __cdist_usage " " From 6a37d58cc8d109fe6aec92026a087541ea416be8 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 17 Jun 2011 14:13:12 +0200 Subject: [PATCH 042/110] more thoughts Signed-off-by: Nico Schottelius --- doc/dev/logs/2011-06-17.design-ideas | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/dev/logs/2011-06-17.design-ideas b/doc/dev/logs/2011-06-17.design-ideas index 0a59b743..26845360 100644 --- a/doc/dev/logs/2011-06-17.design-ideas +++ b/doc/dev/logs/2011-06-17.design-ideas @@ -5,3 +5,5 @@ Indirect call to functions like __cdist_remote_explorer_run are partly hard to debug / think about. Setting up variables is needed for non-core (i.e. explorers) + + From 141b80860367e070ae756122a188983dfb0e03eb Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 17 Jun 2011 14:16:43 +0200 Subject: [PATCH 043/110] do not use cdist-remote always Signed-off-by: Nico Schottelius --- core/__cdist_run_remote | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/__cdist_run_remote b/core/__cdist_run_remote index 3af7c540..17074049 100755 --- a/core/__cdist_run_remote +++ b/core/__cdist_run_remote @@ -28,5 +28,5 @@ __cdist_run_remote() ssh "${__cdist_remote_user}@${__cdist_target_host}" \ "export PATH=\"${__cdist_remote_bin_dir}:\$PATH\";" \ "export __cdist_out_object_dir=\"$__cdist_remote_out_object_dir\";" \ - "cdist-remote" "$@" + "$@" } From 3c903fae678a1fc783ad6f1052515b5adb98c41b Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 17 Jun 2011 14:27:50 +0200 Subject: [PATCH 044/110] abort execution until global explorers work Signed-off-by: Nico Schottelius --- bin/cdist-deploy-to | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/cdist-deploy-to b/bin/cdist-deploy-to index dc20b971..c48eba57 100755 --- a/bin/cdist-deploy-to +++ b/bin/cdist-deploy-to @@ -53,6 +53,8 @@ __cdist_dir push "${__cdist_abs_mydir}" "${__cdist_remote_bin_dir}" __cdist_dir push "${__cdist_core_dir}" "${__cdist_remote_core_dir}" __cdist_explorer_run_global +exit 1 + __cdist_manifest_run_init __cdist_object_all __cdist_object_prepare __cdist_object_all __cdist_object_run From 83e75666c32d0ced699fa1966475d2f75a796ccb Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 17 Jun 2011 14:28:10 +0200 Subject: [PATCH 045/110] begin integration of type|global support Signed-off-by: Nico Schottelius --- core/__cdist_explorer_run | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/core/__cdist_explorer_run b/core/__cdist_explorer_run index 4a6a011d..6a580af3 100755 --- a/core/__cdist_explorer_run +++ b/core/__cdist_explorer_run @@ -18,20 +18,24 @@ # 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 :-) +# Run explorers # __cdist_explorer_run() { - [ $# -eq 3 ] || __cdist_usage " " + [ $# -eq 3 ] || __cdist_usage " " + + case "$1" in + global) + type) + "$__cdist_name_var_object=\"$(__cdist_remote_object_dir "$__cdist_object_self")\"" + *) + ;; + esac - "$__cdist_name_var_object=\"$(__cdist_remote_object_dir "$__cdist_object_self")\"" # Variable that defines the home of the explorers - __cdist_variable_name="$1"; shift + # __cdist_variable_name="$1"; shift # Find explorers here __cdist_explorer_dir="$1"; shift @@ -39,11 +43,11 @@ __cdist_explorer_run() # Write output here __cdist_my_out_dir="$1"; shift - # Setup environment + # Setup remote environment export $__cdist_variable_name="$__cdist_explorer_dir" export __global="$__cdist_remote_out_dir" - mkdir -p "$__cdist_my_out_dir" + # mkdir -p "$__cdist_my_out_dir" # Ensure there is at least one explorer num="$(ls -1 "$__cdist_explorer_dir" | wc -l)" From a5b97139869203439f9fd4e60b8399e111412bb0 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 17 Jun 2011 14:28:45 +0200 Subject: [PATCH 046/110] ++todo, use new function Signed-off-by: Nico Schottelius --- core/__cdist_explorer_run_global | 6 ++---- doc/dev/logs/2011-06-14.timing | 6 ++++++ doc/dev/todo/niconext | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 doc/dev/logs/2011-06-14.timing diff --git a/core/__cdist_explorer_run_global b/core/__cdist_explorer_run_global index 8a590164..dfbeb6ac 100755 --- a/core/__cdist_explorer_run_global +++ b/core/__cdist_explorer_run_global @@ -28,12 +28,10 @@ __cdist_explorer_run_global() # copy the explorers __cdist_dir push "${__cdist_explorer_dir}" "${__cdist_remote_explorer_dir}" - # run the initial explorers remotely - __cdist_run_remote __cdist_remote_explorer_run # FIXME: add object_self!!!! \ - "$__cdist_name_var_explorer" "$__cdist_remote_explorer_dir" \ + # run the global explorers remotely + __cdist_explorer_run global "$__cdist_remote_explorer_dir" \ "$__cdist_remote_out_explorer_dir" - # retrieve the results __cdist_dir pull "${__cdist_remote_out_explorer_dir}" "${__cdist_out_explorer_dir}" } diff --git a/doc/dev/logs/2011-06-14.timing b/doc/dev/logs/2011-06-14.timing new file mode 100644 index 00000000..dcfd4884 --- /dev/null +++ b/doc/dev/logs/2011-06-14.timing @@ -0,0 +1,6 @@ +ikq04: + +cdist-deploy-to ikq04.ethz.ch 35.44s user 30.65s system 34% cpu 3:11.45 total # also migrate cdist-object-gencode +cdist-deploy-to ikq04.ethz.ch 23.56s user 22.44s system 35% cpu 2:09.78 total # ../bin/cdist-object-all -> __cdist_object_all +cdist-deploy-to ikq04.ethz.ch 17.35s user 16.83s system 30% cpu 1:53.69 total # bin/cdist-object-manifest-run -> core/__cdist_object_manifest_run +cdist-deploy-to ikq04.ethz.ch 19.76s user 23.58s system 35% cpu 2:03.33 total # ../core/__cdist_manifest_run_init diff --git a/doc/dev/todo/niconext b/doc/dev/todo/niconext index ce89c643..1ed887d5 100644 --- a/doc/dev/todo/niconext +++ b/doc/dev/todo/niconext @@ -2,4 +2,19 @@ either make functions available on the other side or put logic on the server side. + - trying to run global explorers nicely from local side + + + - Both type and global have... + - local sourcedir + - remote destination dir + - remote out dir + - local out dir + + - Differences are in... + - variables exposed / submitted + + + + Catch broken instances in cdist-mass-deploy -p and report broken deployements at the end! From 29e029a2ebd60084eb447561509a249e15fdd888 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 17 Jun 2011 14:37:36 +0200 Subject: [PATCH 047/110] replace __cdist_type_has_explorer with __cdist_dir_listing Signed-off-by: Nico Schottelius --- bin/cdist-config | 9 --------- core/__cdist_dir_listing | 30 ++++++++++++++++++++++++++++++ core/__cdist_object_explorer_run | 2 +- 3 files changed, 31 insertions(+), 10 deletions(-) create mode 100755 core/__cdist_dir_listing diff --git a/bin/cdist-config b/bin/cdist-config index a8f32dc1..bed9e6b4 100644 --- a/bin/cdist-config +++ b/bin/cdist-config @@ -330,15 +330,6 @@ __cdist_type_from_object() echo "${1%%/*}" } -__cdist_type_has_explorer() -{ - # We only create output, if there's at least one explorer - # and can thus be used as a boolean ;-) - if [ -d "$(__cdist_type_explorer_dir "$1")" ]; then - ls -1 "$(__cdist_type_explorer_dir "$1")" - fi -} - __cdist_type_explorer_pushed() { [ -f "${__cdist_out_type_dir}/${__cdist_name_type_explorer_pushed}" ] \ diff --git a/core/__cdist_dir_listing b/core/__cdist_dir_listing new file mode 100755 index 00000000..f4aa2320 --- /dev/null +++ b/core/__cdist_dir_listing @@ -0,0 +1,30 @@ +#!/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 . +# +# +# List files in a directory, if it exists +# +# We only create output, if there's at least one entry +# and can thus be used as a boolean ;-) +# + +__cdist_dir_listing() +{ + [ -d "$1" ] && ls -1 "$1" +} diff --git a/core/__cdist_object_explorer_run b/core/__cdist_object_explorer_run index eb62401e..45ca3379 100755 --- a/core/__cdist_object_explorer_run +++ b/core/__cdist_object_explorer_run @@ -30,7 +30,7 @@ __cdist_object_explorer_run() __cdist_type="$(__cdist_type_from_object "$__cdist_object_self")" # Check if type of object has >= 1 explorer - __cdist_has_explorer="$(__cdist_type_has_explorer "$__cdist_type")" + __cdist_has_explorer="$(__cdist_dir_listing "$(__cdist_type_explorer_dir "$__cdist_type")")" # Run the type explorers for the current object if any if [ "$__cdist_has_explorer" ]; then if ! __cdist_type_explorer_pushed "$__cdist_type"; then From 390d527515c1bd1828d76ebd1ab0a613ea3046a6 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 17 Jun 2011 14:51:32 +0200 Subject: [PATCH 048/110] global explorers work again Signed-off-by: Nico Schottelius --- core/__cdist_explorer_run | 40 +++++++++++++++++++++++++------- core/__cdist_explorer_run_global | 9 +++---- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/core/__cdist_explorer_run b/core/__cdist_explorer_run index 6a580af3..a5545faf 100755 --- a/core/__cdist_explorer_run +++ b/core/__cdist_explorer_run @@ -23,15 +23,38 @@ __cdist_explorer_run() { - [ $# -eq 3 ] || __cdist_usage " " + # [ $# -eq 3 ] || __cdist_usage " " + [ $# -eq 5 ] || __cdist_usage " " + set -x - case "$1" in - global) - type) - "$__cdist_name_var_object=\"$(__cdist_remote_object_dir "$__cdist_object_self")\"" - *) - ;; - esac + # Only do something, if there's at least one entry + [ "$(__cdist_dir_listing "$2")" ] || return + + # Transfer explorers + __cdist_dir push "$2" "$3" + + # Create output directory + __cdist_run_remote mkdir -p "$4" + + # Execute all explorers + cd "$2"; + for __cdist_explorer_run_explorer in *; do + __cdist_run_remote "$3/$__cdist_explorer_run_explorer" ">" \ + "$4/$__cdist_explorer_run_explorer" + done + + # Transfer results back + __cdist_dir pull "$4" "$5" + + return + +# case "$1" in +# global) +# type) +# "$__cdist_name_var_object=\"$(__cdist_remote_object_dir "$__cdist_object_self")\"" +# *) +# ;; +# esac # Variable that defines the home of the explorers @@ -47,7 +70,6 @@ __cdist_explorer_run() export $__cdist_variable_name="$__cdist_explorer_dir" export __global="$__cdist_remote_out_dir" - # mkdir -p "$__cdist_my_out_dir" # Ensure there is at least one explorer num="$(ls -1 "$__cdist_explorer_dir" | wc -l)" diff --git a/core/__cdist_explorer_run_global b/core/__cdist_explorer_run_global index dfbeb6ac..7265aee1 100755 --- a/core/__cdist_explorer_run_global +++ b/core/__cdist_explorer_run_global @@ -26,12 +26,13 @@ __cdist_explorer_run_global() __cdist_echo info "Running global explorers " # copy the explorers - __cdist_dir push "${__cdist_explorer_dir}" "${__cdist_remote_explorer_dir}" +# __cdist_dir push "${__cdist_explorer_dir}" "${__cdist_remote_explorer_dir}" # run the global explorers remotely - __cdist_explorer_run global "$__cdist_remote_explorer_dir" \ - "$__cdist_remote_out_explorer_dir" + __cdist_explorer_run global \ + "$__cdist_explorer_dir" "$__cdist_remote_explorer_dir" \ + "$__cdist_remote_out_explorer_dir" "$__cdist_out_explorer_dir" # retrieve the results - __cdist_dir pull "${__cdist_remote_out_explorer_dir}" "${__cdist_out_explorer_dir}" +# __cdist_dir pull "${__cdist_remote_out_explorer_dir}" "${__cdist_out_explorer_dir}" } From bb06a69bd5ecf3b8adc1cadbe082394eead8924b Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 17 Jun 2011 14:52:06 +0200 Subject: [PATCH 049/110] cleanup Signed-off-by: Nico Schottelius --- core/__cdist_explorer_run_global | 6 ------ 1 file changed, 6 deletions(-) diff --git a/core/__cdist_explorer_run_global b/core/__cdist_explorer_run_global index 7265aee1..27359713 100755 --- a/core/__cdist_explorer_run_global +++ b/core/__cdist_explorer_run_global @@ -25,14 +25,8 @@ __cdist_explorer_run_global() { __cdist_echo info "Running global explorers " - # copy the explorers -# __cdist_dir push "${__cdist_explorer_dir}" "${__cdist_remote_explorer_dir}" - # run the global explorers remotely __cdist_explorer_run global \ "$__cdist_explorer_dir" "$__cdist_remote_explorer_dir" \ "$__cdist_remote_out_explorer_dir" "$__cdist_out_explorer_dir" - - # retrieve the results -# __cdist_dir pull "${__cdist_remote_out_explorer_dir}" "${__cdist_out_explorer_dir}" } From f544fc5c42d81d7aadb3d528c80a07119b9f434d Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 17 Jun 2011 15:01:31 +0200 Subject: [PATCH 050/110] next todo Signed-off-by: Nico Schottelius --- doc/dev/todo/niconext | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/dev/todo/niconext b/doc/dev/todo/niconext index 1ed887d5..7c91d865 100644 --- a/doc/dev/todo/niconext +++ b/doc/dev/todo/niconext @@ -2,7 +2,10 @@ either make functions available on the other side or put logic on the server side. - - trying to run global explorers nicely from local side + - trying to run type explorers nicely from local side + - must check whether type directory has been transmitted before! + +-------------------------------------------------------------------------------- - Both type and global have... From eeaab438c25f8d707ef67f8f0e205e7fdd48efeb Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 21 Jun 2011 12:34:18 +0200 Subject: [PATCH 051/110] logfile Signed-off-by: Nico Schottelius --- doc/dev/logs/2011-06-21.execute_remote | 38 ++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 doc/dev/logs/2011-06-21.execute_remote diff --git a/doc/dev/logs/2011-06-21.execute_remote b/doc/dev/logs/2011-06-21.execute_remote new file mode 100644 index 00000000..61292688 --- /dev/null +++ b/doc/dev/logs/2011-06-21.execute_remote @@ -0,0 +1,38 @@ +Steven, Nico: + +Problem: + How to execute a function instead of binary + +Solutions: + + 1) + ( + cat $lib/* + cat bin/cdist-config + echo $function $args + ) | ssh foo + + 2) + scp $dir/lib.sh root@foo:/tmp/lib.sh + cat << DONE | ssh root@foo sh + source /tmp/lib.sh + DONE + + 3) follow up to 1) + __run_remote() + { + cat << eof | ssh foo + + . /cdist-config + "$@" # NOT USABLE, no export = export = lines possible! + + eof + + +Problems found and solved: + + - remote shell cannot work due to multi line variable export + - caching library directory with scp + - create function for every remote action + -> prepares environment + From a53782805dd9a811cbff53d340d1af47a717dc74 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 23 Jun 2011 12:13:46 +0200 Subject: [PATCH 052/110] ++log Signed-off-by: Nico Schottelius --- doc/dev/logs/2011-06-21.execute_remote | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/doc/dev/logs/2011-06-21.execute_remote b/doc/dev/logs/2011-06-21.execute_remote index 61292688..a9c88df2 100644 --- a/doc/dev/logs/2011-06-21.execute_remote +++ b/doc/dev/logs/2011-06-21.execute_remote @@ -12,12 +12,19 @@ Solutions: echo $function $args ) | ssh foo + Works partly, does not work for export = ... + Needs to copy over lib every time again! + 2) scp $dir/lib.sh root@foo:/tmp/lib.sh cat << DONE | ssh root@foo sh source /tmp/lib.sh + export foo=bla + function args DONE + Caches lib directory + 3) follow up to 1) __run_remote() { @@ -28,6 +35,22 @@ Solutions: eof + 4) final solution + - write for every remote job a new function + - this functions prepares env + reuses ssh header + + __cdist_remote_explorer() + { + cat << eof + $__cdist_remote_header + export foo1=bar + export foo2=bar + export foo3=bar + + "$@" + eof | __cdist_ssh + } + Problems found and solved: From b06f6be5a6d52d9737a0cec37445d423bd4d70d6 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 26 Jul 2011 23:39:53 +0200 Subject: [PATCH 053/110] begin to re-do __explorer and __global on remote side with functions Signed-off-by: Nico Schottelius --- core/__cdist_explorer_run | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/core/__cdist_explorer_run b/core/__cdist_explorer_run index a5545faf..db5f2e2c 100755 --- a/core/__cdist_explorer_run +++ b/core/__cdist_explorer_run @@ -39,8 +39,13 @@ __cdist_explorer_run() # Execute all explorers cd "$2"; for __cdist_explorer_run_explorer in *; do - __cdist_run_remote "$3/$__cdist_explorer_run_explorer" ">" \ - "$4/$__cdist_explorer_run_explorer" + #BUG: need to export __explorer to remote side! + #exit 23 + __cdist_run_remote \ + "export $__cdist_name_var_explorer=\"$__cdist_remote_explorer_dir\";" \ + "export $__cdist_name_var_global=\"$__cdist_remote_out_dir\";" \ + "$3/$__cdist_explorer_run_explorer" > \ + "$4/$__cdist_explorer_run_explorer" done # Transfer results back From 666744209e32f7706631b1dc8c3bad1bd96785bd Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 26 Jul 2011 23:42:09 +0200 Subject: [PATCH 054/110] running explorers works again Signed-off-by: Nico Schottelius --- core/__cdist_explorer_run | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/__cdist_explorer_run b/core/__cdist_explorer_run index db5f2e2c..51e606b1 100755 --- a/core/__cdist_explorer_run +++ b/core/__cdist_explorer_run @@ -41,10 +41,12 @@ __cdist_explorer_run() for __cdist_explorer_run_explorer in *; do #BUG: need to export __explorer to remote side! #exit 23 + # BUG: no need for remote out dir probably? + # or should we leave it and continue using __cdist_dir pull? __cdist_run_remote \ "export $__cdist_name_var_explorer=\"$__cdist_remote_explorer_dir\";" \ "export $__cdist_name_var_global=\"$__cdist_remote_out_dir\";" \ - "$3/$__cdist_explorer_run_explorer" > \ + "$3/$__cdist_explorer_run_explorer" ">" \ "$4/$__cdist_explorer_run_explorer" done From 4a5c161e96a6d0806cfd00923df969cd0cf4de09 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 26 Jul 2011 23:46:05 +0200 Subject: [PATCH 055/110] ideas of unit testing Signed-off-by: Nico Schottelius --- test/README | 4 ++++ test/fail_if_explorer_fails.sh | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 test/README create mode 100755 test/fail_if_explorer_fails.sh diff --git a/test/README b/test/README new file mode 100644 index 00000000..ce5cde4d --- /dev/null +++ b/test/README @@ -0,0 +1,4 @@ +This directory should contain unit tests. + +I have not yet searched (or found) a good way to implement this for cdist, +feel free to take the hat. diff --git a/test/fail_if_explorer_fails.sh b/test/fail_if_explorer_fails.sh new file mode 100755 index 00000000..3acfdbeb --- /dev/null +++ b/test/fail_if_explorer_fails.sh @@ -0,0 +1,25 @@ +#!/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 . +# +# + +. cdist-config + +mkdir -p /tmp/cdist/... +__cdist_explorer_run global From cfd0f776c901e47cd317553e2065956ed5db7236 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 27 Jul 2011 00:00:31 +0200 Subject: [PATCH 056/110] disable removal of temp data for debugging Signed-off-by: Nico Schottelius --- bin/cdist-config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/cdist-config b/bin/cdist-config index bed9e6b4..0c72727f 100644 --- a/bin/cdist-config +++ b/bin/cdist-config @@ -296,7 +296,7 @@ __cdist_remote_type_explorer_dir() # __cdist_tmp_removal() { - rm -rf "${__cdist_tmp_dir}" + echo rm -rf "${__cdist_tmp_dir}" } # Does not work in children, will be called again in every script! From 197fa583b58985505b0320e90355e8a766226d8f Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 27 Jul 2011 00:06:24 +0200 Subject: [PATCH 057/110] finish global explorer part - works again! Signed-off-by: Nico Schottelius --- core/__cdist_explorer_run | 87 ++++++++++++++------------------------- 1 file changed, 32 insertions(+), 55 deletions(-) diff --git a/core/__cdist_explorer_run b/core/__cdist_explorer_run index 51e606b1..d6cd29c9 100755 --- a/core/__cdist_explorer_run +++ b/core/__cdist_explorer_run @@ -27,8 +27,21 @@ __cdist_explorer_run() [ $# -eq 5 ] || __cdist_usage " " set -x - # Only do something, if there's at least one entry - [ "$(__cdist_dir_listing "$2")" ] || return + # 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 + + # Check whether to setup variable for type explorer + case "$1" in + global) + ;; + type) + # FIXME: think about how and where this gets setup! + "$__cdist_name_var_object=\"$(__cdist_remote_object_dir "$__cdist_object_self")\"" + ;; + esac # Transfer explorers __cdist_dir push "$2" "$3" @@ -38,67 +51,31 @@ __cdist_explorer_run() # Execute all explorers cd "$2"; + # FIXME: cleanup double variable, no need when in directory for __cdist_explorer_run_explorer in *; do - #BUG: need to export __explorer to remote side! - #exit 23 - # BUG: no need for remote out dir probably? + __cdist_explorer_explorer_name="${__cdist_explorer_run_explorer##*/}" + + if [ -f "$__cdist_explorer_run_explorer" ]; then + if [ ! -x "$__cdist_explorer_run_explorer" ]; then + __cdist_exit_err "Explorer \"$__cdist_explorer_run_explorer\" exists, but is not executable." + fi + + else + if [ -e "$__cdist_explorer_run_explorer" ]; then + __cdist_exit_err "Explorer \"$__cdist_explorer_run_explorer\" exists, but is not a file." + fi + fi + + # FIXME: no need for remote out dir probably? # or should we leave it and continue using __cdist_dir pull? __cdist_run_remote \ "export $__cdist_name_var_explorer=\"$__cdist_remote_explorer_dir\";" \ "export $__cdist_name_var_global=\"$__cdist_remote_out_dir\";" \ "$3/$__cdist_explorer_run_explorer" ">" \ - "$4/$__cdist_explorer_run_explorer" + "$4/$__cdist_explorer_run_explorer" || \ + __cdist_exit_err "Explorer $__cdist_explorer_run_explorer failed." done # Transfer results back __cdist_dir pull "$4" "$5" - - return - -# case "$1" in -# global) -# type) -# "$__cdist_name_var_object=\"$(__cdist_remote_object_dir "$__cdist_object_self")\"" -# *) -# ;; -# esac - - - # 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 - - # Setup remote environment - export $__cdist_variable_name="$__cdist_explorer_dir" - export __global="$__cdist_remote_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 - __cdist_exit_err "Explorer \"$explorer\" exists, but is not executable." - fi - - # Execute explorers and save results in remote destination directory - "$explorer" > "${__cdist_my_out_dir}/$explorer_name" - else - if [ -e "$explorer" ]; then - __cdist_exit_err "Explorer \"$explorer\" exists, but is not a file." - fi - fi - done } From 41a0c1dc8ae14964376f89090a3925654eeac025 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 27 Jul 2011 00:07:44 +0200 Subject: [PATCH 058/110] cleanup/continue Signed-off-by: Nico Schottelius --- bin/cdist-deploy-to | 2 +- core/__cdist_explorer_run | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/bin/cdist-deploy-to b/bin/cdist-deploy-to index c48eba57..67bc4ba0 100755 --- a/bin/cdist-deploy-to +++ b/bin/cdist-deploy-to @@ -53,9 +53,9 @@ __cdist_dir push "${__cdist_abs_mydir}" "${__cdist_remote_bin_dir}" __cdist_dir push "${__cdist_core_dir}" "${__cdist_remote_core_dir}" __cdist_explorer_run_global +__cdist_manifest_run_init exit 1 -__cdist_manifest_run_init __cdist_object_all __cdist_object_prepare __cdist_object_all __cdist_object_run __cdist_cache diff --git a/core/__cdist_explorer_run b/core/__cdist_explorer_run index d6cd29c9..c93b348f 100755 --- a/core/__cdist_explorer_run +++ b/core/__cdist_explorer_run @@ -23,9 +23,7 @@ __cdist_explorer_run() { - # [ $# -eq 3 ] || __cdist_usage " " [ $# -eq 5 ] || __cdist_usage " " - set -x # Ensure there is at least one explorer num="$(ls -1 "$__cdist_explorer_dir" | wc -l)" From 67ba0f7e9ff856342d2048822f6a42af9daccddb Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 27 Jul 2011 00:14:04 +0200 Subject: [PATCH 059/110] do not use __global directly; manifest run works Signed-off-by: Nico Schottelius --- core/__cdist_manifest_run | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/__cdist_manifest_run b/core/__cdist_manifest_run index 76d0a934..aa8c56e3 100755 --- a/core/__cdist_manifest_run +++ b/core/__cdist_manifest_run @@ -1,6 +1,6 @@ #!/bin/sh # -# 2010 Nico Schottelius (nico-cdist at schottelius.org) +# 2010-2011 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -39,7 +39,7 @@ __cdist_manifest_run() export __cdist_manifest # Export information for manifests - __cdist_out_dir comes from cdist-config - export __global="$__cdist_out_dir" + export $__cdist_name_var_global="$__cdist_out_dir" ################################################################################ # The actual run From 8ad8ce162fe66f72ccaf04b67ae59bc3e71214cb Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 27 Jul 2011 01:03:51 +0200 Subject: [PATCH 060/110] -legacy Signed-off-by: Nico Schottelius --- core/__cdist_remote_explorer_run | 4 ---- 1 file changed, 4 deletions(-) diff --git a/core/__cdist_remote_explorer_run b/core/__cdist_remote_explorer_run index a7958a41..2fc0f999 100755 --- a/core/__cdist_remote_explorer_run +++ b/core/__cdist_remote_explorer_run @@ -39,10 +39,6 @@ __cdist_remote_explorer_run() # Write output here __cdist_my_out_dir="$1"; shift - # Setup environment - export $__cdist_variable_name="$__cdist_explorer_dir" - export __global="$__cdist_remote_out_dir" - mkdir -p "$__cdist_my_out_dir" # Ensure there is at least one explorer From 6d3053a9bc855e3c2413093a8af08ec3ff583422 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 27 Jul 2011 01:22:54 +0200 Subject: [PATCH 061/110] fix type explorer: working again Signed-off-by: Nico Schottelius --- bin/cdist-deploy-to | 2 +- core/__cdist_object_explorer_run | 40 +++++++++++++++---- core/__cdist_remote_explorer_run | 67 -------------------------------- 3 files changed, 33 insertions(+), 76 deletions(-) delete mode 100755 core/__cdist_remote_explorer_run diff --git a/bin/cdist-deploy-to b/bin/cdist-deploy-to index 67bc4ba0..781c15c4 100755 --- a/bin/cdist-deploy-to +++ b/bin/cdist-deploy-to @@ -54,9 +54,9 @@ __cdist_dir push "${__cdist_core_dir}" "${__cdist_remote_core_dir}" __cdist_explorer_run_global __cdist_manifest_run_init +__cdist_object_all __cdist_object_prepare exit 1 -__cdist_object_all __cdist_object_prepare __cdist_object_all __cdist_object_run __cdist_cache diff --git a/core/__cdist_object_explorer_run b/core/__cdist_object_explorer_run index 45ca3379..1f266dca 100755 --- a/core/__cdist_object_explorer_run +++ b/core/__cdist_object_explorer_run @@ -22,6 +22,8 @@ # Run the explorers for the given object on the target host. # +# FIXME: many cleanups needed before going production! + __cdist_object_explorer_run() { __cdist_object_self="$1"; shift @@ -49,14 +51,36 @@ __cdist_object_explorer_run() "$(__cdist_remote_object_parameter_dir "$__cdist_object_self")" # Execute explorers - __cdist_run_remote \ - "$__cdist_name_var_object=\"$(__cdist_remote_object_dir "$__cdist_object_self")\"" \ - "$__cdist_name_var_object_id=\"$__cdist_object_id\"" \ - "$__cdist_name_var_self=\"$__cdist_object_self\"" \ - cdist-remote-explorer-run \ - "$__cdist_name_var_type_explorer" \ - "$(__cdist_remote_type_explorer_dir "$__cdist_type")" \ - "$(__cdist_remote_object_type_explorer_dir "$__cdist_object_self")" + # FIXME: STOPPED: + # - remove cdist-remote-explorer-run + # - problem: new variables / need to run explorer directly? + # -> or put logic into __cdist_explorer_run + # -> think about having _one_ wrapper script for remote to execute + # shell functions + + # Create remote output directory + __cdist_run_remote mkdir -p "$(__cdist_remote_object_type_explorer_dir "$__cdist_object_self")" + + cd "$(__cdist_type_explorer_dir "$__cdist_type")" + + + for __cdist_object_explorer_run_explorer in *; do + __cdist_run_remote \ + "$__cdist_name_var_object=\"$(__cdist_remote_object_dir "$__cdist_object_self")\"" \ + "$__cdist_name_var_object_id=\"$__cdist_object_id\"" \ + "$__cdist_name_var_self=\"$__cdist_object_self\"" \ + "$(__cdist_remote_type_explorer_dir "$__cdist_type")/$__cdist_object_explorer_run_explorer" \ + ">" "$(__cdist_remote_object_type_explorer_dir "$__cdist_object_self")/$__cdist_object_explorer_run_explorer" + done + +# __cdist_run_remote \ +# "$__cdist_name_var_object=\"$(__cdist_remote_object_dir "$__cdist_object_self")\"" \ +# "$__cdist_name_var_object_id=\"$__cdist_object_id\"" \ +# "$__cdist_name_var_self=\"$__cdist_object_self\"" \ +# cdist-remote-explorer-run \ +# "$__cdist_name_var_type_explorer" \ +# "$(__cdist_remote_type_explorer_dir "$__cdist_type")" \ +# "$(__cdist_remote_object_type_explorer_dir "$__cdist_object_self")" # Copy back results __cdist_dir pull "$(__cdist_remote_object_type_explorer_dir "$__cdist_object_self")" \ diff --git a/core/__cdist_remote_explorer_run b/core/__cdist_remote_explorer_run deleted file mode 100755 index 2fc0f999..00000000 --- a/core/__cdist_remote_explorer_run +++ /dev/null @@ -1,67 +0,0 @@ -#!/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_remote_explorer_run() -{ - [ $# -eq 3 ] || __cdist_usage " " - - "$__cdist_name_var_object=\"$(__cdist_remote_object_dir "$__cdist_object_self")\"" - - # 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 - - 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 - __cdist_exit_err "Explorer \"$explorer\" exists, but is not executable." - fi - - # Execute explorers and save results in remote destination directory - "$explorer" > "${__cdist_my_out_dir}/$explorer_name" - else - if [ -e "$explorer" ]; then - __cdist_exit_err "Explorer \"$explorer\" exists, but is not a file." - fi - fi - done -} From 3a1bf253981dec555038995a5d09d62bad58fc03 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 27 Jul 2011 01:27:05 +0200 Subject: [PATCH 062/110] do not exit if a type does not have explorer :-) Signed-off-by: Nico Schottelius --- bin/cdist-deploy-to | 2 +- core/__cdist_object_explorer_run | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/bin/cdist-deploy-to b/bin/cdist-deploy-to index 781c15c4..a2f7a2f1 100755 --- a/bin/cdist-deploy-to +++ b/bin/cdist-deploy-to @@ -55,9 +55,9 @@ __cdist_dir push "${__cdist_core_dir}" "${__cdist_remote_core_dir}" __cdist_explorer_run_global __cdist_manifest_run_init __cdist_object_all __cdist_object_prepare +__cdist_object_all __cdist_object_run exit 1 -__cdist_object_all __cdist_object_run __cdist_cache __cdist_echo info "cdist $__cdist_version: Successfully finished run" diff --git a/core/__cdist_object_explorer_run b/core/__cdist_object_explorer_run index 1f266dca..b082ce0b 100755 --- a/core/__cdist_object_explorer_run +++ b/core/__cdist_object_explorer_run @@ -26,15 +26,16 @@ __cdist_object_explorer_run() { + set -x __cdist_object_self="$1"; shift __cdist_object_id="$(__cdist_object_id_from_object "$__cdist_object_self")" __cdist_type="$(__cdist_type_from_object "$__cdist_object_self")" # Check if type of object has >= 1 explorer - __cdist_has_explorer="$(__cdist_dir_listing "$(__cdist_type_explorer_dir "$__cdist_type")")" + __cdist_has_explorer="$(__cdist_dir_listing "$(__cdist_type_explorer_dir "$__cdist_type")" | wc -l)" # Run the type explorers for the current object if any - if [ "$__cdist_has_explorer" ]; then + if [ "$__cdist_has_explorer" -ge 1 ]; then if ! __cdist_type_explorer_pushed "$__cdist_type"; then # FIXME: variables! src_dir="$(__cdist_type_explorer_dir "$__cdist_type")" From 0c00e4a0d2c07692a8edb069616e3e7e81c26891 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 28 Jul 2011 10:53:58 +0200 Subject: [PATCH 063/110] no need for eval here Signed-off-by: Nico Schottelius --- core/__cdist_manifest_run_init | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/__cdist_manifest_run_init b/core/__cdist_manifest_run_init index 2d694900..18507252 100755 --- a/core/__cdist_manifest_run_init +++ b/core/__cdist_manifest_run_init @@ -24,7 +24,7 @@ __cdist_manifest_run_init() { - eval export $__cdist_name_var_manifest=\"\$__cdist_manifest_dir\" + export $__cdist_name_var_manifest="$__cdist_manifest_dir" __cdist_echo info "Running initial manifest for $__cdist_target_host " __cdist_manifest_run "$__cdist_manifest_init" From 815de25d9a4c67f89baa66ff463736079ecba12d Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 28 Jul 2011 10:54:18 +0200 Subject: [PATCH 064/110] continue corelib Signed-off-by: Nico Schottelius --- core/__cdist_object_code_run | 2 +- core/__cdist_object_explorer_run | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/core/__cdist_object_code_run b/core/__cdist_object_code_run index 48b6514d..d2e3b4a3 100755 --- a/core/__cdist_object_code_run +++ b/core/__cdist_object_code_run @@ -24,7 +24,7 @@ __cdist_object_code_run() { - + set -x __cdist_object_code_run_object="$1"; shift # Code local diff --git a/core/__cdist_object_explorer_run b/core/__cdist_object_explorer_run index b082ce0b..da59d6c3 100755 --- a/core/__cdist_object_explorer_run +++ b/core/__cdist_object_explorer_run @@ -26,7 +26,6 @@ __cdist_object_explorer_run() { - set -x __cdist_object_self="$1"; shift __cdist_object_id="$(__cdist_object_id_from_object "$__cdist_object_self")" From 5bb177eef99515d3e23e1c87586ef417ab140962 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 2 Aug 2011 12:05:02 +0200 Subject: [PATCH 065/110] ++todo Signed-off-by: Nico Schottelius --- doc/dev/todo/niconext | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/dev/todo/niconext b/doc/dev/todo/niconext index 7c91d865..4198fe3f 100644 --- a/doc/dev/todo/niconext +++ b/doc/dev/todo/niconext @@ -1,3 +1,10 @@ +core/__cdist_object_code_run: + make remote run work again + +__cdist_code_run: + should be changed to run _all_ code (has nice checks) + +-------------------------------------------------------------------------------- - run-remote does not work anymore, because there is no binary :-) either make functions available on the other side or put logic on the server side. From 39f1c8a242767046382b17559431489c50b01631 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 2 Aug 2011 12:15:59 +0200 Subject: [PATCH 066/110] add two new wrapper to run code and shellcode Signed-off-by: Nico Schottelius --- ...__cdist_exec_fail_on_error => __cdist_run} | 11 +++--- core/__cdist_run_shell | 36 +++++++++++++++++++ 2 files changed, 40 insertions(+), 7 deletions(-) rename core/{__cdist_exec_fail_on_error => __cdist_run} (77%) create mode 100755 core/__cdist_run_shell diff --git a/core/__cdist_exec_fail_on_error b/core/__cdist_run similarity index 77% rename from core/__cdist_exec_fail_on_error rename to core/__cdist_run index 96e5f056..db9fd8d9 100755 --- a/core/__cdist_exec_fail_on_error +++ b/core/__cdist_run @@ -18,18 +18,15 @@ # along with cdist. If not, see . # # -# Exit if an error occurs +# Exit if an error occurs running something # -__cdist_exec_fail_on_error() +__cdist_run() { set +e - sh -e "$@" + "$@" if [ "$?" -ne 0 ]; then - __cdist_echo error "$1 exited non-zero" - __cdist_echo warn "Faulty code:" - cat "$1" - __cdist_exit_err "Aborting due to non-zero exit code." + __cdist_echo error "$1 exited non-zero, aborting." fi set -e } diff --git a/core/__cdist_run_shell b/core/__cdist_run_shell new file mode 100755 index 00000000..07fb3d65 --- /dev/null +++ b/core/__cdist_run_shell @@ -0,0 +1,36 @@ +#!/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 . +# +# +# Exit if an error occurs when running a shell script +# + +__cdist_run_shell() +{ + set +e + sh -e "$@" + if [ "$?" -ne 0 ]; then + __cdist_echo error "$1 exited non-zero, aborting." + # __cdist_echo error "$1 exited non-zero" + # __cdist_echo warn "Faulty code:" + # cat "$1" + # __cdist_exit_err "Aborting due to non-zero exit code." + fi + set -e +} From 7fab1c9dd91da5460900f3b2cb011a854c3f7d2e Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 2 Aug 2011 12:17:48 +0200 Subject: [PATCH 067/110] use new wrapper __cdist_run_shell Signed-off-by: Nico Schottelius --- core/__cdist_code_run | 2 +- core/__cdist_manifest_run | 2 +- core/__cdist_object_gencode | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/__cdist_code_run b/core/__cdist_code_run index ca73b02d..eced45af 100755 --- a/core/__cdist_code_run +++ b/core/__cdist_code_run @@ -40,7 +40,7 @@ __cdist_code_run() if [ -f "$__cdist_code" ]; then if [ -x "$__cdist_code" ]; then __cdist_echo info "Executing code-${__cdist_code_type}" - __cdist_exec_fail_on_error "$__cdist_code" + __cdist_run_shell "$__cdist_code" else __cdist_exit_err "$__cdist_code exists, but is not executable." fi diff --git a/core/__cdist_manifest_run b/core/__cdist_manifest_run index aa8c56e3..8bf9cc51 100755 --- a/core/__cdist_manifest_run +++ b/core/__cdist_manifest_run @@ -53,5 +53,5 @@ __cdist_manifest_run() # prepend our path, so all cdist tools come before other tools export PATH="${__cdist_out_type_bin_dir}:$PATH" - __cdist_exec_fail_on_error "${__cdist_manifest}" + __cdist_run_shell "${__cdist_manifest}" } diff --git a/core/__cdist_object_gencode b/core/__cdist_object_gencode index 1024f2c5..08ef8b7d 100755 --- a/core/__cdist_object_gencode +++ b/core/__cdist_object_gencode @@ -43,7 +43,7 @@ __cdist_object_gencode() export __global="$__cdist_out_dir" if [ -x "$__cdist_type_gencode" ]; then - __cdist_exec_fail_on_error "$__cdist_type_gencode" > "$__cdist_tmp_file" + __cdist_run_shell "$__cdist_type_gencode" > "$__cdist_tmp_file" else if [ -e "$__cdist_type_gencode" ]; then __cdist_exit_err "$__cdist_type_gencode exists, but is not executable" From 2926532560a27586d414371432ca8cc24d5d4adb Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 9 Aug 2011 17:14:38 +0200 Subject: [PATCH 068/110] begin to merge __cdist_object_code_run and __cdist_code_run Signed-off-by: Nico Schottelius --- core/__cdist_code_run | 54 ------------------------------- core/__cdist_object_code_run | 62 ++++++++++++++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 56 deletions(-) delete mode 100755 core/__cdist_code_run diff --git a/core/__cdist_code_run b/core/__cdist_code_run deleted file mode 100755 index eced45af..00000000 --- a/core/__cdist_code_run +++ /dev/null @@ -1,54 +0,0 @@ -#!/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 code -# - -__cdist_code_run() -{ - [ $# -eq 2 ] || __cdist_usage " " - - __cdist_object_self="$1"; shift - __cdist_code_type="$1"; shift - - if [ ! -d "$(__cdist_object_dir "$__cdist_object_self")" ]; then - __cdist_exit_err "Object undefined" - fi - - __cdist_code="$(__cdist_object_code "$__cdist_object_self" "${__cdist_code_type}")" - - __cdist_echo info "Checking code-${__cdist_code_type}" - - if [ -e "$__cdist_code" ]; then - if [ -f "$__cdist_code" ]; then - if [ -x "$__cdist_code" ]; then - __cdist_echo info "Executing code-${__cdist_code_type}" - __cdist_run_shell "$__cdist_code" - else - __cdist_exit_err "$__cdist_code exists, but is not executable." - fi - else - __cdist_exit_err "$__cdist_code exists, but is not a file." - fi - fi - - # Exit gracefully if nothing is todo - true -} diff --git a/core/__cdist_object_code_run b/core/__cdist_object_code_run index d2e3b4a3..42e28a6a 100755 --- a/core/__cdist_object_code_run +++ b/core/__cdist_object_code_run @@ -32,6 +32,64 @@ __cdist_object_code_run() __cdist_code_run "$__cdist_object_code_run_object" "${__cdist_name_gencode_local}" # Code remote - __cdist_run_remote "__cdist_code_run" \ - "$__cdist_object_code_run_object" "${__cdist_name_gencode_remote}" + #__cdist_run_remote "__cdist_code_run" \ + # "$__cdist_object_code_run_object" "${__cdist_name_gencode_remote}" + __cdist_run_remote "echo" "__cdist_code_run" \ + "$__cdist_object_code_run_object" "${__cdist_name_gencode_remote}; exit 1" +} + + +#!/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 code +# + +__cdist_code_run() +{ + [ $# -eq 2 ] || __cdist_usage " " + + __cdist_object_self="$1"; shift + __cdist_code_type="$1"; shift + + if [ ! -d "$(__cdist_object_dir "$__cdist_object_self")" ]; then + __cdist_exit_err "Object undefined" + fi + + __cdist_code="$(__cdist_object_code "$__cdist_object_self" "${__cdist_code_type}")" + + __cdist_echo info "Checking code-${__cdist_code_type}" + + if [ -e "$__cdist_code" ]; then + if [ -f "$__cdist_code" ]; then + if [ -x "$__cdist_code" ]; then + __cdist_echo info "Executing code-${__cdist_code_type}" + __cdist_run_shell "$__cdist_code" + else + __cdist_exit_err "$__cdist_code exists, but is not executable." + fi + else + __cdist_exit_err "$__cdist_code exists, but is not a file." + fi + fi + + # Exit gracefully if nothing is todo + true } From 07dc79410a9762fed88aaee60c29929594c119f8 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 9 Aug 2011 17:18:35 +0200 Subject: [PATCH 069/110] add template for script that only runs if the file exists Signed-off-by: Nico Schottelius --- core/__cdist_run_if_exists | 69 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100755 core/__cdist_run_if_exists diff --git a/core/__cdist_run_if_exists b/core/__cdist_run_if_exists new file mode 100755 index 00000000..d8c63d0d --- /dev/null +++ b/core/__cdist_run_if_exists @@ -0,0 +1,69 @@ +#!/bin/sh +# +# 2010-2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 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 . +# +# +# Exec the code for the given object locally and remote +# + +__cdist_object_code_run() +{ + set -x + __cdist_object_code_run_object="$1"; shift + + # Code local + export __cdist_out_object_dir="$__cdist_out_object_dir" + __cdist_code_run "$__cdist_object_code_run_object" "${__cdist_name_gencode_local}" + + # Code remote + #__cdist_run_remote "__cdist_code_run" \ + # "$__cdist_object_code_run_object" "${__cdist_name_gencode_remote}" + __cdist_run_remote "echo" "__cdist_code_run" \ + "$__cdist_object_code_run_object" "${__cdist_name_gencode_remote}; exit 1" + + + # [ $# -eq 2 ] || __cdist_usage " " + + __cdist_object_code_run_object="$1"; shift + __cdist_code_type="$1"; shift + + if [ ! -d "$(__cdist_object_dir "$__cdist_object_code_run_object")" ]; then + __cdist_exit_err "Object undefined" + fi + + __cdist_code="$(__cdist_object_code "$__cdist_object_code_run_object" "${__cdist_code_type}")" + + __cdist_echo info "Checking code-${__cdist_code_type}" + + if [ -e "$__cdist_code" ]; then + if [ -f "$__cdist_code" ]; then + if [ -x "$__cdist_code" ]; then + __cdist_echo info "Executing code-${__cdist_code_type}" + __cdist_run_shell "$__cdist_code" + else + __cdist_exit_err "$__cdist_code exists, but is not executable." + fi + else + __cdist_exit_err "$__cdist_code exists, but is not a file." + fi + fi + + # Exit gracefully if nothing is todo + true +} From f6d7a3e4783a49e9451ede47442528e5d8f12e15 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 9 Aug 2011 17:18:49 +0200 Subject: [PATCH 070/110] and give it a good name Signed-off-by: Nico Schottelius --- core/{__cdist_run_if_exists => __cdist_run_if_executable} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/{__cdist_run_if_exists => __cdist_run_if_executable} (100%) diff --git a/core/__cdist_run_if_exists b/core/__cdist_run_if_executable similarity index 100% rename from core/__cdist_run_if_exists rename to core/__cdist_run_if_executable From bd39d5c185c9d23a78da8ae64f41d6d83e78959f Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 9 Aug 2011 17:23:05 +0200 Subject: [PATCH 071/110] finish __cdist_run_if_executable Signed-off-by: Nico Schottelius --- core/__cdist_run_if_executable | 46 ++++++++-------------------------- 1 file changed, 11 insertions(+), 35 deletions(-) diff --git a/core/__cdist_run_if_executable b/core/__cdist_run_if_executable index d8c63d0d..86732742 100755 --- a/core/__cdist_run_if_executable +++ b/core/__cdist_run_if_executable @@ -1,7 +1,6 @@ #!/bin/sh # -# 2010-2011 Nico Schottelius (nico-cdist at schottelius.org) -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2011 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -22,45 +21,22 @@ # Exec the code for the given object locally and remote # -__cdist_object_code_run() +__cdist_run_if_executable() { - set -x - __cdist_object_code_run_object="$1"; shift + [ $# -gt 1 ] || __cdist_exit_err " " - # Code local - export __cdist_out_object_dir="$__cdist_out_object_dir" - __cdist_code_run "$__cdist_object_code_run_object" "${__cdist_name_gencode_local}" + __cdist_run_if_executable_exec="$1"; shift - # Code remote - #__cdist_run_remote "__cdist_code_run" \ - # "$__cdist_object_code_run_object" "${__cdist_name_gencode_remote}" - __cdist_run_remote "echo" "__cdist_code_run" \ - "$__cdist_object_code_run_object" "${__cdist_name_gencode_remote}; exit 1" - - - # [ $# -eq 2 ] || __cdist_usage " " - - __cdist_object_code_run_object="$1"; shift - __cdist_code_type="$1"; shift - - if [ ! -d "$(__cdist_object_dir "$__cdist_object_code_run_object")" ]; then - __cdist_exit_err "Object undefined" - fi - - __cdist_code="$(__cdist_object_code "$__cdist_object_code_run_object" "${__cdist_code_type}")" - - __cdist_echo info "Checking code-${__cdist_code_type}" - - if [ -e "$__cdist_code" ]; then - if [ -f "$__cdist_code" ]; then - if [ -x "$__cdist_code" ]; then - __cdist_echo info "Executing code-${__cdist_code_type}" - __cdist_run_shell "$__cdist_code" + if [ -e "$__cdist_run_if_executable_exec" ]; then + if [ -f "$__cdist_run_if_executable_exec" ]; then + if [ -x "$__cdist_run_if_executable_exec" ]; then + __cdist_echo debug "Running $@ ..." + "$@" else - __cdist_exit_err "$__cdist_code exists, but is not executable." + __cdist_exit_err "$__cdist_run_if_executable_exec exists, but is not executable." fi else - __cdist_exit_err "$__cdist_code exists, but is not a file." + __cdist_exit_err "$__cdist_run_if_executable_exec exists, but is not a file." fi fi From 8daa07acbf10e3a5c8710d14d7743260659f2479 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 9 Aug 2011 17:38:59 +0200 Subject: [PATCH 072/110] only check, do not run Signed-off-by: Nico Schottelius --- core/{__cdist_run_if_executable => __cdist_is_executable} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/{__cdist_run_if_executable => __cdist_is_executable} (100%) diff --git a/core/__cdist_run_if_executable b/core/__cdist_is_executable similarity index 100% rename from core/__cdist_run_if_executable rename to core/__cdist_is_executable From 5c35cad4770e0ac36d631ce940170c6e1fbe1871 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 9 Aug 2011 17:39:21 +0200 Subject: [PATCH 073/110] cleanups Signed-off-by: Nico Schottelius --- core/__cdist_is_executable | 26 ++++++------- core/__cdist_object_code_run | 75 +++++++----------------------------- core/__cdist_run_shell | 9 ++--- 3 files changed, 30 insertions(+), 80 deletions(-) diff --git a/core/__cdist_is_executable b/core/__cdist_is_executable index 86732742..f2907922 100755 --- a/core/__cdist_is_executable +++ b/core/__cdist_is_executable @@ -21,25 +21,23 @@ # Exec the code for the given object locally and remote # -__cdist_run_if_executable() +__cdist_is_executable() { - [ $# -gt 1 ] || __cdist_exit_err " " + [ $# -eq 1 ] || __cdist_exit_err "" - __cdist_run_if_executable_exec="$1"; shift - - if [ -e "$__cdist_run_if_executable_exec" ]; then - if [ -f "$__cdist_run_if_executable_exec" ]; then - if [ -x "$__cdist_run_if_executable_exec" ]; then - __cdist_echo debug "Running $@ ..." - "$@" + if [ -e "$1" ]; then + if [ -f "$1" ]; then + if [ -x "$1" ]; then + # Exists and is a correct executable + true else - __cdist_exit_err "$__cdist_run_if_executable_exec exists, but is not executable." + __cdist_exit_err "$1 exists, but is not executable." fi else - __cdist_exit_err "$__cdist_run_if_executable_exec exists, but is not a file." + __cdist_exit_err "$1 exists, but is not a file." fi + else + # Does not exist + false fi - - # Exit gracefully if nothing is todo - true } diff --git a/core/__cdist_object_code_run b/core/__cdist_object_code_run index 42e28a6a..53442bbe 100755 --- a/core/__cdist_object_code_run +++ b/core/__cdist_object_code_run @@ -24,72 +24,25 @@ __cdist_object_code_run() { + [ $# -eq 1 ] || __cdist_exit_err "" + set -x - __cdist_object_code_run_object="$1"; shift - # Code local - export __cdist_out_object_dir="$__cdist_out_object_dir" - __cdist_code_run "$__cdist_object_code_run_object" "${__cdist_name_gencode_local}" - - # Code remote - #__cdist_run_remote "__cdist_code_run" \ - # "$__cdist_object_code_run_object" "${__cdist_name_gencode_remote}" - __cdist_run_remote "echo" "__cdist_code_run" \ - "$__cdist_object_code_run_object" "${__cdist_name_gencode_remote}; exit 1" -} - - -#!/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 code -# - -__cdist_code_run() -{ - [ $# -eq 2 ] || __cdist_usage " " - - __cdist_object_self="$1"; shift - __cdist_code_type="$1"; shift - - if [ ! -d "$(__cdist_object_dir "$__cdist_object_self")" ]; then + if [ ! -d "$(__cdist_object_dir "$1")" ]; then __cdist_exit_err "Object undefined" fi - __cdist_code="$(__cdist_object_code "$__cdist_object_self" "${__cdist_code_type}")" - - __cdist_echo info "Checking code-${__cdist_code_type}" - - if [ -e "$__cdist_code" ]; then - if [ -f "$__cdist_code" ]; then - if [ -x "$__cdist_code" ]; then - __cdist_echo info "Executing code-${__cdist_code_type}" - __cdist_run_shell "$__cdist_code" - else - __cdist_exit_err "$__cdist_code exists, but is not executable." - fi - else - __cdist_exit_err "$__cdist_code exists, but is not a file." - fi + # Code local + export __cdist_out_object_dir="$__cdist_out_object_dir" + if __cdist_is_executable \ + "$(__cdist_object_code "$1" "${__cdist_name_gencode_local}")"; then + __cdist_run_shell \ + "$(__cdist_object_code "$1" "${__cdist_name_gencode_local}")" fi - # Exit gracefully if nothing is todo - true + # Code remote + if __cdist_is_executable \ + "$(__cdist_object_code "$1" "${__cdist_name_gencode_remote}")"; then + + fi } diff --git a/core/__cdist_run_shell b/core/__cdist_run_shell index 07fb3d65..fecfba70 100755 --- a/core/__cdist_run_shell +++ b/core/__cdist_run_shell @@ -26,11 +26,10 @@ __cdist_run_shell() set +e sh -e "$@" if [ "$?" -ne 0 ]; then - __cdist_echo error "$1 exited non-zero, aborting." - # __cdist_echo error "$1 exited non-zero" - # __cdist_echo warn "Faulty code:" - # cat "$1" - # __cdist_exit_err "Aborting due to non-zero exit code." + __cdist_echo error "$1 exited non-zero" + __cdist_echo warn "Faulty code:" + cat "$1" + __cdist_exit_err "Aborting due to non-zero exit code." fi set -e } From f6fac37f1d81c603c7322ed5425413527048496c Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 9 Aug 2011 17:50:38 +0200 Subject: [PATCH 074/110] successfully run remote code! Signed-off-by: Nico Schottelius --- bin/cdist-config | 7 +++++++ core/__cdist_object_code_run | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/bin/cdist-config b/bin/cdist-config index 0c72727f..adfd7bd8 100644 --- a/bin/cdist-config +++ b/bin/cdist-config @@ -274,6 +274,13 @@ __cdist_remote_object_dir() echo "$(__cdist_remote_object_base_dir "$1")/${__cdist_name_dot_cdist}" } +__cdist_remote_object_code() +{ + # FIXME: this should probably be __cdist_name_CODE_remote instead, although + # they have the same name always + echo "$(__cdist_remote_object_dir "$1")/${__cdist_name_code}-${__cdist_name_gencode_remote}" +} + __cdist_remote_object_parameter_dir() { echo "$(__cdist_remote_object_dir "$1")/${__cdist_name_parameter}" diff --git a/core/__cdist_object_code_run b/core/__cdist_object_code_run index 53442bbe..734db5c9 100755 --- a/core/__cdist_object_code_run +++ b/core/__cdist_object_code_run @@ -26,7 +26,7 @@ __cdist_object_code_run() { [ $# -eq 1 ] || __cdist_exit_err "" - set -x + # set -x if [ ! -d "$(__cdist_object_dir "$1")" ]; then __cdist_exit_err "Object undefined" @@ -44,5 +44,7 @@ __cdist_object_code_run() if __cdist_is_executable \ "$(__cdist_object_code "$1" "${__cdist_name_gencode_remote}")"; then + __cdist_run_remote $(__cdist_remote_object_code "$1") fi + # set +x } From 765c3d152a6cee58ddf153fae040a019e360f508 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 9 Aug 2011 17:51:51 +0200 Subject: [PATCH 075/110] allow cache to function again Signed-off-by: Nico Schottelius --- bin/cdist-deploy-to | 1 - 1 file changed, 1 deletion(-) diff --git a/bin/cdist-deploy-to b/bin/cdist-deploy-to index a2f7a2f1..e76564f4 100755 --- a/bin/cdist-deploy-to +++ b/bin/cdist-deploy-to @@ -56,7 +56,6 @@ __cdist_explorer_run_global __cdist_manifest_run_init __cdist_object_all __cdist_object_prepare __cdist_object_all __cdist_object_run -exit 1 __cdist_cache From 4ab6c5bbc9d57b75ca925a79dbfe49ea336791b5 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 9 Aug 2011 17:53:25 +0200 Subject: [PATCH 076/110] cleanup object naming in cache handling Signed-off-by: Nico Schottelius --- bin/cdist-deploy-to | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/cdist-deploy-to b/bin/cdist-deploy-to index e76564f4..49c8a6fc 100755 --- a/bin/cdist-deploy-to +++ b/bin/cdist-deploy-to @@ -56,6 +56,7 @@ __cdist_explorer_run_global __cdist_manifest_run_init __cdist_object_all __cdist_object_prepare __cdist_object_all __cdist_object_run +unset __cdist_object_self __cdist_cache From 49bad52715626570cbe43ddb0878d9750c7c990e Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 9 Aug 2011 17:54:28 +0200 Subject: [PATCH 077/110] remove debug Signed-off-by: Nico Schottelius --- core/__cdist_object_run | 3 --- 1 file changed, 3 deletions(-) diff --git a/core/__cdist_object_run b/core/__cdist_object_run index 7f08f192..0e0da80f 100755 --- a/core/__cdist_object_run +++ b/core/__cdist_object_run @@ -54,12 +54,9 @@ __cdist_object_run() __cdist_requirement="$1"; shift __cdist_echo info "Resolving requirement $__cdist_requirement" __cdist_object_run "$__cdist_requirement" - echo "done run" done fi - echo "after done" - __cdist_object_gencode_run "$__cdist_object_self" __cdist_dir push "$(__cdist_object_dir "$__cdist_object_self")" \ "$(__cdist_remote_object_dir "$__cdist_object_self")" From cb3b16d63fde03b162030c0e02fecf85598176bc Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 10 Aug 2011 08:45:44 +0200 Subject: [PATCH 078/110] -obsolete script Signed-off-by: Nico Schottelius --- bin/cdist-remote | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100755 bin/cdist-remote diff --git a/bin/cdist-remote b/bin/cdist-remote deleted file mode 100755 index 0a730a6e..00000000 --- a/bin/cdist-remote +++ /dev/null @@ -1,26 +0,0 @@ -#!/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 scripts runs functions or binaries remotely -# - -. cdist-config - -"$@" From a4f45dfcf4555ea3e4b4a43fdea1e193ca15271a Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 10 Aug 2011 08:52:06 +0200 Subject: [PATCH 079/110] go back to production mode and enable rm -rf Signed-off-by: Nico Schottelius --- bin/cdist-config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/cdist-config b/bin/cdist-config index adfd7bd8..d10f1ac7 100644 --- a/bin/cdist-config +++ b/bin/cdist-config @@ -303,7 +303,7 @@ __cdist_remote_type_explorer_dir() # __cdist_tmp_removal() { - echo rm -rf "${__cdist_tmp_dir}" + rm -rf "${__cdist_tmp_dir}" } # Does not work in children, will be called again in every script! From c70bfb2e207631c9137e5c8dc89cb2c45f0ff2ae Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 10 Aug 2011 15:55:55 +0200 Subject: [PATCH 080/110] cleanup for correct working in function environment Signed-off-by: Nico Schottelius --- core/__cdist_type_build_emulation | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/core/__cdist_type_build_emulation b/core/__cdist_type_build_emulation index a6cfcaa6..5457c99b 100755 --- a/core/__cdist_type_build_emulation +++ b/core/__cdist_type_build_emulation @@ -22,9 +22,8 @@ __cdist_type_build_emulation() { - [ $# -eq 1 ] || __cdist_usage "" + [ $# -eq 0 ] || __cdist_usage "No arguments" - __cdist_output_dir="$1"; shift __cdist_type_emulator="$__cdist_abs_mydir/cdist-type-emulator" if [ ! -d "${__cdist_type_dir}" ]; then @@ -32,12 +31,15 @@ __cdist_type_build_emulation() fi # Get Types - cd "${__cdist_type_dir}" - ls -1 > "${__cdist_tmp_file}" + ( + cd "${__cdist_type_dir}" + ls -1 > "${__cdist_tmp_file}" + ) # Create binaries - mkdir -p "${__cdist_output_dir}" - while read type; do - ln -sf "${__cdist_type_emulator}" "${__cdist_output_dir}/${type}" + mkdir -p "${__cdist_out_type_bin_dir}" + while read __cdist_type_build_emulation_type; do + ln -sf "${__cdist_type_emulator}" \ + "${__cdist_out_type_bin_dir}/${__cdist_type_build_emulation_type}" done < "${__cdist_tmp_file}" } From f8595793c194d6615afd8b69d2cfb7f8b82e9b28 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 10 Aug 2011 16:00:06 +0200 Subject: [PATCH 081/110] cleanup caching function Signed-off-by: Nico Schottelius --- core/__cdist_cache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/__cdist_cache b/core/__cdist_cache index 44c60125..95764d3d 100755 --- a/core/__cdist_cache +++ b/core/__cdist_cache @@ -27,7 +27,7 @@ __cdist_cache() mkdir -p "${__cdist_local_base_cache_dir}" __cdist_echo info \ - "Saving cache to $(__cdist_host_cache_dir "$__cdist_target_host")" + "Caching to $(__cdist_host_cache_dir "$__cdist_target_host")" rm -rf "$(__cdist_host_cache_dir "$__cdist_target_host")" mv "$__cdist_local_base_dir" \ "$(__cdist_host_cache_dir "$__cdist_target_host")" From b5b8bdc016e5098dde77251462a3eb024c987bb9 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 10 Aug 2011 16:03:12 +0200 Subject: [PATCH 082/110] cleanup __cdist_dir Signed-off-by: Nico Schottelius --- core/__cdist_dir | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/core/__cdist_dir b/core/__cdist_dir index 2f08a95c..32ee0075 100755 --- a/core/__cdist_dir +++ b/core/__cdist_dir @@ -23,29 +23,24 @@ # Pull a directory from a target, both sides have the same name (i.e. explorers) # - __cdist_dir() { [ $# -eq 3 ] || __cdist_usage " " - __cdist_dir_action="$1"; shift - __cdist_dir_src="$1"; shift - __cdist_dir_dst="$1"; shift - - # This will be the destination directory, so no subdirectories + # ${3%/*} will be the destination directory, so no subdirectories # of the same name are created, if the directory is already existing - __cdist_dir_top="${__cdist_dir_dst%/*}" - if [ "$__cdist_dir_action" = "push" ]; then + if [ "$1" = "push" ]; then + # FIXME: add error handling with __cdist_run_remote_... or so ssh "${__cdist_remote_user}@${__cdist_target_host}" \ - "mkdir -p \"${__cdist_dir_dst}\"" - scp -qr "$__cdist_dir_src" \ - "${__cdist_remote_user}@${__cdist_target_host}:${__cdist_dir_top}" - elif [ "$__cdist_dir_action" = "pull" ]; then - mkdir -p "${__cdist_dir_dst}" - scp -qr "${__cdist_remote_user}@${__cdist_target_host}:${__cdist_dir_src}" \ - "${__cdist_dir_top}" + "mkdir -p \"$3\"" + scp -qr "$2" \ + "${__cdist_remote_user}@${__cdist_target_host}:${3%/*}" + elif [ "$1" = "pull" ]; then + mkdir -p "$3" + scp -qr "${__cdist_remote_user}@${__cdist_target_host}:$2" \ + "${3%/*}" else - __cdist_exit_err "Unknown action $__cdist_dir_action" + __cdist_exit_err "Unknown action $1" fi } From c9f4455677466aa09b3bc337c4207457e99344fa Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 10 Aug 2011 16:11:08 +0200 Subject: [PATCH 083/110] less todo Signed-off-by: Nico Schottelius --- core/__cdist_explorer_run | 4 ++-- doc/dev/todo/niconext | 33 --------------------------------- 2 files changed, 2 insertions(+), 35 deletions(-) diff --git a/core/__cdist_explorer_run b/core/__cdist_explorer_run index c93b348f..9e58fa09 100755 --- a/core/__cdist_explorer_run +++ b/core/__cdist_explorer_run @@ -18,7 +18,7 @@ # along with cdist. If not, see . # # -# Run explorers +# Run explorers - FIXME: this function is ugly # __cdist_explorer_run() @@ -47,7 +47,7 @@ __cdist_explorer_run() # Create output directory __cdist_run_remote mkdir -p "$4" - # Execute all explorers + # Execute all explorers - FIXME: isolate cd call? cd "$2"; # FIXME: cleanup double variable, no need when in directory for __cdist_explorer_run_explorer in *; do diff --git a/doc/dev/todo/niconext b/doc/dev/todo/niconext index d37658ea..3c3300e1 100644 --- a/doc/dev/todo/niconext +++ b/doc/dev/todo/niconext @@ -1,36 +1,3 @@ -core/__cdist_object_code_run: - make remote run work again - -__cdist_code_run: - should be changed to run _all_ code (has nice checks) - --------------------------------------------------------------------------------- -- run-remote does not work anymore, because there is no binary :-) - either make functions available on the other side or - put logic on the server side. - - - trying to run type explorers nicely from local side - - must check whether type directory has been transmitted before! - --------------------------------------------------------------------------------- - - - - Both type and global have... - - local sourcedir - - remote destination dir - - remote out dir - - local out dir - - - Differences are in... - - variables exposed / submitted - - - - -Catch broken instances in cdist-mass-deploy -p and report broken deployements at the end! - - --------------------------------------------------------------------------------- Bug with requirements when indirect requires is scheduled late: __package/collectd: Generating local code From 97e8c431af3dabc638835be38a3cc13fab9e5c95 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 10 Aug 2011 16:15:10 +0200 Subject: [PATCH 084/110] only build emulator binaries once Signed-off-by: Nico Schottelius --- core/__cdist_type_build_emulation | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/__cdist_type_build_emulation b/core/__cdist_type_build_emulation index 5457c99b..3c7270ca 100755 --- a/core/__cdist_type_build_emulation +++ b/core/__cdist_type_build_emulation @@ -24,6 +24,8 @@ __cdist_type_build_emulation() { [ $# -eq 0 ] || __cdist_usage "No arguments" + [ -f "${__cdist_out_type_bin_dir}/.marker" ] && return 0 + __cdist_type_emulator="$__cdist_abs_mydir/cdist-type-emulator" if [ ! -d "${__cdist_type_dir}" ]; then @@ -42,4 +44,6 @@ __cdist_type_build_emulation() ln -sf "${__cdist_type_emulator}" \ "${__cdist_out_type_bin_dir}/${__cdist_type_build_emulation_type}" done < "${__cdist_tmp_file}" + + touch "${__cdist_out_type_bin_dir}/.marker" } From 160d85dee1e0bdc92a1cdecfe9259f139d0f5c87 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 10 Aug 2011 16:17:15 +0200 Subject: [PATCH 085/110] only setup path when executing something, not generally Signed-off-by: Nico Schottelius --- core/__cdist_is_executable | 3 ++- core/__cdist_manifest_run | 6 +----- core/__cdist_run_shell | 3 ++- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/core/__cdist_is_executable b/core/__cdist_is_executable index f2907922..a7a6d174 100755 --- a/core/__cdist_is_executable +++ b/core/__cdist_is_executable @@ -18,7 +18,8 @@ # along with cdist. If not, see . # # -# Exec the code for the given object locally and remote +# Test whether something is executable (that should be executable) or +# is missing # __cdist_is_executable() diff --git a/core/__cdist_manifest_run b/core/__cdist_manifest_run index 8bf9cc51..60d3fea3 100755 --- a/core/__cdist_manifest_run +++ b/core/__cdist_manifest_run @@ -45,13 +45,9 @@ __cdist_manifest_run() # The actual run # - # Ensure binaries exist and are up-to-date - # FIXME: do only once! no need to check for every manifest! + # Ensure binaries are existing __cdist_type_build_emulation "${__cdist_out_type_bin_dir}" \ || __cdist_exit_err "Failed to build type emulation binaries" - # prepend our path, so all cdist tools come before other tools - export PATH="${__cdist_out_type_bin_dir}:$PATH" - __cdist_run_shell "${__cdist_manifest}" } diff --git a/core/__cdist_run_shell b/core/__cdist_run_shell index fecfba70..1d76e17b 100755 --- a/core/__cdist_run_shell +++ b/core/__cdist_run_shell @@ -24,7 +24,8 @@ __cdist_run_shell() { set +e - sh -e "$@" + # Prepend our path, so all cdist tools come before other tools + PATH="${__cdist_out_type_bin_dir}:$PATH" sh -e "$@" if [ "$?" -ne 0 ]; then __cdist_echo error "$1 exited non-zero" __cdist_echo warn "Faulty code:" From 8fe9e862541b336e5708bce4ca09531061aa800b Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 10 Aug 2011 16:18:20 +0200 Subject: [PATCH 086/110] add prefix to variable name Signed-off-by: Nico Schottelius --- core/__cdist_manifest_run_init | 1 + core/__cdist_object_all | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/core/__cdist_manifest_run_init b/core/__cdist_manifest_run_init index 18507252..e8fa63de 100755 --- a/core/__cdist_manifest_run_init +++ b/core/__cdist_manifest_run_init @@ -24,6 +24,7 @@ __cdist_manifest_run_init() { + # FIXME: probably do not export but always set explicitly? export $__cdist_name_var_manifest="$__cdist_manifest_dir" __cdist_echo info "Running initial manifest for $__cdist_target_host " diff --git a/core/__cdist_object_all b/core/__cdist_object_all index 52661073..f9c505ff 100755 --- a/core/__cdist_object_all +++ b/core/__cdist_object_all @@ -26,7 +26,7 @@ __cdist_object_all() { [ $# -eq 1 ] || __cdist_usage "" - __cdist_command="$1"; shift + __cdist_object_all_command="$1"; shift __cdist_objects="$__cdist_tmp_dir/objects" @@ -50,7 +50,7 @@ __cdist_object_all() while [ $# -gt 0 ]; do __cdist_object="$1"; shift - $__cdist_command "$__cdist_object" + $__cdist_object_all_command "$__cdist_object" done done } From 8dbe6f9c77d455ac2babb65e7c9ba83ad6c3cc67 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 10 Aug 2011 16:20:24 +0200 Subject: [PATCH 087/110] add prefix to variable name [once more] Signed-off-by: Nico Schottelius --- core/__cdist_object_all | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/core/__cdist_object_all b/core/__cdist_object_all index f9c505ff..59457e3c 100755 --- a/core/__cdist_object_all +++ b/core/__cdist_object_all @@ -22,35 +22,36 @@ # Run the given command for each created object. # -__cdist_object_all() +__cdist_object_all_object_all() { [ $# -eq 1 ] || __cdist_usage "" - __cdist_object_all_command="$1"; shift + __cdist_object_all_object_all_command="$1"; shift - __cdist_objects="$__cdist_tmp_dir/objects" + __cdist_object_all_object_all_objects="$__cdist_tmp_dir/objects" # Ensure object dir exists, so marker can be created mkdir -p "${__cdist_out_object_dir}" # Loop until we do not create new objects anymore # which is equal to all objects have been run - touch "$__cdist_objects_created" - while [ -f "$__cdist_objects_created" ]; do + touch "$__cdist_object_all_object_all_objects_created" + while [ -f "$__cdist_object_all_object_all_objects_created" ]; do # Assume we're done after this run - rm "$__cdist_objects_created" + rm "$__cdist_object_all_object_all_objects_created" # Get listing of objects - __cdist_object_list "$__cdist_out_object_dir" > "$__cdist_objects" + __cdist_object_all_object_list "$__cdist_out_object_dir" > \ + "$__cdist_object_all_object_all_objects" # NEED TO CREATE ARRAY, SSH DESTROYS WHILE READ LOOP - while read __cdist_object; do - set -- "$@" "$__cdist_object" - done < "$__cdist_objects" + while read __cdist_object_all_object; do + set -- "$@" "$__cdist_object_all_object" + done < "$__cdist_object_all_object_all_objects" while [ $# -gt 0 ]; do - __cdist_object="$1"; shift - $__cdist_object_all_command "$__cdist_object" + __cdist_object_all_object="$1"; shift + $__cdist_object_all_object_all_command "$__cdist_object_all_object" done done } From 6886c2e6f11e73ddcb31fb0530ca17adca35a775 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 21 Aug 2011 15:18:41 +0200 Subject: [PATCH 088/110] ++todo Signed-off-by: Nico Schottelius --- doc/dev/todo/niconext | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/doc/dev/todo/niconext b/doc/dev/todo/niconext index 3c3300e1..c76bcae4 100644 --- a/doc/dev/todo/niconext +++ b/doc/dev/todo/niconext @@ -20,3 +20,15 @@ __file/etc/collectd/collectd.conf: Warning: Faulty code: scp /home/users/nico/oeffentlich/rechner/projekte/cdist-nutzung/conf/type/__ethz_collectd/files/collectd.conf.client root@shrek08:/etc/collectd/collectd.conf __file/etc/collectd/collectd.conf: Error: Aborting due to non-zero exit code. +-------------------------------------------------------------------------------- + +Bad error reporting in functions: + +[15:15] ikn:cdist-nutzung% cdist-deploy-to ikn +core: cdist 1.8.0: Configuring ikn +core: Creating clean directory structure +core: Transferring cdist binaries/functions to the target host +core: Running global explorers +core: Running initial manifest for ikn +core: Error: cdist-deploy-to: No arguments + From f65b61ee8f89ff576c09c61975f27abb3e9932c4 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 5 Sep 2011 09:42:10 +0200 Subject: [PATCH 089/110] add debug via __cdist_debug variable Signed-off-by: Nico Schottelius --- bin/cdist-config | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bin/cdist-config b/bin/cdist-config index d10f1ac7..d5c0464c 100644 --- a/bin/cdist-config +++ b/bin/cdist-config @@ -27,6 +27,9 @@ set -u # Fail if exited non-zero as well set -e +# enable debugging +[ "$__cdist_debug" ] && set -x + ################################################################################ # cconf standard vars prefixed with cdist From cdc6f0d0c01906b7e12c51373d2f3e9f5f561e08 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 5 Sep 2011 09:43:26 +0200 Subject: [PATCH 090/110] fix wrong call to __cdist_type_build_emulation Signed-off-by: Nico Schottelius --- core/__cdist_manifest_run | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/__cdist_manifest_run b/core/__cdist_manifest_run index 60d3fea3..cf85d646 100755 --- a/core/__cdist_manifest_run +++ b/core/__cdist_manifest_run @@ -45,8 +45,8 @@ __cdist_manifest_run() # The actual run # - # Ensure binaries are existing - __cdist_type_build_emulation "${__cdist_out_type_bin_dir}" \ + # Ensure binaries are existing - FIXME: move error handling into __cdist_type_build_emulation + __cdist_type_build_emulation \ || __cdist_exit_err "Failed to build type emulation binaries" __cdist_run_shell "${__cdist_manifest}" From 86e30c7a8a19e14e6a4a7a708e2ed63de786dda7 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 5 Sep 2011 09:47:58 +0200 Subject: [PATCH 091/110] re-rename variable, which got broken during core integration Signed-off-by: Nico Schottelius --- core/__cdist_object_all | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/core/__cdist_object_all b/core/__cdist_object_all index 59457e3c..abac594d 100755 --- a/core/__cdist_object_all +++ b/core/__cdist_object_all @@ -33,12 +33,19 @@ __cdist_object_all_object_all() # Ensure object dir exists, so marker can be created mkdir -p "${__cdist_out_object_dir}" + BUG: + - where does $__cdist_objects_created get setup? + - why do we use a file? + core/__cdist_object_manifest_run: touch "$__cdist_objects_created" + + + exit 23 # Loop until we do not create new objects anymore # which is equal to all objects have been run - touch "$__cdist_object_all_object_all_objects_created" - while [ -f "$__cdist_object_all_object_all_objects_created" ]; do + touch "$__cdist_objects_created" + while [ -f "$__cdist_objects_created" ]; do # Assume we're done after this run - rm "$__cdist_object_all_object_all_objects_created" + rm "$__cdist_objects_created" # Get listing of objects __cdist_object_all_object_list "$__cdist_out_object_dir" > \ From 444083865017c897f53d5212670fa50241b3dd27 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 5 Sep 2011 09:49:00 +0200 Subject: [PATCH 092/110] enable debugging before catching unset variables Signed-off-by: Nico Schottelius --- bin/cdist-config | 6 +++--- core/__cdist_object_all | 8 ++------ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/bin/cdist-config b/bin/cdist-config index d5c0464c..cff9b03a 100644 --- a/bin/cdist-config +++ b/bin/cdist-config @@ -21,15 +21,15 @@ __cdist_version="1.8.0" +# Enable debugging +[ "$__cdist_debug" ] && set -x + # Fail if something bogus is going on set -u # Fail if exited non-zero as well set -e -# enable debugging -[ "$__cdist_debug" ] && set -x - ################################################################################ # cconf standard vars prefixed with cdist diff --git a/core/__cdist_object_all b/core/__cdist_object_all index abac594d..0babdbf6 100755 --- a/core/__cdist_object_all +++ b/core/__cdist_object_all @@ -33,13 +33,9 @@ __cdist_object_all_object_all() # Ensure object dir exists, so marker can be created mkdir -p "${__cdist_out_object_dir}" - BUG: - - where does $__cdist_objects_created get setup? - - why do we use a file? - core/__cdist_object_manifest_run: touch "$__cdist_objects_created" + # FIXME: : - why do we use a file? + # core/__cdist_object_manifest_run: touch "$__cdist_objects_created" - - exit 23 # Loop until we do not create new objects anymore # which is equal to all objects have been run touch "$__cdist_objects_created" From bea7d5f828087a12f0a1fb6ee61ef151444831cb Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 5 Sep 2011 09:51:38 +0200 Subject: [PATCH 093/110] also fix the function name :-) Signed-off-by: Nico Schottelius --- core/__cdist_object_all | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/__cdist_object_all b/core/__cdist_object_all index 0babdbf6..cdec7df4 100755 --- a/core/__cdist_object_all +++ b/core/__cdist_object_all @@ -22,7 +22,7 @@ # Run the given command for each created object. # -__cdist_object_all_object_all() +__cdist_object_all() { [ $# -eq 1 ] || __cdist_usage "" From f7f2194b8f8ad0c730e08d7528e29d34f98397db Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 5 Sep 2011 09:54:20 +0200 Subject: [PATCH 094/110] move __cdist_object_list into seperate file Signed-off-by: Nico Schottelius --- bin/cdist-config | 14 -------------- core/__cdist_object_list | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 14 deletions(-) create mode 100755 core/__cdist_object_list diff --git a/bin/cdist-config b/bin/cdist-config index cff9b03a..be65fed3 100644 --- a/bin/cdist-config +++ b/bin/cdist-config @@ -219,20 +219,6 @@ __cdist_object_id_from_object() echo "${1#*/}" } -# Find objects, remove ./ and /MARKER -__cdist_object_list() -{ - local basedir="$1"; shift - - # Use subshell to prevent changing cwd in program - ( - cd "${basedir}" - - find . -name "$__cdist_name_dot_cdist" | \ - sed -e 's;^./;;' -e "s;/${__cdist_name_dot_cdist}\$;;" - ) -} - __cdist_object_parameter_dir() { echo "$(__cdist_object_dir "$1")/${__cdist_name_parameter}" diff --git a/core/__cdist_object_list b/core/__cdist_object_list new file mode 100755 index 00000000..af209daa --- /dev/null +++ b/core/__cdist_object_list @@ -0,0 +1,36 @@ +#!/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 . +# +# +# Print error and exit (perror() alike) +# + +__cdist_object_list() +{ + # FIXME: no local in posix + local basedir="$1"; shift + + # Use subshell to prevent changing cwd in program + ( + cd "${basedir}" + + find . -name "$__cdist_name_dot_cdist" | \ + sed -e 's;^./;;' -e "s;/${__cdist_name_dot_cdist}\$;;" + ) +} From 368ea87b8961c907bfb3b38cc92afd657061b2aa Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 5 Sep 2011 09:55:22 +0200 Subject: [PATCH 095/110] call to __cdist_object_list Signed-off-by: Nico Schottelius --- core/__cdist_object_all | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/__cdist_object_all b/core/__cdist_object_all index cdec7df4..965d08f6 100755 --- a/core/__cdist_object_all +++ b/core/__cdist_object_all @@ -44,7 +44,7 @@ __cdist_object_all() rm "$__cdist_objects_created" # Get listing of objects - __cdist_object_all_object_list "$__cdist_out_object_dir" > \ + __cdist_object_list "$__cdist_out_object_dir" > \ "$__cdist_object_all_object_all_objects" # NEED TO CREATE ARRAY, SSH DESTROYS WHILE READ LOOP From a5564850cef5834f9424e8aae44b51af177d6ec3 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 5 Sep 2011 09:57:44 +0200 Subject: [PATCH 096/110] -whitespaces at the end of lines Signed-off-by: Nico Schottelius --- core/__cdist_object_list | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/__cdist_object_list b/core/__cdist_object_list index af209daa..f2785c30 100755 --- a/core/__cdist_object_list +++ b/core/__cdist_object_list @@ -27,10 +27,10 @@ __cdist_object_list() local basedir="$1"; shift # Use subshell to prevent changing cwd in program - ( + ( cd "${basedir}" - find . -name "$__cdist_name_dot_cdist" | \ + find . -name "$__cdist_name_dot_cdist" | \ sed -e 's;^./;;' -e "s;/${__cdist_name_dot_cdist}\$;;" - ) + ) } From 2b955b09bc92fbb88023ae5986b9d2ebb9360119 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 5 Sep 2011 10:01:56 +0200 Subject: [PATCH 097/110] move out all functions that do not only print a value from bin/cdist-config Signed-off-by: Nico Schottelius --- bin/cdist-config | 19 ------------------- core/__cdist_kill_on_interrupt | 31 +++++++++++++++++++++++++++++++ core/__cdist_tmp_removal | 27 +++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 19 deletions(-) create mode 100644 core/__cdist_kill_on_interrupt create mode 100755 core/__cdist_tmp_removal diff --git a/bin/cdist-config b/bin/cdist-config index be65fed3..87f24d06 100644 --- a/bin/cdist-config +++ b/bin/cdist-config @@ -165,11 +165,6 @@ for __cdist_lib in $__cdist_core_dir/*; do . "$__cdist_lib" done -___cdist_lib_path() -{ - echo $_ -} - ################################################################################ # Cache @@ -213,7 +208,6 @@ __cdist_object_base_dir() echo "${__cdist_out_object_dir}/$1" } - __cdist_object_id_from_object() { echo "${1#*/}" @@ -290,19 +284,6 @@ __cdist_remote_type_explorer_dir() ################################################################################ # Traps # -__cdist_tmp_removal() -{ - rm -rf "${__cdist_tmp_dir}" -} - -# Does not work in children, will be called again in every script! -# Use only in interactive "front end" scripts -__cdist_kill_on_interrupt() -{ - __cdist_tmp_removal - kill 0 - exit 1 -} # Remove tempfiles at normal exit trap __cdist_tmp_removal EXIT diff --git a/core/__cdist_kill_on_interrupt b/core/__cdist_kill_on_interrupt new file mode 100644 index 00000000..7cb711fa --- /dev/null +++ b/core/__cdist_kill_on_interrupt @@ -0,0 +1,31 @@ +#!/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 . +# +# +# Run the given command for each created object. +# + +# Does not work in children, will be called again in every script! +# Use only in interactive "front end" scripts +__cdist_kill_on_interrupt() +{ + __cdist_tmp_removal + kill 0 + exit 1 +} diff --git a/core/__cdist_tmp_removal b/core/__cdist_tmp_removal new file mode 100755 index 00000000..74d74936 --- /dev/null +++ b/core/__cdist_tmp_removal @@ -0,0 +1,27 @@ +#!/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 . +# +# +# Remove tmp dir +# + +__cdist_tmp_removal() +{ + rm -rf "${__cdist_tmp_dir}" +} From fe68c5b5566e16b01533a5091c220e7826a14c6e Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 6 Sep 2011 12:24:53 +0200 Subject: [PATCH 098/110] do not exit implicitly via set -e anymore Signed-off-by: Nico Schottelius --- bin/cdist-config | 3 --- 1 file changed, 3 deletions(-) diff --git a/bin/cdist-config b/bin/cdist-config index 87f24d06..bf3f5b24 100644 --- a/bin/cdist-config +++ b/bin/cdist-config @@ -27,9 +27,6 @@ __cdist_version="1.8.0" # Fail if something bogus is going on set -u -# Fail if exited non-zero as well -set -e - ################################################################################ # cconf standard vars prefixed with cdist From 74418c77e028c72c45bd95d4a803f56a893d5367 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Sep 2011 10:01:59 +0200 Subject: [PATCH 099/110] remove obsolete calls to set +e/-e Signed-off-by: Nico Schottelius --- core/__cdist_run | 7 +------ core/__cdist_run_shell | 2 -- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/core/__cdist_run b/core/__cdist_run index db9fd8d9..8febe550 100755 --- a/core/__cdist_run +++ b/core/__cdist_run @@ -23,10 +23,5 @@ __cdist_run() { - set +e - "$@" - if [ "$?" -ne 0 ]; then - __cdist_echo error "$1 exited non-zero, aborting." - fi - set -e + "$@" || __cdist_echo error "$1 exited non-zero, aborting." } diff --git a/core/__cdist_run_shell b/core/__cdist_run_shell index 1d76e17b..b6e0a57d 100755 --- a/core/__cdist_run_shell +++ b/core/__cdist_run_shell @@ -23,7 +23,6 @@ __cdist_run_shell() { - set +e # Prepend our path, so all cdist tools come before other tools PATH="${__cdist_out_type_bin_dir}:$PATH" sh -e "$@" if [ "$?" -ne 0 ]; then @@ -32,5 +31,4 @@ __cdist_run_shell() cat "$1" __cdist_exit_err "Aborting due to non-zero exit code." fi - set -e } From c3bf34bf3d9a59c8467f94e5830b6b2711f1b753 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Sep 2011 10:07:04 +0200 Subject: [PATCH 100/110] add support for __cdist_debug={0,1,2} Signed-off-by: Nico Schottelius --- bin/cdist-config | 12 ++++++++++-- core/__cdist_echo | 4 +--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/bin/cdist-config b/bin/cdist-config index bf3f5b24..b15d1f3e 100644 --- a/bin/cdist-config +++ b/bin/cdist-config @@ -21,8 +21,16 @@ __cdist_version="1.8.0" -# Enable debugging -[ "$__cdist_debug" ] && set -x +# +# Enable debugging: +# +# __cdist_debug unset -> no debug +# __cdist_debug = 1 -> debug via __cdist_echo +# __cdist_debug = 2 -> debug via set -x +# + +: ${__cdist_debug:=0} +[ "$__cdist_debug" = 2 ] && set -x # Fail if something bogus is going on set -u diff --git a/core/__cdist_echo b/core/__cdist_echo index 2fcc93f0..37d24dd6 100755 --- a/core/__cdist_echo +++ b/core/__cdist_echo @@ -35,11 +35,9 @@ __cdist_echo() case "$__cdist_echo_type" in debug) - set +u - if [ "$__cdist_debug" ]; then + if [ "$__cdist_debug" = 1 ]; then echo $__cdist_echo_prefix "Debug: $@" fi - set -u ;; info) echo $__cdist_echo_prefix "$@" From bd85d22a89d96348c17a6afb0a2b0d3406d84e59 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Sep 2011 10:09:19 +0200 Subject: [PATCH 101/110] +debugging of __cdist_object_run Signed-off-by: Nico Schottelius --- core/__cdist_object_run | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/__cdist_object_run b/core/__cdist_object_run index 0e0da80f..086bfb0b 100755 --- a/core/__cdist_object_run +++ b/core/__cdist_object_run @@ -57,9 +57,12 @@ __cdist_object_run() done fi + __cdist_echo debug "Before gencode" __cdist_object_gencode_run "$__cdist_object_self" + __cdist_echo debug "Before push" __cdist_dir push "$(__cdist_object_dir "$__cdist_object_self")" \ "$(__cdist_remote_object_dir "$__cdist_object_self")" + __cdist_echo debug "Before run" __cdist_object_code_run "$__cdist_object_self" # Mark this object as done From 68a51da380a153e9033cb5df009379c1939be9dc Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Sep 2011 10:10:46 +0200 Subject: [PATCH 102/110] make debug more verbose Signed-off-by: Nico Schottelius --- core/__cdist_echo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/__cdist_echo b/core/__cdist_echo index 37d24dd6..a89d1821 100755 --- a/core/__cdist_echo +++ b/core/__cdist_echo @@ -36,7 +36,7 @@ __cdist_echo() case "$__cdist_echo_type" in debug) if [ "$__cdist_debug" = 1 ]; then - echo $__cdist_echo_prefix "Debug: $@" + echo $__cdist_echo_prefix "DEBUG: $@" fi ;; info) From 06a6bf1a0dfdc997413b6e63d77b4bb8dae40a16 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Sep 2011 10:12:40 +0200 Subject: [PATCH 103/110] debug object run Signed-off-by: Nico Schottelius --- core/__cdist_object_code_run | 4 ++-- core/__cdist_object_run | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/core/__cdist_object_code_run b/core/__cdist_object_code_run index 734db5c9..a932f655 100755 --- a/core/__cdist_object_code_run +++ b/core/__cdist_object_code_run @@ -26,7 +26,7 @@ __cdist_object_code_run() { [ $# -eq 1 ] || __cdist_exit_err "" - # set -x + set -x if [ ! -d "$(__cdist_object_dir "$1")" ]; then __cdist_exit_err "Object undefined" @@ -46,5 +46,5 @@ __cdist_object_code_run() __cdist_run_remote $(__cdist_remote_object_code "$1") fi - # set +x + set +x } diff --git a/core/__cdist_object_run b/core/__cdist_object_run index 086bfb0b..d122bdd4 100755 --- a/core/__cdist_object_run +++ b/core/__cdist_object_run @@ -64,6 +64,7 @@ __cdist_object_run() "$(__cdist_remote_object_dir "$__cdist_object_self")" __cdist_echo debug "Before run" __cdist_object_code_run "$__cdist_object_self" + __cdist_echo debug "Object run done # Mark this object as done touch "$__cdist_object_finished" From 512ff6957413077bd13a9355f89b1fd5fcb56c5d Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Sep 2011 10:13:00 +0200 Subject: [PATCH 104/110] +" Signed-off-by: Nico Schottelius --- core/__cdist_object_run | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/__cdist_object_run b/core/__cdist_object_run index d122bdd4..7446c844 100755 --- a/core/__cdist_object_run +++ b/core/__cdist_object_run @@ -64,7 +64,7 @@ __cdist_object_run() "$(__cdist_remote_object_dir "$__cdist_object_self")" __cdist_echo debug "Before run" __cdist_object_code_run "$__cdist_object_self" - __cdist_echo debug "Object run done + __cdist_echo debug "Object run done" # Mark this object as done touch "$__cdist_object_finished" From 44586bc6f9dc9b1dc747365806ce40e6e8b8f8f1 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Sep 2011 10:17:18 +0200 Subject: [PATCH 105/110] changes for 1.8.0 Signed-off-by: Nico Schottelius --- doc/changelog | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/changelog b/doc/changelog index 82ae4b95..a9a70afb 100644 --- a/doc/changelog +++ b/doc/changelog @@ -1,3 +1,6 @@ +1.8.0: + * Added debug (via __cdist_debug={1,2} environment variable) + 1.7.1: 2011-07-26 * Documentation: Add explorers to reference * Documentation: Typo cleanup (Derek Brost) From adf2e05a0805473f789ca7942d5691b4e6a52662 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Sep 2011 10:18:03 +0200 Subject: [PATCH 106/110] more changes for 1.8.0 Signed-off-by: Nico Schottelius --- doc/changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/changelog b/doc/changelog index a9a70afb..a0d114a1 100644 --- a/doc/changelog +++ b/doc/changelog @@ -1,5 +1,6 @@ 1.8.0: * Added debug (via __cdist_debug={1,2} environment variable) + * Transformed shell script based approach to shell functions (performance improvement) 1.7.1: 2011-07-26 * Documentation: Add explorers to reference From 279d519dda0caa14f8488392675f6f411c0e8d99 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 8 Sep 2011 00:10:53 +0200 Subject: [PATCH 107/110] debug for core/__cdist_object_code_run Signed-off-by: Nico Schottelius --- core/__cdist_object_code_run | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/__cdist_object_code_run b/core/__cdist_object_code_run index a932f655..26bf7ef8 100755 --- a/core/__cdist_object_code_run +++ b/core/__cdist_object_code_run @@ -26,7 +26,6 @@ __cdist_object_code_run() { [ $# -eq 1 ] || __cdist_exit_err "" - set -x if [ ! -d "$(__cdist_object_dir "$1")" ]; then __cdist_exit_err "Object undefined" @@ -34,6 +33,7 @@ __cdist_object_code_run() # Code local export __cdist_out_object_dir="$__cdist_out_object_dir" + __cdist_echo debug "Trying to run local code" if __cdist_is_executable \ "$(__cdist_object_code "$1" "${__cdist_name_gencode_local}")"; then __cdist_run_shell \ @@ -41,10 +41,10 @@ __cdist_object_code_run() fi # Code remote + __cdist_echo debug "Trying to run remote code" if __cdist_is_executable \ "$(__cdist_object_code "$1" "${__cdist_name_gencode_remote}")"; then __cdist_run_remote $(__cdist_remote_object_code "$1") fi - set +x } From 0b5e7b585522113d7b3a13e10fc515fe91201c25 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 8 Sep 2011 00:17:28 +0200 Subject: [PATCH 108/110] debug log for code inserted Signed-off-by: Nico Schottelius --- core/__cdist_object_code_run | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/__cdist_object_code_run b/core/__cdist_object_code_run index 26bf7ef8..8af67ab8 100755 --- a/core/__cdist_object_code_run +++ b/core/__cdist_object_code_run @@ -38,6 +38,8 @@ __cdist_object_code_run() "$(__cdist_object_code "$1" "${__cdist_name_gencode_local}")"; then __cdist_run_shell \ "$(__cdist_object_code "$1" "${__cdist_name_gencode_local}")" + else + __cdist_echo debug "Local code: none" fi # Code remote @@ -46,5 +48,7 @@ __cdist_object_code_run() "$(__cdist_object_code "$1" "${__cdist_name_gencode_remote}")"; then __cdist_run_remote $(__cdist_remote_object_code "$1") + else + __cdist_echo debug "Remote code: none" fi } From 0ec3c2d017e5cc6f733b255350cc2588bbb221fc Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 8 Sep 2011 00:39:04 +0200 Subject: [PATCH 109/110] document bug Signed-off-by: Nico Schottelius --- core/__cdist_object_run | 2 ++ doc/dev/todo/niconext | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/core/__cdist_object_run b/core/__cdist_object_run index 7446c844..d2c7df6e 100755 --- a/core/__cdist_object_run +++ b/core/__cdist_object_run @@ -53,6 +53,8 @@ __cdist_object_run() while [ $# -gt 0 ]; do __cdist_requirement="$1"; shift __cdist_echo info "Resolving requirement $__cdist_requirement" + # FIXME: BUG: at this point, the other __cdist_object_run may have + # overwritten all our variables! __cdist_object_run "$__cdist_requirement" done fi diff --git a/doc/dev/todo/niconext b/doc/dev/todo/niconext index c76bcae4..cd4f8e70 100644 --- a/doc/dev/todo/niconext +++ b/doc/dev/todo/niconext @@ -1,3 +1,7 @@ +BUG in core/__cdist_object_run: each recursive call overwrites the variables! + +-------------------------------------------------------------------------------- + Bug with requirements when indirect requires is scheduled late: __package/collectd: Generating local code From 159ac76134a060469c6315600c67ccdbcd24c02f Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 8 Sep 2011 00:40:17 +0200 Subject: [PATCH 110/110] really do so Signed-off-by: Nico Schottelius --- BUG | 1 + 1 file changed, 1 insertion(+) create mode 100644 BUG diff --git a/BUG b/BUG new file mode 100644 index 00000000..9d57ee49 --- /dev/null +++ b/BUG @@ -0,0 +1 @@ +See core/__cdist_object_run.