From 3ead0e591210da93681f0f3887dbc580af065060 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 2 Feb 2011 15:02:26 +0100 Subject: [PATCH] cleanup cdist_tree_wrapper Signed-off-by: Nico Schottelius --- bin/cdist-config | 8 ++++++++ bin/cdist_tree_wrapper | 24 ++++++++++-------------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/bin/cdist-config b/bin/cdist-config index 60f06f08..c69bb0c4 100755 --- a/bin/cdist-config +++ b/bin/cdist-config @@ -58,6 +58,9 @@ __cdist_abs_myname="$__cdist_abs_mydir/$__cdist_myname" # Used for generating binaries in cdist-build-bin __cdist_bin_prefix="__" +# Used for IDs +__cdist_sane_chars='[A-Za-z0-9_]' + ################################################################################ # Function list # @@ -79,6 +82,11 @@ __cdist_usage() __cdist_exit_err "$__cdist_myname: $@" } +__cdist_cache_host() +{ + echo "${__cdist_cache_hosts}/${__cdist_target_host}" +} + #set -e diff --git a/bin/cdist_tree_wrapper b/bin/cdist_tree_wrapper index 5abe6f7a..6be8806e 100755 --- a/bin/cdist_tree_wrapper +++ b/bin/cdist_tree_wrapper @@ -1,6 +1,6 @@ #!/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. # @@ -24,35 +24,31 @@ # a new type # - . cdist-config [ $# -ge 1 ] || __cdist_usage " " echo "I am $__cdist_myname and have been called with $@" -id="$1"; shift +__cdist_id="$1"; shift -# FIXME: find a better definiton of sane (i.e. everything that is a valid filename) -sanechars='[A-Za-z0-9_]' +echo "$__cdist_id" | grep -q "^${__cdist_sane_chars}*\$" || __cdist_usage "Provide sane id, please" -echo "$id" | grep -q "^${sanechars}*\$" || __cdist_usage "Provide sane id, please" +__cdist_tid="${__cdist_myname}/${__cdist_id}" +__cdist_ddir="$(__cdist_cache_host)/${__cdist_tid}" -tid="${__cdist_myname}/${id}" -ddir="${cdist_confdir}/${tid}" - -if [ -e "${ddir}" ]; then +if [ -e "${__cdist_ddir}" ]; then # FIXME: add source! $cdist_config_base/source # FIXME: force $source information to be present from outside! - __cdist_usage "${tid} already exists" + __cdist_usage "${__cdist_tid} already exists" fi -mkdir -p "${ddir}" +mkdir -p "${__cdist_ddir}" while [ $# -gt 0 ]; do opt="$1"; shift - echo "$opt" | grep -q "^--${sanechars}*\$" || __cdist_usage "Provide sane options" + echo "$opt" | grep -q "^--${__cdist_sane_chars}*\$" || __cdist_usage "Provide sane options" opt_file="$(echo $opt | sed 's/^--//')" @@ -63,7 +59,7 @@ while [ $# -gt 0 ]; do value="$1"; shift - echo "${value}" > "${ddir}/${opt_file}" + echo "${value}" > "${__cdist_ddir}/${opt_file}"