2010-09-19 12:13:13 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# 2010 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
|
|
|
|
#
|
|
|
|
|
2011-02-05 18:32:29 +00:00
|
|
|
|
2011-02-02 20:49:01 +00:00
|
|
|
# Values can be overriden from outside, so you can
|
|
|
|
# customise paths as you like (for distributors, geeks and hackers)
|
2011-02-02 13:23:54 +00:00
|
|
|
|
2011-02-05 18:41:47 +00:00
|
|
|
# Names
|
|
|
|
: ${__cdist_name_bin:=bin}
|
|
|
|
: ${__cdist_name_cache:=cache}
|
2011-02-07 23:26:26 +00:00
|
|
|
: ${__cdist_name_code:=code}
|
2011-02-04 21:49:20 +00:00
|
|
|
: ${__cdist_name_explorer:=explorers}
|
2011-02-14 10:28:14 +00:00
|
|
|
: ${__cdist_name_gencode:=gencode}
|
2011-02-05 18:41:47 +00:00
|
|
|
: ${__cdist_name_host:=hosts}
|
|
|
|
: ${__cdist_name_init:=init}
|
2011-02-17 08:17:13 +00:00
|
|
|
|
|
|
|
# Name of the manifest file in types
|
|
|
|
: ${__cdist_name_manifest:=manifest}
|
|
|
|
|
|
|
|
# Name of the base directory containing the initial manifests
|
|
|
|
: ${__cdist_name_manifests:=manifests}
|
2011-02-05 18:41:47 +00:00
|
|
|
: ${__cdist_name_object:=objects}
|
2011-02-16 22:04:02 +00:00
|
|
|
|
2011-02-05 18:41:47 +00:00
|
|
|
: ${__cdist_name_type:=types}
|
2011-02-16 22:04:02 +00:00
|
|
|
: ${__cdist_name_type_params:=parameters}
|
|
|
|
: ${__cdist_name_type_params_required:=required}
|
|
|
|
: ${__cdist_name_type_params_optional:=optional}
|
2011-02-16 19:14:40 +00:00
|
|
|
|
|
|
|
# Name of the executable generated
|
2011-02-16 19:12:29 +00:00
|
|
|
: ${__cdist_name_exec:=exec}
|
|
|
|
|
|
|
|
# File that contains source of a specific object creation
|
2011-02-16 19:14:40 +00:00
|
|
|
: ${__cdist_name_object_source:=.source}
|
|
|
|
|
|
|
|
# Marks an object finished
|
|
|
|
: ${__cdist_name_object_finished:=.done}
|
2011-02-16 19:12:29 +00:00
|
|
|
|
2011-02-04 21:49:20 +00:00
|
|
|
|
2011-02-05 18:41:47 +00:00
|
|
|
# Base
|
|
|
|
: ${__cdist_config:=/etc/cdist}
|
2011-02-05 18:42:49 +00:00
|
|
|
: ${__cdist_explorer_dir:=$__cdist_config/$__cdist_name_explorer}
|
2011-02-17 08:17:13 +00:00
|
|
|
: ${__cdist_manifest_dir:=$__cdist_config/$__cdist_name_manifests}
|
2011-02-05 18:41:47 +00:00
|
|
|
: ${__cdist_manifest_init:=$__cdist_manifest_dir/$__cdist_name_init}
|
|
|
|
: ${__cdist_type_dir:=$__cdist_config/$__cdist_name_type}
|
2011-02-02 13:01:21 +00:00
|
|
|
|
2011-02-05 18:41:47 +00:00
|
|
|
# Cache
|
2011-02-02 13:23:54 +00:00
|
|
|
: ${__cdist_cache_dir:=$__cdist_config/cache}
|
2011-02-05 18:41:47 +00:00
|
|
|
: ${__cdist_cache_hosts:=$__cdist_cache_dir/$__cdist_name_host}
|
|
|
|
: ${__cdist_cache_bin:=$__cdist_cache_dir/$__cdist_name_bin}
|
2011-02-02 13:23:54 +00:00
|
|
|
|
2011-02-04 13:38:17 +00:00
|
|
|
|
2011-02-05 18:42:49 +00:00
|
|
|
# Remote
|
2011-02-04 13:38:17 +00:00
|
|
|
: ${__cdist_remote_base_dir:=/var/lib/cdist}
|
2011-02-04 21:49:20 +00:00
|
|
|
: ${__cdist_remote_explorer_dir:=$__cdist_remote_base_dir/$__cdist_name_explorer}
|
2011-02-04 21:39:26 +00:00
|
|
|
export __cdist_remote_explorer_dir
|
2011-02-05 18:41:47 +00:00
|
|
|
: ${__cdist_remote_cache_dir:=$__cdist_remote_base_dir/$__cdist_name_cache}
|
2011-02-04 21:49:20 +00:00
|
|
|
: ${__cdist_remote_cache_explorer:=$__cdist_remote_cache_dir/$__cdist_name_explorer}
|
2011-02-04 21:39:26 +00:00
|
|
|
export __cdist_remote_cache_explorer
|
2011-02-05 18:41:47 +00:00
|
|
|
: ${__cdist_remote_cache_bin:=$__cdist_remote_base_dir/$__cdist_name_bin}
|
2011-02-17 14:11:41 +00:00
|
|
|
: ${__cdist_remote_cache_exec:=$__cdist_remote_base_dir/$__cdist_name_exec}
|
2011-02-04 13:38:17 +00:00
|
|
|
|
2011-02-05 18:32:29 +00:00
|
|
|
# Tempfiles need to be recreated for each individual script, unshared!
|
|
|
|
__cdist_tmp_dir=$(mktemp -d "/tmp/cdist.XXXXXXXXXXXX")
|
|
|
|
export __cdist_tmp_dir
|
|
|
|
__cdist_tmp_file=$(mktemp "$__cdist_tmp_dir/cdist.XXXXXXXXXXXX")
|
|
|
|
export __cdist_tmp_file
|
2010-09-30 17:09:21 +00:00
|
|
|
|
2010-09-29 16:55:18 +00:00
|
|
|
################################################################################
|
|
|
|
# cconf standard vars prefixed with cdist
|
|
|
|
__cdist_pwd="$(pwd -P)"
|
|
|
|
__cdist_mydir="${0%/*}";
|
2010-09-30 17:09:21 +00:00
|
|
|
__cdist_abs_mydir="$(cd "$__cdist_mydir" && pwd -P)"
|
2010-09-29 16:55:18 +00:00
|
|
|
__cdist_myname=${0##*/};
|
2010-09-30 17:09:21 +00:00
|
|
|
__cdist_abs_myname="$__cdist_abs_mydir/$__cdist_myname"
|
2010-09-29 16:55:18 +00:00
|
|
|
|
2011-02-02 13:55:28 +00:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Other constants
|
|
|
|
|
2011-02-02 14:02:26 +00:00
|
|
|
# Used for IDs
|
2011-02-02 20:43:11 +00:00
|
|
|
__cdist_sane_regexp='[A-Za-z0-9]*[-A-Za-z0-9_]*'
|
2011-02-02 13:01:21 +00:00
|
|
|
################################################################################
|
|
|
|
# Function list
|
|
|
|
#
|
2010-09-29 16:55:18 +00:00
|
|
|
__cdist_debug_echo()
|
2010-09-25 10:36:30 +00:00
|
|
|
{
|
2011-02-02 13:01:21 +00:00
|
|
|
if [ "$__cdist_debug" ]; then
|
2010-09-30 17:09:21 +00:00
|
|
|
echo "Debug: $@"
|
|
|
|
fi
|
2010-09-25 10:36:30 +00:00
|
|
|
}
|
2010-09-19 12:30:36 +00:00
|
|
|
|
2011-02-02 13:55:28 +00:00
|
|
|
__cdist_exit_err()
|
2010-09-29 16:55:18 +00:00
|
|
|
{
|
2011-02-17 15:07:07 +00:00
|
|
|
echo "$@" >&2
|
2010-09-29 16:55:18 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2011-02-02 13:55:28 +00:00
|
|
|
__cdist_usage()
|
|
|
|
{
|
|
|
|
__cdist_exit_err "$__cdist_myname: $@"
|
|
|
|
}
|
|
|
|
|
2011-02-02 14:02:26 +00:00
|
|
|
__cdist_cache_host()
|
|
|
|
{
|
|
|
|
echo "${__cdist_cache_hosts}/${__cdist_target_host}"
|
|
|
|
}
|
2011-02-05 18:32:29 +00:00
|
|
|
|
2011-02-07 16:50:25 +00:00
|
|
|
__cdist_type_mydir()
|
|
|
|
{
|
|
|
|
echo "${__cdist_type_dir}/${__cdist_type_current}"
|
|
|
|
}
|
|
|
|
|
2011-02-16 18:44:04 +00:00
|
|
|
__cdist_type_gencode()
|
|
|
|
{
|
|
|
|
local type="$1"
|
|
|
|
|
|
|
|
echo "${__cdist_type_dir}/${type}/$__cdist_name_gencode"
|
|
|
|
}
|
|
|
|
|
2011-02-16 22:04:02 +00:00
|
|
|
__cdist_type_param_file()
|
|
|
|
{
|
|
|
|
local type="$1"; shift
|
|
|
|
local paramtype="$1"; shift
|
|
|
|
|
|
|
|
echo "${__cdist_type_dir}/$type/$__cdist_name_type_params/$paramtype"
|
|
|
|
}
|
|
|
|
|
2011-02-16 18:44:04 +00:00
|
|
|
__cdist_object_arg()
|
|
|
|
{
|
|
|
|
local arg="$1"; shift
|
|
|
|
local object="$1"; shift
|
|
|
|
|
|
|
|
cat "${__cdist_object_base_dir}/${object}/${arg}"
|
|
|
|
}
|
|
|
|
|
2011-02-16 19:12:29 +00:00
|
|
|
__cdist_object_list()
|
|
|
|
{
|
|
|
|
local basedir="$1"; shift
|
|
|
|
|
2011-02-17 08:17:13 +00:00
|
|
|
# Use subshell to prevent changing cwd in program
|
|
|
|
(
|
|
|
|
cd "${basedir}"
|
|
|
|
|
|
|
|
find . -name "$__cdist_name_object_source" | \
|
|
|
|
sed -e "s;$__cdist_name_object_source\$;;" -e 's;^./;;'
|
|
|
|
)
|
2011-02-16 19:12:29 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-02-16 21:11:53 +00:00
|
|
|
__cdist_object_source()
|
|
|
|
{
|
|
|
|
local object_dir="$1"; shift
|
|
|
|
|
|
|
|
cat "${object_dir}/$__cdist_name_object_source"
|
|
|
|
}
|
|
|
|
|
2011-02-05 18:32:29 +00:00
|
|
|
__cdist_tmp_removal()
|
|
|
|
{
|
|
|
|
rm -rf "${__cdist_tmp_dir}"
|
|
|
|
}
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Trap for tmp removal
|
|
|
|
#
|
|
|
|
trap __cdist_tmp_removal EXIT
|