forked from ungleich-public/cdist
Merge branch 'master' into install
Conflicts: bin/cdist-config Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
commit
9a3d9334d5
57 changed files with 1613 additions and 694 deletions
204
bin/cdist
204
bin/cdist
|
@ -62,37 +62,24 @@ VERSION = "2.0.0"
|
||||||
logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')
|
logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')
|
||||||
log = logging.getLogger()
|
log = logging.getLogger()
|
||||||
|
|
||||||
class TypeEmulator:
|
|
||||||
def __init__(self, name):
|
|
||||||
self.name = name
|
|
||||||
self.type = os.path.basename(name)
|
|
||||||
|
|
||||||
|
def file_to_list(filename):
|
||||||
|
"""Return list from \n seperated file"""
|
||||||
|
if os.path.isfile(filename):
|
||||||
|
file_fd = open(filename, "r")
|
||||||
|
lines = file_fd.readlines()
|
||||||
|
file_fd.close()
|
||||||
|
|
||||||
def type_emulator(self):
|
# Remove \n from all lines
|
||||||
type = basename(sys.argv[0])
|
lines = map(lambda s: s.strip(), lines)
|
||||||
|
else:
|
||||||
|
lines = []
|
||||||
|
|
||||||
type_is_singleton(type)
|
return lines
|
||||||
|
|
||||||
# Check object id
|
def exit_error(*args):
|
||||||
|
log.error(*args)
|
||||||
# Prevent double slash if id begins with /
|
sys.exit(1)
|
||||||
|
|
||||||
# Record parameter: opt_file="${opt#--}"
|
|
||||||
# [ $# -ge 1 ] || __cdist_usage "Missing value for $opt"
|
|
||||||
# echo "${value}" > "${__cdist_parameter_dir}/${opt_file}"
|
|
||||||
|
|
||||||
# Record requirements
|
|
||||||
# echo $requirement >> "$(__cdist_object_require "$__cdist_object_self")"
|
|
||||||
|
|
||||||
# Ensure required parameters are given
|
|
||||||
# Ensure that only optional or required parameters are given
|
|
||||||
# [ "$is_valid" ] || __cdist_usage "Unknown parameter $parameter"
|
|
||||||
|
|
||||||
# Merge object (creating twice with the same parameter + requirements == allowed)
|
|
||||||
|
|
||||||
# diff -ru "${__cdist_new_object_dir}/${__cdist_name_parameter}
|
|
||||||
# # Add "I was here message"
|
|
||||||
# _cdist_object_source_add "${__cdist_object_dir}"
|
|
||||||
|
|
||||||
class Cdist:
|
class Cdist:
|
||||||
"""Cdist main class to hold arbitrary data"""
|
"""Cdist main class to hold arbitrary data"""
|
||||||
|
@ -160,10 +147,6 @@ class Cdist:
|
||||||
shutil.rmtree(self.cache_dir)
|
shutil.rmtree(self.cache_dir)
|
||||||
shutil.move(self.temp_dir, self.cache_dir)
|
shutil.move(self.temp_dir, self.cache_dir)
|
||||||
|
|
||||||
def exit_error(self, *args):
|
|
||||||
log.error(*args)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
def remote_mkdir(self, directory):
|
def remote_mkdir(self, directory):
|
||||||
"""Create directory on remote side"""
|
"""Create directory on remote side"""
|
||||||
self.run_or_fail(["mkdir", "-p", directory], remote=True)
|
self.run_or_fail(["mkdir", "-p", directory], remote=True)
|
||||||
|
@ -198,7 +181,9 @@ class Cdist:
|
||||||
print(script_fd.read())
|
print(script_fd.read())
|
||||||
script_fd.close()
|
script_fd.close()
|
||||||
|
|
||||||
self.exit_error("Command failed (shell): " + " ".join(*args))
|
exit_error("Command failed (shell): " + " ".join(*args))
|
||||||
|
except OSError as error:
|
||||||
|
exit_error(" ".join(*args) + ": " + error.args[1])
|
||||||
|
|
||||||
def run_or_fail(self, *args, **kargs):
|
def run_or_fail(self, *args, **kargs):
|
||||||
if "remote" in kargs:
|
if "remote" in kargs:
|
||||||
|
@ -211,7 +196,10 @@ class Cdist:
|
||||||
try:
|
try:
|
||||||
subprocess.check_call(*args, **kargs)
|
subprocess.check_call(*args, **kargs)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
self.exit_error("Command failed: " + " ".join(*args))
|
exit_error("Command failed: " + " ".join(*args))
|
||||||
|
except OSError as error:
|
||||||
|
exit_error(" ".join(*args) + ": " + error.args[1])
|
||||||
|
|
||||||
|
|
||||||
def remove_remote_dir(self, destination):
|
def remove_remote_dir(self, destination):
|
||||||
self.run_or_fail(["rm", "-rf", destination], remote=True)
|
self.run_or_fail(["rm", "-rf", destination], remote=True)
|
||||||
|
@ -366,8 +354,8 @@ class Cdist:
|
||||||
|
|
||||||
def link_type_to_emulator(self):
|
def link_type_to_emulator(self):
|
||||||
"""Link type names to cdist-type-emulator"""
|
"""Link type names to cdist-type-emulator"""
|
||||||
|
source = os.path.abspath(sys.argv[0])
|
||||||
for type in self.list_types():
|
for type in self.list_types():
|
||||||
source = os.path.join(self.lib_dir, "cdist-type-emulator")
|
|
||||||
destination = os.path.join(self.bin_dir, type)
|
destination = os.path.join(self.bin_dir, type)
|
||||||
log.debug("Linking %s to %s", source, destination)
|
log.debug("Linking %s to %s", source, destination)
|
||||||
os.symlink(source, destination)
|
os.symlink(source, destination)
|
||||||
|
@ -376,7 +364,7 @@ class Cdist:
|
||||||
"""Run global explorers"""
|
"""Run global explorers"""
|
||||||
explorers = self.list_global_explorers()
|
explorers = self.list_global_explorers()
|
||||||
if(len(explorers) == 0):
|
if(len(explorers) == 0):
|
||||||
self.exit_error("No explorers found in", self.global_explorer_dir)
|
exit_error("No explorers found in", self.global_explorer_dir)
|
||||||
|
|
||||||
self.transfer_global_explorers()
|
self.transfer_global_explorers()
|
||||||
for explorer in explorers:
|
for explorer in explorers:
|
||||||
|
@ -450,14 +438,17 @@ class Cdist:
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
env['PATH'] = self.bin_dir + ":" + env['PATH']
|
env['PATH'] = self.bin_dir + ":" + env['PATH']
|
||||||
|
|
||||||
|
# Information required in every manifest
|
||||||
env['__target_host'] = self.target_host
|
env['__target_host'] = self.target_host
|
||||||
env['__global'] = self.out_dir
|
env['__global'] = self.out_dir
|
||||||
|
|
||||||
# Legacy stuff to make cdist-type-emulator work
|
# Legacy stuff to make cdist-type-emulator work
|
||||||
env['__cdist_conf_dir'] = self.conf_dir
|
|
||||||
env['__cdist_core_dir'] = os.path.join(self.base_dir, "core")
|
env['__cdist_core_dir'] = os.path.join(self.base_dir, "core")
|
||||||
env['__cdist_local_base_dir'] = self.temp_dir
|
env['__cdist_local_base_dir'] = self.temp_dir
|
||||||
env['__cdist_manifest'] = self.initial_manifest
|
|
||||||
|
# Submit information to new type emulator
|
||||||
|
env['__cdist_manifest'] = manifest
|
||||||
|
env['__cdist_type_base_dir'] = self.type_base_dir
|
||||||
|
|
||||||
# Other environment stuff
|
# Other environment stuff
|
||||||
if extra_env:
|
if extra_env:
|
||||||
|
@ -465,28 +456,11 @@ class Cdist:
|
||||||
|
|
||||||
self.shell_run_or_debug_fail(manifest, [manifest], env=env)
|
self.shell_run_or_debug_fail(manifest, [manifest], env=env)
|
||||||
|
|
||||||
def list_object_requirements(self, cdist_object):
|
|
||||||
"""Return list of requirements for specific object"""
|
|
||||||
file=os.path.join(self.object_dir(cdist_object), "require")
|
|
||||||
|
|
||||||
if os.path.isfile(file):
|
|
||||||
file_fd = open(file, "r")
|
|
||||||
requirements = file_fd.readlines()
|
|
||||||
file_fd.close()
|
|
||||||
|
|
||||||
# Remove \n from all lines
|
|
||||||
requirements = map(lambda s: s.strip(), requirements)
|
|
||||||
|
|
||||||
log.debug("Requirements for %s: %s", cdist_object, requirements)
|
|
||||||
else:
|
|
||||||
requirements = []
|
|
||||||
|
|
||||||
return requirements
|
|
||||||
|
|
||||||
def object_run(self, cdist_object, mode):
|
def object_run(self, cdist_object, mode):
|
||||||
"""Run gencode or code for an object"""
|
"""Run gencode or code for an object"""
|
||||||
log.debug("Running %s from %s", mode, cdist_object)
|
log.debug("Running %s from %s", mode, cdist_object)
|
||||||
requirements = self.list_object_requirements(cdist_object)
|
file=os.path.join(self.object_dir(cdist_object), "require")
|
||||||
|
requirements = file_to_list(file)
|
||||||
type = self.get_type_from_object(cdist_object)
|
type = self.get_type_from_object(cdist_object)
|
||||||
|
|
||||||
for requirement in requirements:
|
for requirement in requirements:
|
||||||
|
@ -636,6 +610,108 @@ def install(args):
|
||||||
def emulator():
|
def emulator():
|
||||||
"""Emulate type commands (i.e. __file and co)"""
|
"""Emulate type commands (i.e. __file and co)"""
|
||||||
type = os.path.basename(sys.argv[0])
|
type = os.path.basename(sys.argv[0])
|
||||||
|
type_dir = os.path.join(os.environ['__cdist_type_base_dir'], type)
|
||||||
|
param_dir = os.path.join(type_dir, "parameter")
|
||||||
|
global_dir = os.environ['__global']
|
||||||
|
object_source = os.environ['__cdist_manifest']
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(add_help=False)
|
||||||
|
|
||||||
|
# Setup optional parameters
|
||||||
|
for parameter in file_to_list(os.path.join(param_dir, "optional")):
|
||||||
|
argument = "--" + parameter
|
||||||
|
parser.add_argument(argument, action='store', required=False)
|
||||||
|
|
||||||
|
# Setup required parameters
|
||||||
|
for parameter in file_to_list(os.path.join(param_dir, "required")):
|
||||||
|
argument = "--" + parameter
|
||||||
|
parser.add_argument(argument, action='store', required=True)
|
||||||
|
|
||||||
|
# Setup positional parameter, if not singleton
|
||||||
|
|
||||||
|
if not os.path.isfile(os.path.join(type_dir, "singleton")):
|
||||||
|
parser.add_argument("object_id", nargs=1)
|
||||||
|
|
||||||
|
# And finally verify parameter
|
||||||
|
args = parser.parse_args(sys.argv[1:])
|
||||||
|
|
||||||
|
# Setup object_id
|
||||||
|
if os.path.isfile(os.path.join(type_dir, "singleton")):
|
||||||
|
object_id = "singleton"
|
||||||
|
else:
|
||||||
|
object_id = args.object_id[0]
|
||||||
|
del args.object_id
|
||||||
|
|
||||||
|
# FIXME: / hardcoded - better portable solution available?
|
||||||
|
if object_id[0] == '/':
|
||||||
|
object_id = object_id[1:]
|
||||||
|
|
||||||
|
# FIXME: verify object id
|
||||||
|
log.debug(args)
|
||||||
|
|
||||||
|
object_dir = os.path.join(global_dir, "object", type,
|
||||||
|
object_id, DOT_CDIST)
|
||||||
|
param_out_dir = os.path.join(object_dir, "parameter")
|
||||||
|
|
||||||
|
object_source_file = os.path.join(object_dir, "source")
|
||||||
|
|
||||||
|
if os.path.exists(param_out_dir):
|
||||||
|
object_exists = True
|
||||||
|
old_object_source_fd = open(object_source_file, "r")
|
||||||
|
old_object_source = old_object_source_fd.readlines()
|
||||||
|
old_object_source_fd.close()
|
||||||
|
|
||||||
|
else:
|
||||||
|
object_exists = False
|
||||||
|
try:
|
||||||
|
os.makedirs(param_out_dir, exist_ok=True)
|
||||||
|
except OSError as error:
|
||||||
|
exit_error(param_out_dir + ": " + error.args[1])
|
||||||
|
|
||||||
|
# Record parameter
|
||||||
|
params = vars(args)
|
||||||
|
for param in params:
|
||||||
|
value = getattr(args, param)
|
||||||
|
if value:
|
||||||
|
file = os.path.join(param_out_dir, param)
|
||||||
|
log.debug(file + "<-" + param + " = " + value)
|
||||||
|
|
||||||
|
# Already exists, verify all parameter are the same
|
||||||
|
if object_exists:
|
||||||
|
if not os.path.isfile(file):
|
||||||
|
print("New parameter + " + param + "specified, aborting")
|
||||||
|
print("Source = " + old_object_source + "new =" + object_source)
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
param_fd = open(file, "r")
|
||||||
|
param_old = param_fd.realines()
|
||||||
|
param_fd.close()
|
||||||
|
|
||||||
|
if(param_old != param):
|
||||||
|
print("Parameter differs: " + param_old + "vs," + param)
|
||||||
|
print("Source = " + old_object_source + "new =" + object_source)
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
param_fd = open(file, "w")
|
||||||
|
param_fd.writelines(value)
|
||||||
|
param_fd.close()
|
||||||
|
|
||||||
|
# Record requirements
|
||||||
|
if "__require" in os.environ:
|
||||||
|
requirements = os.environ['__require']
|
||||||
|
print(object_id + ":Writing requirements: " + requirements)
|
||||||
|
require_fd = open(os.path.join(object_dir, "require"), "a")
|
||||||
|
require_fd.writelines(requirements.split(" "))
|
||||||
|
require_fd.close()
|
||||||
|
|
||||||
|
# Record / Append source
|
||||||
|
source_fd = open(os.path.join(object_dir, "source"), "a")
|
||||||
|
source_fd.writelines(object_source)
|
||||||
|
source_fd.close()
|
||||||
|
|
||||||
|
# sys.exit(1)
|
||||||
|
print("Finished " + type + "/" + object_id + repr(params))
|
||||||
|
|
||||||
|
|
||||||
def commandline():
|
def commandline():
|
||||||
"""Parse command line"""
|
"""Parse command line"""
|
||||||
|
@ -696,13 +772,13 @@ def commandline():
|
||||||
logging.root.setLevel(logging.DEBUG)
|
logging.root.setLevel(logging.DEBUG)
|
||||||
log.debug(args)
|
log.debug(args)
|
||||||
|
|
||||||
try:
|
args.func(args)
|
||||||
args.func(args)
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if re.match(TYPE_PREFIX, os.path.basename(sys.argv[0])):
|
try:
|
||||||
emulator()
|
if re.match(TYPE_PREFIX, os.path.basename(sys.argv[0])):
|
||||||
else:
|
emulator()
|
||||||
commandline()
|
else:
|
||||||
|
commandline()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
sys.exit(0)
|
||||||
|
|
438
bin/cdist-config
438
bin/cdist-config
|
@ -1,438 +0,0 @@
|
||||||
#!/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/>.
|
|
||||||
#
|
|
||||||
#
|
|
||||||
|
|
||||||
__cdist_version="1.7.0"
|
|
||||||
|
|
||||||
# Fail if something bogus is going on
|
|
||||||
set -u
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# cconf standard vars prefixed with cdist
|
|
||||||
|
|
||||||
__cdist_pwd="$(pwd -P)"
|
|
||||||
__cdist_mydir="${0%/*}";
|
|
||||||
__cdist_abs_mydir="$(cd "$__cdist_mydir" && pwd -P)"
|
|
||||||
__cdist_myname=${0##*/};
|
|
||||||
__cdist_abs_myname="$__cdist_abs_mydir/$__cdist_myname"
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# Names / Constants
|
|
||||||
#
|
|
||||||
# Most values can be overriden from outside, so you can
|
|
||||||
# customise paths as you like (for distributors, geeks and hackers)
|
|
||||||
#
|
|
||||||
|
|
||||||
: ${__cdist_name_bin:=bin}
|
|
||||||
: ${__cdist_name_cache:=cache}
|
|
||||||
: ${__cdist_name_code:=code}
|
|
||||||
: ${__cdist_name_conf_dir:=conf}
|
|
||||||
: ${__cdist_name_dot_cdist:=.cdist}
|
|
||||||
: ${__cdist_name_explorer:=explorer}
|
|
||||||
: ${__cdist_name_gencode:=gencode}
|
|
||||||
: ${__cdist_name_gencode_local:=local}
|
|
||||||
: ${__cdist_name_gencode_remote:=remote}
|
|
||||||
: ${__cdist_name_global:=global}
|
|
||||||
: ${__cdist_name_host:=host}
|
|
||||||
: ${__cdist_name_init:=init}
|
|
||||||
: ${__cdist_name_manifest:=manifest}
|
|
||||||
: ${__cdist_name_object:=object}
|
|
||||||
: ${__cdist_name_object_finished:=done}
|
|
||||||
: ${__cdist_name_object_prepared:=prepared}
|
|
||||||
: ${__cdist_name_object_id:=object_id}
|
|
||||||
: ${__cdist_name_object_source:=source}
|
|
||||||
: ${__cdist_name_objects_created:=.objects_created}
|
|
||||||
: ${__cdist_name_out_dir:=out}
|
|
||||||
: ${__cdist_name_parameter:=parameter}
|
|
||||||
: ${__cdist_name_parameter_required:=required}
|
|
||||||
: ${__cdist_name_parameter_optional:=optional}
|
|
||||||
: ${__cdist_name_require:=require}
|
|
||||||
: ${__cdist_name_self:=self}
|
|
||||||
: ${__cdist_name_singleton:=singleton}
|
|
||||||
: ${__cdist_name_target_host:=target_host}
|
|
||||||
: ${__cdist_name_target_user:=target_user}
|
|
||||||
: ${__cdist_name_type:=type}
|
|
||||||
: ${__cdist_name_type_bin:=type_bin}
|
|
||||||
: ${__cdist_name_type_explorer:=type_explorer}
|
|
||||||
: ${__cdist_name_type_explorer_pushed:=.explorer_pushed}
|
|
||||||
|
|
||||||
# Used for IDs: Allow everything not starting with - and .
|
|
||||||
: ${__cdist_sane_regexp:=[^-\.].*}
|
|
||||||
|
|
||||||
# Default remote user
|
|
||||||
: ${__cdist_remote_user:=root}
|
|
||||||
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# Exported variable names (usable for non core
|
|
||||||
#
|
|
||||||
: ${__cdist_name_var_explorer:=__$__cdist_name_explorer}
|
|
||||||
: ${__cdist_name_var_type_explorer:=__$__cdist_name_type_explorer}
|
|
||||||
: ${__cdist_name_var_global:=__$__cdist_name_global}
|
|
||||||
: ${__cdist_name_var_manifest:=__$__cdist_name_manifest}
|
|
||||||
: ${__cdist_name_var_target_host:=__$__cdist_name_target_host}
|
|
||||||
: ${__cdist_name_var_target_user:=__$__cdist_name_target_user}
|
|
||||||
: ${__cdist_name_var_object:=__$__cdist_name_object}
|
|
||||||
: ${__cdist_name_var_object_id:=__$__cdist_name_object_id}
|
|
||||||
: ${__cdist_name_var_self:=__$__cdist_name_self}
|
|
||||||
: ${__cdist_name_var_type:=__$__cdist_name_type}
|
|
||||||
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# Tempfiles
|
|
||||||
#
|
|
||||||
: ${__cdist_tmp_base_dir=/tmp}
|
|
||||||
__cdist_tmp_dir=$(mktemp -d "$__cdist_tmp_base_dir/cdist.XXXXXXXXXXXX")
|
|
||||||
__cdist_tmp_file=$(mktemp "$__cdist_tmp_dir/cdist.XXXXXXXXXXXX")
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# Local Base
|
|
||||||
#
|
|
||||||
: ${__cdist_local_base_dir:=$__cdist_tmp_dir}
|
|
||||||
|
|
||||||
# Cache may *NOT* be below __cdist_local_base_dir!
|
|
||||||
: ${__cdist_local_base_cache_dir:=$__cdist_abs_mydir/../$__cdist_name_cache}
|
|
||||||
|
|
||||||
: ${__cdist_conf_dir:="$(cd "$__cdist_abs_mydir/../conf" && pwd -P)"}
|
|
||||||
|
|
||||||
: ${__cdist_explorer_dir:=$__cdist_conf_dir/$__cdist_name_explorer}
|
|
||||||
: ${__cdist_manifest_dir:=$__cdist_conf_dir/$__cdist_name_manifest}
|
|
||||||
: ${__cdist_manifest_init:=$__cdist_manifest_dir/$__cdist_name_init}
|
|
||||||
: ${__cdist_type_dir:=$__cdist_conf_dir/$__cdist_name_type}
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# Local output
|
|
||||||
#
|
|
||||||
: ${__cdist_out_dir:=$__cdist_local_base_dir/$__cdist_name_out_dir}
|
|
||||||
: ${__cdist_out_explorer_dir:=$__cdist_out_dir/$__cdist_name_explorer}
|
|
||||||
: ${__cdist_out_object_dir:=$__cdist_out_dir/$__cdist_name_object}
|
|
||||||
: ${__cdist_out_type_dir:=$__cdist_out_dir/$__cdist_name_type}
|
|
||||||
: ${__cdist_out_type_bin_dir:=$__cdist_out_dir/$__cdist_name_type_bin}
|
|
||||||
|
|
||||||
: ${__cdist_objects_created:=$__cdist_out_object_dir/$__cdist_name_objects_created}
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# Remote base
|
|
||||||
#
|
|
||||||
: ${__cdist_remote_base_dir:=/var/lib/cdist}
|
|
||||||
: ${__cdist_remote_bin_dir:=$__cdist_remote_base_dir/$__cdist_name_bin}
|
|
||||||
: ${__cdist_remote_conf_dir:=$__cdist_remote_base_dir/$__cdist_name_conf_dir}
|
|
||||||
|
|
||||||
: ${__cdist_remote_explorer_dir:=$__cdist_remote_conf_dir/$__cdist_name_explorer}
|
|
||||||
: ${__cdist_remote_type_dir:=$__cdist_remote_conf_dir/$__cdist_name_type}
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# Remote output
|
|
||||||
#
|
|
||||||
: ${__cdist_remote_out_dir:=$__cdist_remote_base_dir/$__cdist_name_out_dir}
|
|
||||||
: ${__cdist_remote_out_explorer_dir:=$__cdist_remote_out_dir/$__cdist_name_explorer}
|
|
||||||
: ${__cdist_remote_out_object_dir:=$__cdist_remote_out_dir/$__cdist_name_object}
|
|
||||||
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# Internal functions
|
|
||||||
#
|
|
||||||
__cdist_echo()
|
|
||||||
{
|
|
||||||
__cdist_echo_type="$1"; shift
|
|
||||||
|
|
||||||
set +u
|
|
||||||
if [ "$__cdist_object_self" ]; then
|
|
||||||
__cdist_echo_prefix="${__cdist_object_self}:"
|
|
||||||
else
|
|
||||||
__cdist_echo_prefix="core: "
|
|
||||||
fi
|
|
||||||
set -u
|
|
||||||
|
|
||||||
case "$__cdist_echo_type" in
|
|
||||||
debug)
|
|
||||||
set +u
|
|
||||||
if [ "$__cdist_debug" ]; then
|
|
||||||
echo $__cdist_echo_prefix "Debug: $@"
|
|
||||||
fi
|
|
||||||
set -u
|
|
||||||
;;
|
|
||||||
info)
|
|
||||||
echo $__cdist_echo_prefix "$@"
|
|
||||||
;;
|
|
||||||
warn)
|
|
||||||
echo $__cdist_echo_prefix "Warning: $@"
|
|
||||||
;;
|
|
||||||
error)
|
|
||||||
echo $__cdist_echo_prefix "Error: $@" >&2
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "CORE BUG, who created the broken commit in $0?" >&2
|
|
||||||
exit 23
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
__cdist_exec_fail_on_error()
|
|
||||||
{
|
|
||||||
set +e
|
|
||||||
sh -e "$@"
|
|
||||||
if [ "$?" -ne 0 ]; then
|
|
||||||
__cdist_echo error "$1 exited non-zero"
|
|
||||||
__cdist_echo warn "Faulty code:"
|
|
||||||
cat "$1"
|
|
||||||
__cdist_exit_err "Aborting due to non-zero exit code."
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
__cdist_exit_err()
|
|
||||||
{
|
|
||||||
__cdist_echo error "$@"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
__cdist_usage()
|
|
||||||
{
|
|
||||||
__cdist_exit_err "$__cdist_myname: $@"
|
|
||||||
}
|
|
||||||
|
|
||||||
__cdist_init_deploy()
|
|
||||||
{
|
|
||||||
__cdist_echo info "Creating clean directory structure "
|
|
||||||
|
|
||||||
# Ensure there is no old stuff, neither local nor remote
|
|
||||||
rm -rf "$__cdist_local_base_dir"
|
|
||||||
ssh "${__cdist_remote_user}@$1" "rm -rf ${__cdist_remote_base_dir}"
|
|
||||||
|
|
||||||
# Init base
|
|
||||||
mkdir -p "$__cdist_local_base_dir"
|
|
||||||
ssh "${__cdist_remote_user}@$1" "mkdir -p ${__cdist_remote_base_dir}"
|
|
||||||
|
|
||||||
# Link configuration source directory - consistent with remote
|
|
||||||
ln -sf "$__cdist_conf_dir" "$__cdist_local_base_dir/$__cdist_name_conf_dir"
|
|
||||||
}
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# Cache
|
|
||||||
#
|
|
||||||
__cdist_cache_dir()
|
|
||||||
{
|
|
||||||
cd "${__cdist_local_base_cache_dir}" && pwd -P
|
|
||||||
}
|
|
||||||
|
|
||||||
__cdist_host_cache_dir()
|
|
||||||
{
|
|
||||||
echo "$(__cdist_cache_dir)/$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# Object
|
|
||||||
#
|
|
||||||
|
|
||||||
__cdist_object_code()
|
|
||||||
{
|
|
||||||
echo "$(__cdist_object_dir "$1")/${__cdist_name_code}-$2"
|
|
||||||
}
|
|
||||||
|
|
||||||
__cdist_object_prepared()
|
|
||||||
{
|
|
||||||
echo "$(__cdist_object_dir "$1")/${__cdist_name_object_prepared}"
|
|
||||||
}
|
|
||||||
|
|
||||||
__cdist_object_finished()
|
|
||||||
{
|
|
||||||
echo "$(__cdist_object_dir "$1")/${__cdist_name_object_finished}"
|
|
||||||
}
|
|
||||||
|
|
||||||
__cdist_object_dir()
|
|
||||||
{
|
|
||||||
echo "$(__cdist_object_base_dir "$1")/${__cdist_name_dot_cdist}"
|
|
||||||
}
|
|
||||||
|
|
||||||
__cdist_object_base_dir()
|
|
||||||
{
|
|
||||||
echo "${__cdist_out_object_dir}/$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
__cdist_object_id_from_object()
|
|
||||||
{
|
|
||||||
echo "${1#*/}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Find objects, remove ./ and /MARKER
|
|
||||||
__cdist_object_list()
|
|
||||||
{
|
|
||||||
local basedir="$1"; shift
|
|
||||||
|
|
||||||
# Use subshell to prevent changing cwd in program
|
|
||||||
(
|
|
||||||
cd "${basedir}"
|
|
||||||
|
|
||||||
find . -name "$__cdist_name_dot_cdist" | \
|
|
||||||
sed -e 's;^./;;' -e "s;/${__cdist_name_dot_cdist}\$;;"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
__cdist_object_parameter_dir()
|
|
||||||
{
|
|
||||||
echo "$(__cdist_object_dir "$1")/${__cdist_name_parameter}"
|
|
||||||
}
|
|
||||||
|
|
||||||
__cdist_object_require()
|
|
||||||
{
|
|
||||||
echo "$(__cdist_object_dir "$1")/${__cdist_name_require}"
|
|
||||||
}
|
|
||||||
|
|
||||||
__cdist_object_source_name()
|
|
||||||
{
|
|
||||||
echo "$1/${__cdist_name_object_source}"
|
|
||||||
}
|
|
||||||
|
|
||||||
__cdist_object_source()
|
|
||||||
{
|
|
||||||
cat "$(__cdist_object_source_name "$1")"
|
|
||||||
}
|
|
||||||
|
|
||||||
__cdist_object_source_add()
|
|
||||||
{
|
|
||||||
echo "$__cdist_manifest" >> "$(__cdist_object_source_name "$1")"
|
|
||||||
}
|
|
||||||
|
|
||||||
__cdist_object_type_explorer_dir()
|
|
||||||
{
|
|
||||||
echo "$(__cdist_object_dir "$1")/${__cdist_name_explorer}"
|
|
||||||
}
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# Remote
|
|
||||||
#
|
|
||||||
|
|
||||||
__cdist_remote_object_base_dir()
|
|
||||||
{
|
|
||||||
echo "${__cdist_remote_out_object_dir}/$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
__cdist_remote_object_dir()
|
|
||||||
{
|
|
||||||
echo "$(__cdist_remote_object_base_dir "$1")/${__cdist_name_dot_cdist}"
|
|
||||||
}
|
|
||||||
|
|
||||||
__cdist_remote_object_parameter_dir()
|
|
||||||
{
|
|
||||||
echo "$(__cdist_remote_object_dir "$1")/${__cdist_name_parameter}"
|
|
||||||
}
|
|
||||||
|
|
||||||
__cdist_remote_object_type_explorer_dir()
|
|
||||||
{
|
|
||||||
echo "$(__cdist_remote_object_dir "$1")/${__cdist_name_explorer}"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
__cdist_remote_type_explorer_dir()
|
|
||||||
{
|
|
||||||
echo "${__cdist_remote_type_dir}/$1/${__cdist_name_explorer}"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# Traps
|
|
||||||
#
|
|
||||||
__cdist_tmp_removal()
|
|
||||||
{
|
|
||||||
rm -rf "${__cdist_tmp_dir}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Does not work in children, will be called again in every script!
|
|
||||||
# Use only in interactive "front end" scripts
|
|
||||||
__cdist_kill_on_interrupt()
|
|
||||||
{
|
|
||||||
__cdist_tmp_removal
|
|
||||||
kill 0
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Remove tempfiles at normal exit
|
|
||||||
trap __cdist_tmp_removal EXIT
|
|
||||||
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# Type
|
|
||||||
#
|
|
||||||
__cdist_type_dir()
|
|
||||||
{
|
|
||||||
echo "${__cdist_type_dir}/$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
__cdist_type_explorer_dir()
|
|
||||||
{
|
|
||||||
echo "${__cdist_type_dir}/$1/${__cdist_name_explorer}"
|
|
||||||
}
|
|
||||||
|
|
||||||
__cdist_type_from_object()
|
|
||||||
{
|
|
||||||
echo "${1%%/*}"
|
|
||||||
}
|
|
||||||
|
|
||||||
__cdist_type_has_explorer()
|
|
||||||
{
|
|
||||||
# We only create output, if there's at least one explorer
|
|
||||||
# and can thus be used as a boolean ;-)
|
|
||||||
if [ -d "$(__cdist_type_explorer_dir "$1")" ]; then
|
|
||||||
ls -1 "$(__cdist_type_explorer_dir "$1")"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
__cdist_type_explorer_pushed()
|
|
||||||
{
|
|
||||||
[ -f "${__cdist_out_type_dir}/${__cdist_name_type_explorer_pushed}" ] \
|
|
||||||
&& grep -x -q "$1" "${__cdist_out_type_dir}/${__cdist_name_type_explorer_pushed}"
|
|
||||||
}
|
|
||||||
|
|
||||||
__cdist_type_explorer_pushed_add()
|
|
||||||
{
|
|
||||||
[ -d "$__cdist_out_type_dir" ] || mkdir "$__cdist_out_type_dir"
|
|
||||||
echo "$1" >> "${__cdist_out_type_dir}/${__cdist_name_type_explorer_pushed}"
|
|
||||||
}
|
|
||||||
|
|
||||||
__cdist_type_gencode()
|
|
||||||
{
|
|
||||||
echo "${__cdist_type_dir}/$1/${__cdist_name_gencode}-$2"
|
|
||||||
}
|
|
||||||
|
|
||||||
__cdist_type_manifest()
|
|
||||||
{
|
|
||||||
echo "${__cdist_type_dir}/$1/${__cdist_name_manifest}"
|
|
||||||
}
|
|
||||||
|
|
||||||
__cdist_type_parameter_dir()
|
|
||||||
{
|
|
||||||
echo "$(__cdist_type_dir "$1")/${__cdist_name_parameter}"
|
|
||||||
}
|
|
||||||
|
|
||||||
__cdist_type_parameter_optional()
|
|
||||||
{
|
|
||||||
echo "$(__cdist_type_parameter_dir "$1")/$__cdist_name_parameter_optional"
|
|
||||||
}
|
|
||||||
|
|
||||||
__cdist_type_parameter_required()
|
|
||||||
{
|
|
||||||
echo "$(__cdist_type_parameter_dir "$1")/$__cdist_name_parameter_required"
|
|
||||||
}
|
|
||||||
|
|
||||||
__cdist_type_singleton()
|
|
||||||
{
|
|
||||||
echo "${__cdist_type_dir}/$1/${__cdist_name_singleton}"
|
|
||||||
}
|
|
|
@ -1,6 +1,9 @@
|
||||||
2.0.0:
|
2.0.1:
|
||||||
|
* Bugfix cdist: Always print source of error in case of exec errors
|
||||||
|
|
||||||
|
2.0.0: 2011-09-16
|
||||||
* New Type: __package_rubygem (Chase Allen James)
|
* New Type: __package_rubygem (Chase Allen James)
|
||||||
* __self replaced by __object_fq (or so)
|
* __self replaced by __object_fq
|
||||||
* Rewrote cdist in Python
|
* Rewrote cdist in Python
|
||||||
|
|
||||||
1.7.1: 2011-07-26
|
1.7.1: 2011-07-26
|
||||||
|
|
63
doc/dev/logs/2011-09-16.benchmark-r815-no-control-socket
Normal file
63
doc/dev/logs/2011-09-16.benchmark-r815-no-control-socket
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
48 core
|
||||||
|
model name : AMD Opteron(tm) Processor 6174
|
||||||
|
128 GB RAM
|
||||||
|
Dell PowerEdge R815
|
||||||
|
|
||||||
|
root@sgs-r815-01:~/cdist-nutzung# grep "Total processing time for" deploy-all-benchmark-noikr13
|
||||||
|
INFO: Total processing time for 1 host(s): 257.641541
|
||||||
|
INFO: Total processing time for 2 host(s): 257.025783
|
||||||
|
INFO: Total processing time for 3 host(s): 258.933088
|
||||||
|
INFO: Total processing time for 4 host(s): 259.253074
|
||||||
|
INFO: Total processing time for 5 host(s): 260.331896
|
||||||
|
INFO: Total processing time for 6 host(s): 262.051349
|
||||||
|
INFO: Total processing time for 7 host(s): 323.820878
|
||||||
|
INFO: Total processing time for 8 host(s): 329.081856
|
||||||
|
INFO: Total processing time for 9 host(s): 333.346278
|
||||||
|
INFO: Total processing time for 10 host(s): 334.832419
|
||||||
|
INFO: Total processing time for 11 host(s): 330.572375
|
||||||
|
INFO: Total processing time for 12 host(s): 331.726628
|
||||||
|
INFO: Total processing time for 13 host(s): 331.740591
|
||||||
|
INFO: Total processing time for 14 host(s): 331.237139
|
||||||
|
INFO: Total processing time for 15 host(s): 331.718861
|
||||||
|
INFO: Total processing time for 16 host(s): 332.374645
|
||||||
|
INFO: Total processing time for 17 host(s): 331.510445
|
||||||
|
INFO: Total processing time for 18 host(s): 332.030743
|
||||||
|
INFO: Total processing time for 19 host(s): 332.193198
|
||||||
|
INFO: Total processing time for 20 host(s): 333.933765
|
||||||
|
INFO: Total processing time for 21 host(s): 335.292953
|
||||||
|
INFO: Total processing time for 22 host(s): 337.253608
|
||||||
|
INFO: Total processing time for 23 host(s): 337.831493
|
||||||
|
INFO: Total processing time for 24 host(s): 339.024737
|
||||||
|
INFO: Total processing time for 25 host(s): 343.515044
|
||||||
|
INFO: Total processing time for 26 host(s): 339.759678
|
||||||
|
INFO: Total processing time for 27 host(s): 339.378998
|
||||||
|
INFO: Total processing time for 28 host(s): 339.640378
|
||||||
|
INFO: Total processing time for 29 host(s): 340.885614
|
||||||
|
INFO: Total processing time for 30 host(s): 341.836923
|
||||||
|
INFO: Total processing time for 31 host(s): 343.825758
|
||||||
|
INFO: Total processing time for 32 host(s): 344.176089
|
||||||
|
INFO: Total processing time for 33 host(s): 345.408518
|
||||||
|
INFO: Total processing time for 34 host(s): 347.15322
|
||||||
|
INFO: Total processing time for 35 host(s): 351.330649
|
||||||
|
INFO: Total processing time for 36 host(s): 347.640758
|
||||||
|
INFO: Total processing time for 37 host(s): 347.381126
|
||||||
|
INFO: Total processing time for 38 host(s): 347.053406
|
||||||
|
INFO: Total processing time for 39 host(s): 347.453166
|
||||||
|
INFO: Total processing time for 40 host(s): 347.84804
|
||||||
|
INFO: Total processing time for 41 host(s): 349.035272
|
||||||
|
INFO: Total processing time for 42 host(s): 349.41507
|
||||||
|
INFO: Total processing time for 43 host(s): 351.208072
|
||||||
|
INFO: Total processing time for 44 host(s): 351.788401
|
||||||
|
INFO: Total processing time for 45 host(s): 351.730259
|
||||||
|
INFO: Total processing time for 46 host(s): 515.693497
|
||||||
|
INFO: Total processing time for 47 host(s): 352.702677
|
||||||
|
INFO: Total processing time for 48 host(s): 353.418003
|
||||||
|
INFO: Total processing time for 49 host(s): 355.07111
|
||||||
|
INFO: Total processing time for 50 host(s): 354.622388
|
||||||
|
INFO: Total processing time for 51 host(s): 355.192521
|
||||||
|
INFO: Total processing time for 52 host(s): 355.283238
|
||||||
|
INFO: Total processing time for 53 host(s): 358.112329
|
||||||
|
INFO: Total processing time for 54 host(s): 357.717426
|
||||||
|
INFO: Total processing time for 55 host(s): 357.748707
|
||||||
|
INFO: Total processing time for 56 host(s): 358.902118
|
||||||
|
INFO: Total processing time for 57 host(s): 367.817594
|
1373
doc/dev/logs/2011-09-16.benchmark-r815-no-control-socket.dmidecode
Normal file
1373
doc/dev/logs/2011-09-16.benchmark-r815-no-control-socket.dmidecode
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,23 @@
|
||||||
|
2.0.1:
|
||||||
|
|
||||||
|
- Rewrite cdist-type-emulator
|
||||||
|
- Remove legacy code in cdist
|
||||||
|
- Remove cdist-config
|
||||||
|
- Remove man1/cdist-type-emulator.text
|
||||||
|
- Remove the PATH=... part from the README
|
||||||
|
|
||||||
|
- how to access output dir?
|
||||||
|
|
||||||
|
Test:
|
||||||
|
__cdist_type_base_dir=$(pwd -P)/conf/type __file
|
||||||
|
|
||||||
|
- Fix / rewrite cdist-quickstart
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
- Initial install support
|
- Initial install support
|
||||||
- setup $__install = "" for
|
- setup $__install = "yes" for
|
||||||
manifest(s)
|
manifest(s), gencode-*
|
||||||
|
|
||||||
- run standard manifest (?)
|
- run standard manifest (?)
|
||||||
- creates initial objects
|
- creates initial objects
|
||||||
|
@ -11,17 +28,16 @@
|
||||||
- run all other manifests
|
- run all other manifests
|
||||||
- creates all objects
|
- creates all objects
|
||||||
- what about type explorer?
|
- what about type explorer?
|
||||||
|
- do not run, create empty output (types should be able
|
||||||
|
to handle this!)
|
||||||
|
via __global/
|
||||||
|
|
||||||
- Support parallel execution
|
- Support parallel execution
|
||||||
- and maximum number of parallel runs (-p X)
|
- and maximum number of parallel runs (-p X)
|
||||||
- error handling / report failed hosts
|
- error handling / report failed hosts
|
||||||
|
|
||||||
- Rewrite cdist-type-emulator
|
|
||||||
- Remove legacy code in cdist
|
|
||||||
- Remove cdist-config
|
|
||||||
- Remove man1/cdist-type-emulator.text
|
|
||||||
- Remove the PATH=... part from the README
|
|
||||||
|
|
||||||
- Allow manifest to be read from stdin
|
- Allow manifest to be read from stdin
|
||||||
- Create new video for cdist 2.0.0
|
- Create new video for cdist 2.0.0
|
||||||
http://www.youtube.com/watch?v=PRMjzy48eTI
|
http://www.youtube.com/watch?v=PRMjzy48eTI
|
||||||
|
|
||||||
|
- Setup __debug, if -d is given, so other tools can reuse it
|
||||||
|
|
|
@ -82,6 +82,14 @@ cdist --version
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
ENVIRONMENT
|
||||||
|
-----------
|
||||||
|
TMPDIR, TEMP, TMP::
|
||||||
|
Setup the base directory for the temporary directory.
|
||||||
|
See http://docs.python.org/py3k/library/tempfile.html for
|
||||||
|
more information. This is rather useful, if the standard
|
||||||
|
directory used does not allow executables.
|
||||||
|
|
||||||
SEE ALSO
|
SEE ALSO
|
||||||
--------
|
--------
|
||||||
- cdist(7)
|
- cdist(7)
|
||||||
|
|
|
@ -1,182 +0,0 @@
|
||||||
#!/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/>.
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# Wrapper script that generates cconfig from arguments
|
|
||||||
#
|
|
||||||
# This script will be called everytime the manifest decides to create
|
|
||||||
# a new type
|
|
||||||
#
|
|
||||||
|
|
||||||
. cdist-config
|
|
||||||
set -u
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# Prepare object and type
|
|
||||||
#
|
|
||||||
|
|
||||||
__cdist_type="$__cdist_myname"
|
|
||||||
|
|
||||||
# Find out whether type is a singleton or regular type
|
|
||||||
if [ -f "$(__cdist_type_singleton "$__cdist_type")" ]; then
|
|
||||||
__cdist_object_id="$__cdist_name_singleton"
|
|
||||||
else
|
|
||||||
[ $# -ge 1 ] || __cdist_usage "<id> <options>"
|
|
||||||
__cdist_object_id="$1"; shift
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Verify object id
|
|
||||||
__cdist_object_id_sane=$(echo "$__cdist_object_id" | grep "^${__cdist_sane_regexp}\$")
|
|
||||||
if [ -z "$__cdist_object_id_sane" ]; then
|
|
||||||
__cdist_usage "Insane object id, ${__cdist_object_id}."
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Prevent double slash if id begins with /
|
|
||||||
if [ "$(echo $__cdist_object_id | grep "^/")" ]; then
|
|
||||||
__cdist_object_self="${__cdist_type}${__cdist_object_id}"
|
|
||||||
else
|
|
||||||
__cdist_object_self="${__cdist_type}/${__cdist_object_id}"
|
|
||||||
fi
|
|
||||||
################################################################################
|
|
||||||
# Internal quirks
|
|
||||||
#
|
|
||||||
|
|
||||||
# Append id for error messages
|
|
||||||
__cdist_myname="$__cdist_myname ($__cdist_object_id)"
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# Create object in tmpdir first
|
|
||||||
#
|
|
||||||
|
|
||||||
# Save original destination
|
|
||||||
__cdist_out_object_dir_orig="$__cdist_out_object_dir"
|
|
||||||
|
|
||||||
# Store to tmp now
|
|
||||||
__cdist_out_object_dir="$__cdist_tmp_dir"
|
|
||||||
|
|
||||||
__cdist_new_object_dir="$(__cdist_object_dir "$__cdist_object_self")"
|
|
||||||
|
|
||||||
# Initialise object
|
|
||||||
mkdir -p "${__cdist_new_object_dir}"
|
|
||||||
|
|
||||||
# Record parameter
|
|
||||||
__cdist_parameter_dir="$(__cdist_object_parameter_dir "$__cdist_object_self")"
|
|
||||||
mkdir -p "${__cdist_parameter_dir}"
|
|
||||||
|
|
||||||
while [ $# -gt 0 ]; do
|
|
||||||
opt="$1"; shift
|
|
||||||
|
|
||||||
echo "$opt" | grep -q "^--${__cdist_sane_regexp}\$" || \
|
|
||||||
__cdist_usage "Provide sane options"
|
|
||||||
|
|
||||||
opt_file="${opt#--}"
|
|
||||||
|
|
||||||
[ $# -ge 1 ] || __cdist_usage "Missing value for $opt"
|
|
||||||
|
|
||||||
value="$1"; shift
|
|
||||||
|
|
||||||
echo "${value}" > "${__cdist_parameter_dir}/${opt_file}"
|
|
||||||
done
|
|
||||||
|
|
||||||
# Record requirements
|
|
||||||
# it's fine, if it's not set
|
|
||||||
set +u
|
|
||||||
for requirement in $require; do
|
|
||||||
echo $requirement >> "$(__cdist_object_require "$__cdist_object_self")"
|
|
||||||
__cdist_echo info "Recording requirement $requirement"
|
|
||||||
done
|
|
||||||
set -u
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# Check newly created object
|
|
||||||
#
|
|
||||||
|
|
||||||
#
|
|
||||||
# Ensure required parameters are given
|
|
||||||
#
|
|
||||||
if [ -f "$(__cdist_type_parameter_required "$__cdist_type")" ]; then
|
|
||||||
while read required; do
|
|
||||||
if [ ! -f "${__cdist_parameter_dir}/${required}" ]; then
|
|
||||||
__cdist_usage "Missing required parameter $required"
|
|
||||||
fi
|
|
||||||
done < "$(__cdist_type_parameter_required "$__cdist_type")"
|
|
||||||
fi
|
|
||||||
|
|
||||||
#
|
|
||||||
# Ensure that only optional or required parameters are given
|
|
||||||
#
|
|
||||||
|
|
||||||
if [ -f "$(__cdist_type_parameter_optional "$__cdist_type")" ]; then
|
|
||||||
cat "$(__cdist_type_parameter_optional "$__cdist_type")" > \
|
|
||||||
"$__cdist_tmp_file"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -f "$(__cdist_type_parameter_required "$__cdist_type")" ]; then
|
|
||||||
cat "$(__cdist_type_parameter_required "$__cdist_type")" >> \
|
|
||||||
"$__cdist_tmp_file"
|
|
||||||
fi
|
|
||||||
|
|
||||||
cd "$__cdist_parameter_dir"
|
|
||||||
for parameter in $(ls -1); do
|
|
||||||
is_valid=$(grep "^$parameter\$" "$__cdist_tmp_file")
|
|
||||||
|
|
||||||
[ "$is_valid" ] || __cdist_usage "Unknown parameter $parameter"
|
|
||||||
done
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# Merge object
|
|
||||||
#
|
|
||||||
# Restore original destination
|
|
||||||
__cdist_out_object_dir="$__cdist_out_object_dir_orig"
|
|
||||||
|
|
||||||
__cdist_object_dir="$(__cdist_object_dir "$__cdist_object_self")"
|
|
||||||
|
|
||||||
#
|
|
||||||
# If the object already exists and is exactly the same, merge it. Otherwise fail.
|
|
||||||
#
|
|
||||||
if [ -e "${__cdist_object_dir}" ]; then
|
|
||||||
# Allow diff to fail
|
|
||||||
set +e
|
|
||||||
diff -ru "${__cdist_new_object_dir}/${__cdist_name_parameter}" \
|
|
||||||
"${__cdist_object_dir}/${__cdist_name_parameter}" \
|
|
||||||
> "$__cdist_tmp_file"; ret=$?
|
|
||||||
set -e
|
|
||||||
|
|
||||||
if [ "$ret" != 0 ]; then
|
|
||||||
# Go to standard error
|
|
||||||
exec >&2
|
|
||||||
echo "${__cdist_object_self} already exists differently."
|
|
||||||
echo "Recorded source(s):"
|
|
||||||
__cdist_object_source "${__cdist_object_dir}"
|
|
||||||
echo "Differences:"
|
|
||||||
cat "$__cdist_tmp_file"
|
|
||||||
__cdist_exit_err "Aborting due to object conflict."
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
#
|
|
||||||
# Move object into tree:
|
|
||||||
# Create full path minus .cdist and move .cdist
|
|
||||||
#
|
|
||||||
__cdist_new_object_base_dir="$(__cdist_object_base_dir "$__cdist_object_self")"
|
|
||||||
mkdir -p "$__cdist_new_object_base_dir"
|
|
||||||
mv "$__cdist_new_object_dir" "$__cdist_new_object_base_dir"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Add "I was here message"
|
|
||||||
__cdist_object_source_add "${__cdist_object_dir}"
|
|
Loading…
Reference in a new issue