From e06c0824dcd68f9f767c1c3db4237feb183cf223 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 1 Dec 2010 20:48:15 +0100 Subject: [PATCH] add some checks, more types Signed-off-by: Nico Schottelius --- test/cdist-cconfig-tree | 12 +++++++++--- test/cdist_config_base | 8 +++++++- test/cdist_tree_wrapper | 24 ++++++++++++++++++++++-- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/test/cdist-cconfig-tree b/test/cdist-cconfig-tree index a69fe525..dfe954ba 100755 --- a/test/cdist-cconfig-tree +++ b/test/cdist-cconfig-tree @@ -32,13 +32,14 @@ export cdist_types="file service user" # the file that contains mapping from hosts to types # we will execute this later -config_base="./cdist_config_base" +cdist_config_base="./cdist_config_base" cdist_tree_wrapper="./cdist_tree_wrapper" # used to build the tree and other stuff tmpdir=/tmp/cdist-test-hardcoded cdist_bindir="${tmpdir}/bin" +cdist_confdir="${tmpdir}/conf" cdist_type_prefix="__" @@ -69,10 +70,15 @@ mkdir -p "${cdist_bindir}" # prepend our path PATH="${cdist_bindir}:$PATH" +# create output dir +mkdir -p "${cdist_confdir}" + # force -x, so the user is aware the file is executed -if [ -x "${config_base}" ]; then - "${config_base}" +if [ -x "${cdist_config_base}" ]; then + "${cdist_config_base}" else echo Throw some error, as you forgot to +x it. exit 1 fi + +echo "Finished tree generation, have a look at ${cdist_confdir}." diff --git a/test/cdist_config_base b/test/cdist_config_base index d27c9813..900fc19d 100755 --- a/test/cdist_config_base +++ b/test/cdist_config_base @@ -21,6 +21,12 @@ # Define configuration, currently global, add matches later! # -__file /usr/bin/cdist --source /from/outer/space +__file cdist_bin --source /from/outer/space --destination /to/earth __user hal --uid 9000 __service puppet --status disabled + +# fails +__service puppet --status duplicated + +# fails +__service time --missing diff --git a/test/cdist_tree_wrapper b/test/cdist_tree_wrapper index 709955c1..f8f0a602 100755 --- a/test/cdist_tree_wrapper +++ b/test/cdist_tree_wrapper @@ -31,7 +31,27 @@ echo "I am $__cdist_myname and have been called with $@" id="$1"; shift # FIXME: find a better definiton of sane (i.e. everything that is a valid filename) -echo "$id" | grep -q '^[A-Za-z0-9_]*$' || __cdist_usage "Provide sane id, please" +sanechars='[A-Za-z0-9_]' + +echo "$id" | grep -q "^${sanechars}*\$" || __cdist_usage "Provide sane id, please" + +if [ -e "${cdist_confdir}/${__cdist_myname}/${id}" ]; then + # FIXME: add source! $cdist_config_base/source + __cdist_usage "${__cdist_myname}/${id} already exists" +fi + +mkdir -p "${cdist_confdir}/${__cdist_myname}/${id}" + +while [ $# -gt 0 ]; do + opt="$1"; shift + + echo "$opt" | grep -q "^--${sanechars}*\$" || __cdist_usage "Provide sane options" -echo mkdir -p "${cdist_confdir}/${__cdist_myname}/${id}" + [ $# -ge 1 ] || __cdist_usage "Missing value for $opt" + + value="$1"; shift + + + +done