2011-06-17 10:49:02 +00:00
|
|
|
#!/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 <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
#
|
2011-06-17 12:28:10 +00:00
|
|
|
# Run explorers
|
2011-06-17 10:49:02 +00:00
|
|
|
#
|
|
|
|
|
2011-06-17 11:01:03 +00:00
|
|
|
__cdist_explorer_run()
|
2011-06-17 10:49:02 +00:00
|
|
|
{
|
2011-06-17 12:28:10 +00:00
|
|
|
[ $# -eq 3 ] || __cdist_usage "<global|type> <explorer dir> <out dir>"
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
global)
|
|
|
|
type)
|
|
|
|
"$__cdist_name_var_object=\"$(__cdist_remote_object_dir "$__cdist_object_self")\""
|
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
2011-06-17 10:49:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Variable that defines the home of the explorers
|
2011-06-17 12:28:10 +00:00
|
|
|
# __cdist_variable_name="$1"; shift
|
2011-06-17 10:49:02 +00:00
|
|
|
|
|
|
|
# Find explorers here
|
|
|
|
__cdist_explorer_dir="$1"; shift
|
|
|
|
|
|
|
|
# Write output here
|
|
|
|
__cdist_my_out_dir="$1"; shift
|
|
|
|
|
2011-06-17 12:28:10 +00:00
|
|
|
# Setup remote environment
|
2011-06-17 10:49:02 +00:00
|
|
|
export $__cdist_variable_name="$__cdist_explorer_dir"
|
|
|
|
export __global="$__cdist_remote_out_dir"
|
|
|
|
|
2011-06-17 12:28:10 +00:00
|
|
|
# mkdir -p "$__cdist_my_out_dir"
|
2011-06-17 10:49:02 +00:00
|
|
|
|
|
|
|
# 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
|
|
|
|
}
|