finish cdist-object-codegen-all
Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
parent
6914071fe0
commit
80c745383a
3 changed files with 29 additions and 102 deletions
|
@ -24,18 +24,25 @@ set -x
|
|||
export PATH="$PATH:$(pwd -P)/bin"
|
||||
object_tmp=/tmp/localhost/objects
|
||||
explorer_tmp=/tmp/localhost/explorers
|
||||
exec_tmp=/tmp/localhost/exec
|
||||
|
||||
# Test first level manifest execution
|
||||
__cdist_config=$(pwd -P)/conf cdist-manifest-init localhost "$object_tmp"
|
||||
|
||||
# See what it generated
|
||||
find $object_tmp
|
||||
find "$object_tmp"
|
||||
|
||||
# Run explorer on a "remote" host
|
||||
__cdist_config=$(pwd -P)/conf cdist-explorer-run localhost "$explorer_tmp"
|
||||
|
||||
# Display result
|
||||
find $explorer_tmp
|
||||
find "$explorer_tmp"
|
||||
|
||||
# Generate code for all objects in object dir
|
||||
__cdist_config=$(pwd -P)/conf cdist-object-codegen-all localhost "$object_tmp" "$exec_tmp"
|
||||
|
||||
# Display result
|
||||
find "$exec_tmp"
|
||||
|
||||
################################################################################
|
||||
# Soon working
|
||||
|
@ -43,9 +50,3 @@ find $explorer_tmp
|
|||
|
||||
# Generate all objects, including from types that generate objects as well
|
||||
__cdist_config=$(pwd -P)/conf cdist-manifest-recursive-run localhost "$object_tmp"
|
||||
|
||||
# Generate code for one object
|
||||
__cdist_config=$(pwd -P)/conf cdist-object-codegen localhost "$object_tmp" __file/etc-issue
|
||||
|
||||
# Generate code for all objects in object dir
|
||||
__cdist_config=$(pwd -P)/conf cdist-code-gen-all localhost "$object_tmp"
|
||||
|
|
|
@ -141,9 +141,8 @@ __cdist_object_list()
|
|||
|
||||
cd "${basedir}"
|
||||
|
||||
find . -name "$__cdist_name_object_source" | \
|
||||
sed -e "s;$__cdist_name_object_source\$;;" \
|
||||
-e 's;^./;;'
|
||||
find . -name "$__cdist_name_object_source" | \
|
||||
sed -e "s;$__cdist_name_object_source\$;;" -e 's;^./;;'
|
||||
}
|
||||
|
||||
__cdist_tmp_removal()
|
||||
|
|
|
@ -18,110 +18,37 @@
|
|||
# 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.
|
||||
#
|
||||
#
|
||||
# For each created object create the code to be executed on the
|
||||
# target.
|
||||
#
|
||||
|
||||
. cdist-config
|
||||
|
||||
if [ $# -ne 2 ]; then
|
||||
__cdist_usage "<target host> <object_dir>"
|
||||
if [ $# -ne 3 ]; then
|
||||
__cdist_usage "<target host> <object_base_dir> <outdir>"
|
||||
fi
|
||||
|
||||
set -eu
|
||||
|
||||
__cdist_target_host="$1"; shift
|
||||
__cdist_object_dir="$1"; shift
|
||||
__cdist_object_base_dir="$1"; shift
|
||||
__cdist_exec_dir="$1"; shift
|
||||
|
||||
# change to directory containing objects
|
||||
cd "$__cdist_object_dir"
|
||||
# cd "$__cdist_object_base_dir"
|
||||
|
||||
# Loop until we do not create new objects anymore
|
||||
# which is equal to all objects have been run
|
||||
__cdist_object_created_new=1
|
||||
set -x
|
||||
__cdist_object_list "$__cdist_object_base_dir" > "$__cdist_tmp_file"
|
||||
|
||||
while read object; do
|
||||
outdir="$__cdist_exec_dir/${object}"
|
||||
outfile="${outdir}/${__cdist_name_exec}"
|
||||
|
||||
while [ "$__cdist_object_created_new" = 1 ]; do
|
||||
# assume we're done after this run
|
||||
__cdist_object_created_new=0
|
||||
mkdir -p "${outdir}"
|
||||
|
||||
# find all objects (every object has the source recorded)
|
||||
find . -name "$__cdist_object_source" | \
|
||||
sed -e "s;$__cdist_object_source\$;;" \
|
||||
-e 's;^./;;' \
|
||||
> "$__cdist_tmp_file"
|
||||
cdist-object-codegen "$__cdist_target_host" \
|
||||
"$__cdist_object_base_dir" \
|
||||
"$object" > "${outfile}"
|
||||
|
||||
# FIXME: DEBUG
|
||||
cat "$__cdist_tmp_file"
|
||||
|
||||
while read object; do
|
||||
if [ ! -f "${object}/$__cdist_object_finished" ]; then
|
||||
echo "Working on object ${object} ..."
|
||||
|
||||
type=${object%%/*}
|
||||
manifest="$__cdist_type_dir/${type}/${__cdist_name_init}"
|
||||
|
||||
if [ -x "${manifest}" ]; then
|
||||
echo "Running manifest of type ${type} ..."
|
||||
|
||||
# FIXME: use subdir in tmpdir?
|
||||
cdist-manifest-run "$__cdist_target_host" "${manifest}" "${__cdist_tmp_dir}"
|
||||
|
||||
echo "Trying to merge... "
|
||||
|
||||
# list of new objects
|
||||
cd "${__cdist_tmp_dir}"
|
||||
find . -name "$__cdist_object_source" | \
|
||||
sed -e "s;$__cdist_object_source\$;;" \
|
||||
-e 's;^./;;' \
|
||||
> "$__cdist_tmp_file"
|
||||
|
||||
while read newobject; do
|
||||
if [ -e "$__cdist_object_dir/${newobject}" ]; then
|
||||
__cdist_exit_err "${newobject} already exists, merge failed."
|
||||
else
|
||||
# Fine, merge back! FIXME: touch correct here?
|
||||
touch "${newobject}/$__cdist_object_finished"
|
||||
pax -r -w "$newobject" "$__cdist_object_dir"
|
||||
fi
|
||||
done < "$__cdist_tmp_file"
|
||||
|
||||
# Always rerun the whole loop if we ran
|
||||
# a manifest of an object
|
||||
break
|
||||
|
||||
|
||||
# FIXME: continue here
|
||||
# tar, cp, pax, mv?
|
||||
# mv/cp -n look good - posix?
|
||||
|
||||
# pax:
|
||||
# pax -r -w -k could work, but -k does not raise an error if files
|
||||
# are already existing
|
||||
|
||||
# - copy if not existing
|
||||
# fail (abort whole recursive run) if existing
|
||||
#
|
||||
# iterate over all new objects and copy each back?
|
||||
|
||||
else
|
||||
# Be nice, warn user if manifests exists, but is not executable
|
||||
if [ -f "${manifest}" ]; then
|
||||
echo "Warning ${manifest} is not executable"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
# At least one more run needed
|
||||
__cdist_object_created_new=1
|
||||
fi
|
||||
done < "$__cdist_tmp_file"
|
||||
|
||||
done
|
||||
|
||||
exit 0
|
||||
chmod u+x "${outfile}"
|
||||
done < "$__cdist_tmp_file"
|
||||
|
|
Loading…
Reference in a new issue