forked from ungleich-public/cdist
fix many bugs in cdist-manifest-recursive-all
Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
parent
711f9d7647
commit
7bd2ba1358
1 changed files with 48 additions and 55 deletions
|
@ -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"
|
||||||
|
|
||||||
# pax:
|
set -x
|
||||||
# pax -r -w -k could work, but -k does not raise an error if files
|
# where to save the newly created object
|
||||||
# are already existing
|
object_dir="$__cdist_object_base_dir/$newobject"
|
||||||
|
|
||||||
# - copy if not existing
|
# Source of the new object
|
||||||
# fail (abort whole recursive run) if existing
|
new_object_dir="${newobjects}/$newobject"
|
||||||
#
|
|
||||||
# iterate over all new objects and copy each back?
|
|
||||||
|
|
||||||
|
echo "MIGRATING: $newobject"
|
||||||
|
find $new_object_dir
|
||||||
|
|
||||||
|
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
|
fi
|
||||||
|
|
||||||
|
# done with this object
|
||||||
|
touch "$cur_object_dir/$__cdist_name_object_finished"
|
||||||
|
|
||||||
# At least one more run needed
|
done < "$objectlist"
|
||||||
__cdist_object_created_new=1
|
|
||||||
fi
|
|
||||||
done < "$__cdist_tmp_file"
|
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
exit 0
|
|
||||||
|
|
Loading…
Reference in a new issue