cdist/bin/cdist-manifest-run-all
Nico Schottelius 1d796e6ed1 rename no_new_object to new_objects_created (more intuitive)
Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
2011-02-17 09:34:59 +01:00

108 lines
3.7 KiB
Bash
Executable file

#!/bin/sh
#
# 2010-2011 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
#
# For each created object
# run the manifest of the type (with object id),
# try to merge back newly created objects (otherwise fail),
# mark the object as being run
# and iterate until all objects are marked being run.
#
#
#
. cdist-config
[ $# -eq 2 ] || __cdist_usage "<target host> <object_base_dir>"
set -eu
__cdist_target_host="$1"; shift
__cdist_object_base_dir="$1"; shift
objectlist="${__cdist_tmp_dir}/objectfile"
newobjectlist="${__cdist_tmp_dir}/newobjectfile"
newobjects="${__cdist_tmp_dir}/newobjects"
new_objects_created=y
# Loop until we do not create new objects anymore
# which is equal to all objects have been run
while [ "$new_objects_created" = "y" ]; do
# assume we're done after this run
new_objects_created=n
# find all objects (every object has the source recorded)
__cdist_object_list "$__cdist_object_base_dir" > "$objectlist"
# Check every object, if we need to run it
while read object; do
cur_object_dir="$__cdist_object_base_dir/$object"
if [ ! -f "${cur_object_dir}/$__cdist_name_object_finished" ]; then
echo "Working on object ${object} ..."
type="${object%%/*}"
manifest="$__cdist_type_dir/${type}/${__cdist_name_manifest}"
echo $manifest
if [ -x "${manifest}" ]; then
echo "Executing manifest ${manifest} ..."
cdist-manifest-run "$__cdist_target_host" "${manifest}" "${newobjects}"
__cdist_object_list "${newobjects}" > "$newobjectlist"
# Verify no conflicting objects have been created
while read newobject; do
grep -q "^$newobject\$" "$objectlist" && \
__cdist_exit_err "${manifest} tried to recreate ${newobject}"
done < "$newobjectlist"
# Safe harbour: We can merge all objects into main tree
# Merge = mkdir + mv parameters and source information
while read newobject; do
[ "$new_objects_created" = "n" ] && new_objects_created="y"
set -x
# where to save the newly created object
object_dir="$__cdist_object_base_dir/$newobject"
# Source of the new object
new_object_dir="${newobjects}/$newobject"
find $new_object_dir
mkdir -p "$object_dir"
# Move parameters and source information
mv "${new_object_dir}/"* "$object_dir"
mv "${new_object_dir}/${__cdist_name_object_source}" "$object_dir"
set +x
done < "$newobjectlist"
# Remove listing and rest of newobjects, otherwise the next type will reuse it...
rm -rf "$newobjects" "$newobjectlist"
else
# Be nice, warn user if manifests exists, but is not executable
if [ -f "${manifest}" ]; then
echo "Warning ${manifest} exists, but is not executable." >&2
fi
fi
fi
# done with this object
touch "$cur_object_dir/$__cdist_name_object_finished"
done < "$objectlist"
done