fix many bugs in cdist-manifest-recursive-all

Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
Nico Schottelius 2011-02-17 09:23:38 +01:00
parent 711f9d7647
commit 7bd2ba1358

View file

@ -1,6 +1,6 @@
#!/bin/sh #!/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. # This file is part of cdist.
# #
@ -38,84 +38,77 @@ set -eu
__cdist_target_host="$1"; shift __cdist_target_host="$1"; shift
__cdist_object_base_dir="$1"; shift __cdist_object_base_dir="$1"; shift
# change to directory containing objects objectlist="${__cdist_tmp_dir}/objectfile"
cd "$__cdist_object_base_dir" newobjectlist="${__cdist_tmp_dir}/newobjectfile"
newobjects="${__cdist_tmp_dir}/newobjects"
no_new_object=n
# Loop until we do not create new objects anymore # Loop until we do not create new objects anymore
# which is equal to all objects have been run # which is equal to all objects have been run
__cdist_object_created_new=1 while [ "$no_new_object" = "n" ]; do
while [ "$__cdist_object_created_new" = 1 ]; do
# assume we're done after this run # assume we're done after this run
__cdist_object_created_new=0 no_new_object=y
# find all objects (every object has the source recorded) # find all objects (every object has the source recorded)
__cdist_object_list . > "$__cdist_tmp_file" __cdist_object_list "$__cdist_object_base_dir" > "$objectlist"
# FIXME: DEBUG
cat "$__cdist_tmp_file"
# Check every object, if we need to run it
while read object; do while read object; do
if [ ! -f "${object}/$__cdist_name_object_finished" ]; then cur_object_dir="$__cdist_object_base_dir/$object"
if [ ! -f "${cur_object_dir}/$__cdist_name_object_finished" ]; then
echo "Working on object ${object} ..." echo "Working on object ${object} ..."
type=${object%%/*} type="${object%%/*}"
manifest="$__cdist_type_dir/${type}/${__cdist_name_init}" manifest="$__cdist_type_dir/${type}/${__cdist_name_manifest}"
echo $manifest
if [ -x "${manifest}" ]; then if [ -x "${manifest}" ]; then
echo "Running manifest of type ${type} ..." echo "Executing manifest ${manifest} ..."
cdist-manifest-run "$__cdist_target_host" "${manifest}" "${newobjects}"
# FIXME: use subdir in tmpdir? __cdist_object_list "${newobjects}" > "$newobjectlist"
cdist-manifest-run "$__cdist_target_host" "${manifest}" "${__cdist_tmp_dir}"
echo "Trying to merge... "
# list of new objects
cd "${__cdist_tmp_dir}"
__cdist_object_list . > "$__cdist_tmp_file"
# Verify no conflicting objects have been created
while read newobject; do while read newobject; do
if [ -e "$__cdist_object_base_dir/${newobject}" ]; then grep -q "^$newobject\$" "$objectlist" && \
__cdist_exit_err "${newobject} already exists, merge failed." __cdist_exit_err "${manifest} tried to recreate ${newobject}"
else done < "$newobjectlist"
# Fine, merge back! FIXME: touch correct here?
touch "${newobject}/$___cdist_name_object_finished"
pax -r -w "$newobject" "$__cdist_object_base_dir"
fi
done < "$__cdist_tmp_file"
# Always rerun the whole loop if we ran
# a manifest of an object
break
# FIXME: continue here # Safe harbour: We can merge all objects into main tree
# tar, cp, pax, mv? # Merge = mkdir + mv parameters
# mv/cp -n look good - posix? while read newobject; do
# Unset no_new_object - only once needed... FIXME (beautify)
no_new_object="n"
set -x
# where to save the newly created object
object_dir="$__cdist_object_base_dir/$newobject"
# pax: # Source of the new object
# pax -r -w -k could work, but -k does not raise an error if files new_object_dir="${newobjects}/$newobject"
# are already existing
# - copy if not existing echo "MIGRATING: $newobject"
# fail (abort whole recursive run) if existing find $new_object_dir
#
# iterate over all new objects and copy each back?
mkdir -p "$object_dir"
mv "${new_object_dir}/"* "$object_dir"
set +x
done < "$newobjectlist"
# Remove listing and rest of newobjects, otherwise the next type will reuse it...
rm -rf "$newobjects" "$newobjectlist"
else else
# Be nice, warn user if manifests exists, but is not executable # Be nice, warn user if manifests exists, but is not executable
if [ -f "${manifest}" ]; then if [ -f "${manifest}" ]; then
echo "Warning ${manifest} is not executable" echo "Warning ${manifest} exists, but is not executable." >&2
fi fi
fi fi
# At least one more run needed
__cdist_object_created_new=1
fi fi
done < "$__cdist_tmp_file"
# done with this object
touch "$cur_object_dir/$__cdist_name_object_finished"
done < "$objectlist"
done done
exit 0