2010-12-01 18:52:34 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2011-02-02 14:02:26 +00:00
|
|
|
# 2010-2011 Nico Schottelius (nico-cdist at schottelius.org)
|
2010-12-01 18:52:34 +00:00
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
2011-01-14 11:46:51 +00:00
|
|
|
# This script will be called everytime the manifest decides to create
|
|
|
|
# a new type
|
|
|
|
#
|
2010-12-01 18:52:34 +00:00
|
|
|
|
|
|
|
. cdist-config
|
|
|
|
|
2010-12-01 19:33:25 +00:00
|
|
|
[ $# -ge 1 ] || __cdist_usage "<id> <options>"
|
|
|
|
|
2011-02-05 18:10:48 +00:00
|
|
|
set -eu
|
|
|
|
|
2010-12-01 18:52:34 +00:00
|
|
|
echo "I am $__cdist_myname and have been called with $@"
|
2010-12-01 19:33:25 +00:00
|
|
|
|
2011-02-06 21:07:17 +00:00
|
|
|
export __cdist_object_id="$1"; shift
|
2011-02-07 16:50:25 +00:00
|
|
|
export __cdist_type_current="$__cdist_myname"
|
2010-12-01 19:33:25 +00:00
|
|
|
|
2011-02-06 21:07:17 +00:00
|
|
|
echo "$__cdist_object_id" | grep -q "^${__cdist_sane_regexp}\$" || __cdist_usage "Provide sane id, please"
|
2010-12-01 19:33:25 +00:00
|
|
|
|
2011-02-06 21:07:17 +00:00
|
|
|
__cdist_tid="${__cdist_myname}/${__cdist_object_id}"
|
2011-02-05 18:44:12 +00:00
|
|
|
__cdist_ddir="$(__cdist_cache_host)/${__cdist_name_object}/${__cdist_tid}"
|
2010-12-01 19:53:26 +00:00
|
|
|
|
2011-02-02 14:02:26 +00:00
|
|
|
if [ -e "${__cdist_ddir}" ]; then
|
2011-02-02 18:53:13 +00:00
|
|
|
source="$(cat "${__cdist_ddir}/${__cdist_object_source}")"
|
|
|
|
__cdist_usage "${__cdist_tid} already exists (source: $source)"
|
2010-12-01 19:48:15 +00:00
|
|
|
fi
|
|
|
|
|
2011-02-02 14:02:26 +00:00
|
|
|
mkdir -p "${__cdist_ddir}"
|
2010-12-01 19:48:15 +00:00
|
|
|
|
2011-02-05 18:20:59 +00:00
|
|
|
# Record (correct ;-) source
|
|
|
|
echo "${__cdist_manifest}" > "${__cdist_ddir}/${__cdist_object_source}"
|
|
|
|
|
2010-12-01 19:48:15 +00:00
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
opt="$1"; shift
|
|
|
|
|
2011-02-02 20:43:11 +00:00
|
|
|
echo "$opt" | grep -q "^--${__cdist_sane_regexp}\$" || __cdist_usage "Provide sane options"
|
2010-12-01 19:48:15 +00:00
|
|
|
|
2010-12-01 19:53:26 +00:00
|
|
|
opt_file="$(echo $opt | sed 's/^--//')"
|
2010-12-01 19:48:15 +00:00
|
|
|
|
2011-01-14 11:46:51 +00:00
|
|
|
# FIXME: check for options supported by type - or leave it to the type?
|
|
|
|
# I guess do it here, so we also check whether
|
|
|
|
|
2010-12-01 19:48:15 +00:00
|
|
|
[ $# -ge 1 ] || __cdist_usage "Missing value for $opt"
|
|
|
|
|
|
|
|
value="$1"; shift
|
|
|
|
|
2011-02-02 14:02:26 +00:00
|
|
|
echo "${value}" > "${__cdist_ddir}/${opt_file}"
|
2010-12-01 19:53:26 +00:00
|
|
|
|
2010-12-01 19:48:15 +00:00
|
|
|
done
|