cleanup cdist_tree_wrapper

Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
Nico Schottelius 2011-02-02 15:02:26 +01:00
parent f7f687995b
commit 3ead0e5912
2 changed files with 18 additions and 14 deletions

View file

@ -58,6 +58,9 @@ __cdist_abs_myname="$__cdist_abs_mydir/$__cdist_myname"
# Used for generating binaries in cdist-build-bin # Used for generating binaries in cdist-build-bin
__cdist_bin_prefix="__" __cdist_bin_prefix="__"
# Used for IDs
__cdist_sane_chars='[A-Za-z0-9_]'
################################################################################ ################################################################################
# Function list # Function list
# #
@ -79,6 +82,11 @@ __cdist_usage()
__cdist_exit_err "$__cdist_myname: $@" __cdist_exit_err "$__cdist_myname: $@"
} }
__cdist_cache_host()
{
echo "${__cdist_cache_hosts}/${__cdist_target_host}"
}
#set -e #set -e

View file

@ -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.
# #
@ -24,35 +24,31 @@
# a new type # a new type
# #
. cdist-config . cdist-config
[ $# -ge 1 ] || __cdist_usage "<id> <options>" [ $# -ge 1 ] || __cdist_usage "<id> <options>"
echo "I am $__cdist_myname and have been called with $@" 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) echo "$__cdist_id" | grep -q "^${__cdist_sane_chars}*\$" || __cdist_usage "Provide sane id, please"
sanechars='[A-Za-z0-9_]'
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}" if [ -e "${__cdist_ddir}" ]; then
ddir="${cdist_confdir}/${tid}"
if [ -e "${ddir}" ]; then
# FIXME: add source! $cdist_config_base/source # FIXME: add source! $cdist_config_base/source
# FIXME: force $source information to be present from outside! # FIXME: force $source information to be present from outside!
__cdist_usage "${tid} already exists" __cdist_usage "${__cdist_tid} already exists"
fi fi
mkdir -p "${ddir}" mkdir -p "${__cdist_ddir}"
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
opt="$1"; shift 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/^--//')" opt_file="$(echo $opt | sed 's/^--//')"
@ -63,7 +59,7 @@ while [ $# -gt 0 ]; do
value="$1"; shift value="$1"; shift
echo "${value}" > "${ddir}/${opt_file}" echo "${value}" > "${__cdist_ddir}/${opt_file}"