add some checks, more types

Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
Nico Schottelius 2010-12-01 20:48:15 +01:00
parent a78eb81951
commit e06c0824dc
3 changed files with 38 additions and 6 deletions

View file

@ -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}."

View file

@ -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

View file

@ -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