|
|
|
#!/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/>.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Print configuration directories - helper for all other scripts
|
|
|
|
#
|
|
|
|
|
|
|
|
# Fail if something bogus is going on and export all variables
|
|
|
|
# The export is mainly needed for remote knowledge
|
|
|
|
set -au
|
|
|
|
|
|
|
|
# Values can be overriden from outside, so you can
|
|
|
|
# customise paths as you like (for distributors, geeks and hackers)
|
|
|
|
|
|
|
|
# Names / Constants
|
|
|
|
: ${__cdist_name_bin:=bin}
|
|
|
|
: ${__cdist_name_code:=code}
|
|
|
|
: ${__cdist_name_explorer:=explorers}
|
|
|
|
: ${__cdist_name_gencode:=gencode}
|
|
|
|
: ${__cdist_name_host:=hosts}
|
|
|
|
: ${__cdist_name_init:=init}
|
|
|
|
: ${__cdist_name_out_dir:=out}
|
|
|
|
: ${__cdist_name_conf_dir:=conf}
|
|
|
|
: ${__cdist_name_type_bin:=type_bin}
|
|
|
|
|
|
|
|
# Name of the manifest file in types
|
|
|
|
: ${__cdist_name_manifest:=manifest}
|
|
|
|
|
|
|
|
# Name of the base directory containing the initial manifests
|
|
|
|
: ${__cdist_name_manifests:=manifests}
|
|
|
|
: ${__cdist_name_object:=objects}
|
|
|
|
|
|
|
|
: ${__cdist_name_type:=types}
|
|
|
|
: ${__cdist_name_params:=parameters}
|
|
|
|
: ${__cdist_name_params_required:=required}
|
|
|
|
: ${__cdist_name_params_optional:=optional}
|
|
|
|
|
|
|
|
# Name of the executable generated
|
|
|
|
: ${__cdist_name_exec:=exec}
|
|
|
|
|
|
|
|
# File that contains source of a specific object creation
|
|
|
|
: ${__cdist_name_object_source:=.source}
|
|
|
|
|
|
|
|
# Marks an object finished
|
|
|
|
: ${__cdist_name_object_finished:=.done}
|
|
|
|
|
|
|
|
# Base
|
|
|
|
: ${__cdist_conf_dir:=/etc/cdist}
|
|
|
|
: ${__cdist_explorer_dir:=$__cdist_conf_dir/$__cdist_name_explorer}
|
|
|
|
: ${__cdist_manifest_dir:=$__cdist_conf_dir/$__cdist_name_manifests}
|
|
|
|
: ${__cdist_manifest_init:=$__cdist_manifest_dir/$__cdist_name_init}
|
|
|
|
: ${__cdist_type_dir:=$__cdist_conf_dir/$__cdist_name_type}
|
|
|
|
|
|
|
|
# Used for IDs
|
|
|
|
__cdist_sane_regexp='[A-Za-z0-9]*[-A-Za-z0-9_]*'
|
|
|
|
|
|
|
|
# Default remote user
|
|
|
|
: ${__cdist_remote_user:=root}
|
|
|
|
|
|
|
|
# Remote base
|
|
|
|
: ${__cdist_remote_base_dir:=/var/lib/cdist}
|
|
|
|
|
|
|
|
# Remote config
|
|
|
|
: ${__cdist_remote_conf_dir:=$__cdist_remote_base_dir/$__cdist_name_conf_dir}
|
|
|
|
: ${__cdist_remote_explorer_dir:=$__cdist_remote_conf_dir/$__cdist_name_explorer}
|
|
|
|
: ${__cdist_remote_bin_dir:=$__cdist_remote_conf_dir/$__cdist_name_bin}
|
|
|
|
|
|
|
|
# Remote out
|
|
|
|
: ${__cdist_remote_out_dir:=$__cdist_remote_base_dir/$__cdist_name_out_dir}
|
|
|
|
: ${__cdist_remote_out_explorer_dir:=$__cdist_remote_out_dir/$__cdist_name_explorer}
|
|
|
|
|
|
|
|
# Tempfiles
|
|
|
|
__cdist_tmp_dir=$(mktemp -d "/tmp/cdist.XXXXXXXXXXXX")
|
|
|
|
__cdist_tmp_file=$(mktemp "$__cdist_tmp_dir/cdist.XXXXXXXXXXXX")
|
|
|
|
|
|
|
|
# Local output base directory
|
|
|
|
: ${__cdist_out_dir:=$__cdist_tmp_dir/$__cdist_name_out_dir}
|
|
|
|
: ${__cdist_out_explorer_dir:=$__cdist_out_dir/$__cdist_name_explorer}
|
|
|
|
: ${__cdist_out_object_dir:=$__cdist_out_dir/$__cdist_name_object}
|
|
|
|
: ${__cdist_out_type_bin_dir:=$__cdist_out_dir/$__cdist_name_type_bin}
|
|
|
|
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# cconf standard vars prefixed with cdist
|
|
|
|
__cdist_pwd="$(pwd -P)"
|
|
|
|
__cdist_mydir="${0%/*}";
|
|
|
|
__cdist_abs_mydir="$(cd "$__cdist_mydir" && pwd -P)"
|
|
|
|
__cdist_myname=${0##*/};
|
|
|
|
__cdist_abs_myname="$__cdist_abs_mydir/$__cdist_myname"
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Function list
|
|
|
|
#
|
|
|
|
__cdist_debug_echo()
|
|
|
|
{
|
|
|
|
if [ "$__cdist_debug" ]; then
|
|
|
|
echo "Debug: $@"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
__cdist_exit_err()
|
|
|
|
{
|
|
|
|
echo "$@" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
__cdist_usage()
|
|
|
|
{
|
|
|
|
__cdist_exit_err "$__cdist_myname: $@"
|
|
|
|
}
|
|
|
|
|
|
|
|
# __cdist_cache_host()
|
|
|
|
# {
|
|
|
|
# echo "${__cdist_cache_hosts}/${__cdist_target_host}"
|
|
|
|
# }
|
|
|
|
|
|
|
|
__cdist_type_mydir()
|
|
|
|
{
|
|
|
|
echo "${__cdist_type_dir}/${__cdist_type_current}"
|
|
|
|
}
|
|
|
|
|
|
|
|
__cdist_type_explorer_dir()
|
|
|
|
{
|
|
|
|
echo "${__cdist_type_dir}/$1/$__cdist_name_explorer"
|
|
|
|
}
|
|
|
|
|
|
|
|
__cdist_type_gencode()
|
|
|
|
{
|
|
|
|
local type="$1"
|
|
|
|
|
|
|
|
echo "${__cdist_type_dir}/${type}/$__cdist_name_gencode"
|
|
|
|
}
|
|
|
|
|
|
|
|
__cdist_type_param_file()
|
|
|
|
{
|
|
|
|
local type="$1"; shift
|
|
|
|
local paramtype="$1"; shift
|
|
|
|
|
|
|
|
echo "${__cdist_type_dir}/$type/$__cdist_name_params/$paramtype"
|
|
|
|
}
|
|
|
|
|
|
|
|
__cdist_type_from_object()
|
|
|
|
{
|
|
|
|
echo "${1%%/*}"
|
|
|
|
}
|
|
|
|
|
|
|
|
__cdist_object_id_from_object()
|
|
|
|
{
|
|
|
|
echo "${1#*/}"
|
|
|
|
}
|
|
|
|
|
|
|
|
__cdist_object_arg()
|
|
|
|
{
|
|
|
|
local arg="$1"; shift
|
|
|
|
local object="$1"; shift
|
|
|
|
|
|
|
|
cat "${__cdist_object_base_dir}/${object}/${arg}"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Find objects, remove ./ and /MARKER
|
|
|
|
__cdist_object_list()
|
|
|
|
{
|
|
|
|
local basedir="$1"; shift
|
|
|
|
|
|
|
|
# Use subshell to prevent changing cwd in program
|
|
|
|
(
|
|
|
|
cd "${basedir}"
|
|
|
|
|
|
|
|
find . -name "$__cdist_name_object_source" | \
|
|
|
|
sed -e 's;^./;;' -e "s;/$__cdist_name_object_source\$;;"
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
__cdist_object_source()
|
|
|
|
{
|
|
|
|
local object_dir="$1"; shift
|
|
|
|
|
|
|
|
cat "${object_dir}/$__cdist_name_object_source"
|
|
|
|
}
|
|
|
|
|
|
|
|
__cdist_exec_fail_on_error()
|
|
|
|
{
|
|
|
|
sh -e "$@"
|
|
|
|
[ "$?" -eq 0 ] || __cdist_exit_err "Error: $1 exited non-zero."
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
__cdist_tmp_removal()
|
|
|
|
{
|
|
|
|
rm -rf "${__cdist_tmp_dir}"
|
|
|
|
}
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Trap for tmp removal
|
|
|
|
#
|
|
|
|
trap __cdist_tmp_removal EXIT
|