|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# 2010-2011 Nico Schottelius (nico-cdist at schottelius.org)
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
# This script will be called everytime the manifest decides to create
|
|
|
|
# a new type
|
|
|
|
#
|
|
|
|
|
|
|
|
. cdist-config
|
|
|
|
|
|
|
|
[ $# -ge 1 ] || __cdist_usage "<id> <options>"
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
export __cdist_object_id="$1"; shift
|
|
|
|
export __cdist_type="$__cdist_myname"
|
|
|
|
|
|
|
|
echo "$__cdist_object_id" | grep -q "^${__cdist_sane_regexp}\$" || \
|
|
|
|
__cdist_usage "Insane object id, ${__cdist_object_id}."
|
|
|
|
|
|
|
|
__cdist_object="${__cdist_type}/${__cdist_object_id}"
|
|
|
|
__cdist_ddir="$__cdist_output_dir/${__cdist_object}"
|
|
|
|
|
|
|
|
# Append id for error messages
|
|
|
|
__cdist_myname="$__cdist_myname ($__cdist_object_id)"
|
|
|
|
|
|
|
|
if [ -e "${__cdist_ddir}" ]; then
|
|
|
|
source="$(__cdist_object_source "${__cdist_ddir}")"
|
|
|
|
__cdist_exit_err "${__cdist_object} already exists (source: $source)"
|
|
|
|
fi
|
|
|
|
|
|
|
|
mkdir -p "${__cdist_ddir}"
|
|
|
|
|
|
|
|
# Record (correct ;-) source
|
|
|
|
echo "${__cdist_manifest}" > "${__cdist_ddir}/${__cdist_name_object_source}"
|
|
|
|
|
|
|
|
# Record parameters to subdir
|
|
|
|
tempparams="${__cdist_tmp_dir}/params"
|
|
|
|
mkdir -p "$tempparams"
|
|
|
|
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
opt="$1"; shift
|
|
|
|
|
|
|
|
echo "$opt" | grep -q "^--${__cdist_sane_regexp}\$" || \
|
|
|
|
__cdist_usage "Provide sane options"
|
|
|
|
|
|
|
|
opt_file="$(echo $opt | sed 's/^--//')"
|
|
|
|
|
|
|
|
[ $# -ge 1 ] || __cdist_usage "Missing value for $opt"
|
|
|
|
|
|
|
|
value="$1"; shift
|
|
|
|
|
|
|
|
echo "${value}" > "${tempparams}/${opt_file}"
|
|
|
|
done
|
|
|
|
|
|
|
|
# Ensure required parameters are given
|
|
|
|
while read required; do
|
|
|
|
if [ ! -f "${tempparams}/${required}" ]; then
|
|
|
|
__cdist_usage "Missing required parameter $required"
|
|
|
|
fi
|
|
|
|
|
|
|
|
mv "${tempparams}/${required}" "${__cdist_ddir}"
|
|
|
|
done < "$(__cdist_type_param_file "$__cdist_type" "$__cdist_name_type_params_required")"
|
|
|
|
|
|
|
|
# Allow optional parameters
|
|
|
|
while read optional; do
|
|
|
|
if [ -f "${tempparams}/${optional}" ]; then
|
|
|
|
mv "${tempparams}/${optional}" "${__cdist_ddir}"
|
|
|
|
fi
|
|
|
|
done < "$(__cdist_type_param_file "$__cdist_type" "$__cdist_name_type_params_optional")"
|
|
|
|
|
|
|
|
# Error out on other paramaters
|
|
|
|
cd "${tempparams}"
|
|
|
|
other="$(ls)"
|
|
|
|
|
|
|
|
if [ "$other" ]; then
|
|
|
|
__cdist_usage "Unsupported parameter: $other"
|
|
|
|
fi
|