2010-09-19 12:13:13 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2011-02-17 16:46:18 +00:00
|
|
|
# 2010-2011 Nico Schottelius (nico-cdist at schottelius.org)
|
2010-09-19 12:13:13 +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/>.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
2011-02-23 15:45:38 +00:00
|
|
|
# Fail if something bogus is going on and export all variables
|
2011-02-24 13:28:29 +00:00
|
|
|
set -u
|
2011-02-05 18:32:29 +00:00
|
|
|
|
2011-03-03 13:49:48 +00:00
|
|
|
################################################################################
|
|
|
|
# cconf standard vars prefixed with cdist
|
2011-03-04 01:08:05 +00:00
|
|
|
|
2011-03-03 13:49:48 +00:00
|
|
|
__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"
|
|
|
|
|
2011-03-04 08:15:18 +00:00
|
|
|
: ${__cdist_version:="$(cd "$__cdist_abs_mydir/.." && git describe)"}
|
2011-03-04 08:07:48 +00:00
|
|
|
|
2011-03-03 13:49:48 +00:00
|
|
|
################################################################################
|
|
|
|
# Names / Constants
|
|
|
|
#
|
2011-02-25 00:48:18 +00:00
|
|
|
# Most values can be overriden from outside, so you can
|
2011-02-02 20:49:01 +00:00
|
|
|
# customise paths as you like (for distributors, geeks and hackers)
|
2011-03-03 13:49:48 +00:00
|
|
|
#
|
2011-02-02 13:23:54 +00:00
|
|
|
|
2011-02-05 18:41:47 +00:00
|
|
|
: ${__cdist_name_bin:=bin}
|
2011-02-07 23:26:26 +00:00
|
|
|
: ${__cdist_name_code:=code}
|
2011-02-24 23:14:26 +00:00
|
|
|
: ${__cdist_name_conf_dir:=conf}
|
2011-02-24 20:32:01 +00:00
|
|
|
: ${__cdist_name_explorer:=explorer}
|
2011-02-14 10:28:14 +00:00
|
|
|
: ${__cdist_name_gencode:=gencode}
|
2011-03-03 09:37:11 +00:00
|
|
|
: ${__cdist_name_global:=global}
|
2011-02-24 20:32:01 +00:00
|
|
|
: ${__cdist_name_host:=host}
|
2011-02-05 18:41:47 +00:00
|
|
|
: ${__cdist_name_init:=init}
|
2011-02-24 13:47:52 +00:00
|
|
|
: ${__cdist_name_manifest:=manifest}
|
2011-02-24 14:34:17 +00:00
|
|
|
: ${__cdist_name_object:=object}
|
2011-02-24 23:14:26 +00:00
|
|
|
: ${__cdist_name_object_finished:=.done}
|
2011-02-24 14:34:17 +00:00
|
|
|
: ${__cdist_name_object_id:=object_id}
|
2011-02-24 23:14:26 +00:00
|
|
|
: ${__cdist_name_object_source:=.source}
|
|
|
|
: ${__cdist_name_out_dir:=out}
|
2011-02-24 20:32:01 +00:00
|
|
|
: ${__cdist_name_parameter:=parameter}
|
|
|
|
: ${__cdist_name_parameter_required:=required}
|
|
|
|
: ${__cdist_name_parameter_optional:=optional}
|
2011-02-24 14:05:31 +00:00
|
|
|
: ${__cdist_name_target_host:=target_host}
|
2011-02-24 20:32:01 +00:00
|
|
|
: ${__cdist_name_type:=type}
|
2011-02-23 17:40:58 +00:00
|
|
|
: ${__cdist_name_type_bin:=type_bin}
|
2011-02-24 20:32:01 +00:00
|
|
|
: ${__cdist_name_type_explorer:=type_explorer}
|
|
|
|
|
2011-03-03 13:49:48 +00:00
|
|
|
# Used for IDs
|
|
|
|
: ${__cdist_sane_regexp:=[A-Za-z0-9/]*[-A-Za-z0-9_/]*}
|
2011-02-17 08:17:13 +00:00
|
|
|
|
2011-03-03 13:49:48 +00:00
|
|
|
# Default remote user
|
|
|
|
: ${__cdist_remote_user:=root}
|
|
|
|
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Exported variable names (usable for non core
|
|
|
|
#
|
2011-02-24 13:24:47 +00:00
|
|
|
: ${__cdist_name_var_explorer:=__$__cdist_name_explorer}
|
2011-02-24 20:32:01 +00:00
|
|
|
: ${__cdist_name_var_type_explorer:=__$__cdist_name_type_explorer}
|
2011-03-03 09:37:11 +00:00
|
|
|
: ${__cdist_name_var_global:=__$__cdist_name_global}
|
2011-02-24 20:32:01 +00:00
|
|
|
: ${__cdist_name_var_manifest:=__$__cdist_name_manifest}
|
2011-02-24 14:05:31 +00:00
|
|
|
: ${__cdist_name_var_target_host:=__$__cdist_name_target_host}
|
2011-02-24 14:34:17 +00:00
|
|
|
: ${__cdist_name_var_object:=__$__cdist_name_object}
|
|
|
|
: ${__cdist_name_var_object_id:=__$__cdist_name_object_id}
|
2011-02-25 17:42:38 +00:00
|
|
|
: ${__cdist_name_var_type:=__$__cdist_name_type}
|
2011-02-17 08:17:13 +00:00
|
|
|
|
2011-02-16 19:12:29 +00:00
|
|
|
|
2011-03-03 14:27:51 +00:00
|
|
|
################################################################################
|
|
|
|
# Tempfiles
|
|
|
|
#
|
|
|
|
__cdist_tmp_dir=$(mktemp -d "/tmp/cdist.XXXXXXXXXXXX")
|
|
|
|
__cdist_tmp_file=$(mktemp "$__cdist_tmp_dir/cdist.XXXXXXXXXXXX")
|
|
|
|
|
2011-03-03 13:49:48 +00:00
|
|
|
################################################################################
|
2011-03-03 09:37:11 +00:00
|
|
|
# Local Base
|
2011-03-03 13:49:48 +00:00
|
|
|
#
|
2011-03-03 14:27:51 +00:00
|
|
|
: ${__cdist_local_base_dir:=$__cdist_tmp_dir}
|
|
|
|
|
|
|
|
: ${__cdist_conf_dir:="$(cd "$__cdist_abs_mydir/../conf" && pwd -P)"}
|
|
|
|
|
2011-02-23 18:01:29 +00:00
|
|
|
: ${__cdist_explorer_dir:=$__cdist_conf_dir/$__cdist_name_explorer}
|
2011-02-24 20:32:01 +00:00
|
|
|
: ${__cdist_manifest_dir:=$__cdist_conf_dir/$__cdist_name_manifest}
|
2011-02-05 18:41:47 +00:00
|
|
|
: ${__cdist_manifest_init:=$__cdist_manifest_dir/$__cdist_name_init}
|
2011-02-23 18:01:29 +00:00
|
|
|
: ${__cdist_type_dir:=$__cdist_conf_dir/$__cdist_name_type}
|
2011-02-02 13:01:21 +00:00
|
|
|
|
2011-03-03 13:49:48 +00:00
|
|
|
################################################################################
|
|
|
|
# Local output
|
|
|
|
#
|
2011-03-03 09:37:11 +00:00
|
|
|
: ${__cdist_out_dir:=$__cdist_local_base_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}
|
2011-02-22 19:40:54 +00:00
|
|
|
|
2011-03-03 13:49:48 +00:00
|
|
|
################################################################################
|
2011-02-23 15:19:41 +00:00
|
|
|
# Remote base
|
2011-03-03 13:49:48 +00:00
|
|
|
#
|
2011-02-04 13:38:17 +00:00
|
|
|
: ${__cdist_remote_base_dir:=/var/lib/cdist}
|
2011-03-03 14:27:51 +00:00
|
|
|
: ${__cdist_remote_bin_dir:=$__cdist_remote_base_dir/$__cdist_name_bin}
|
2011-02-23 15:19:41 +00:00
|
|
|
: ${__cdist_remote_conf_dir:=$__cdist_remote_base_dir/$__cdist_name_conf_dir}
|
2011-03-03 14:27:51 +00:00
|
|
|
|
2011-02-23 15:19:41 +00:00
|
|
|
: ${__cdist_remote_explorer_dir:=$__cdist_remote_conf_dir/$__cdist_name_explorer}
|
2011-02-24 15:33:08 +00:00
|
|
|
: ${__cdist_remote_type_dir:=$__cdist_remote_conf_dir/$__cdist_name_type}
|
2011-02-23 15:19:41 +00:00
|
|
|
|
2011-03-03 13:49:48 +00:00
|
|
|
################################################################################
|
|
|
|
# Remote output
|
|
|
|
#
|
2011-02-23 15:19:41 +00:00
|
|
|
: ${__cdist_remote_out_dir:=$__cdist_remote_base_dir/$__cdist_name_out_dir}
|
|
|
|
: ${__cdist_remote_out_explorer_dir:=$__cdist_remote_out_dir/$__cdist_name_explorer}
|
2011-02-24 20:24:21 +00:00
|
|
|
: ${__cdist_remote_out_object_base_dir:=$__cdist_remote_out_dir/$__cdist_name_object}
|
2011-02-04 13:38:17 +00:00
|
|
|
|
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-03-03 08:43:04 +00:00
|
|
|
__cdist_init_deploy()
|
|
|
|
{
|
2011-03-03 08:47:02 +00:00
|
|
|
echo "Creating clean directory structure ..."
|
2011-03-03 08:43:04 +00:00
|
|
|
|
|
|
|
# Ensure there is no old stuff, neither local nor remote
|
|
|
|
rm -rf "$__cdist_local_base_dir"
|
|
|
|
ssh "${__cdist_remote_user}@$1" "rm -rf ${__cdist_remote_base_dir}"
|
|
|
|
|
|
|
|
# Init base
|
|
|
|
mkdir -p "$__cdist_local_base_dir"
|
|
|
|
ssh "${__cdist_remote_user}@$1" "mkdir -p ${__cdist_remote_base_dir}"
|
|
|
|
|
|
|
|
# Link configuration source directory - consistent with remote
|
|
|
|
ln -sf "$__cdist_conf_dir" "$__cdist_local_base_dir/$__cdist_name_conf_dir"
|
|
|
|
}
|
|
|
|
|
2011-02-23 15:19:41 +00:00
|
|
|
# __cdist_cache_host()
|
|
|
|
# {
|
|
|
|
# echo "${__cdist_cache_hosts}/${__cdist_target_host}"
|
|
|
|
# }
|
2011-02-05 18:32:29 +00:00
|
|
|
|
2011-02-24 16:28:14 +00:00
|
|
|
__cdist_type_has_explorer()
|
|
|
|
{
|
2011-02-24 20:24:21 +00:00
|
|
|
# We only create output, if there's at least one explorer
|
|
|
|
# and can thus be used as a boolean ;-)
|
|
|
|
if [ -d "$(__cdist_type_explorer_dir "$1")" ]; then
|
|
|
|
ls -1 "$(__cdist_type_explorer_dir "$1")"
|
|
|
|
fi
|
2011-02-24 16:28:14 +00:00
|
|
|
}
|
|
|
|
|
2011-02-25 17:39:21 +00:00
|
|
|
__cdist_type_dir()
|
2011-02-07 16:50:25 +00:00
|
|
|
{
|
2011-02-25 17:39:21 +00:00
|
|
|
echo "${__cdist_type_dir}/$1"
|
2011-02-07 16:50:25 +00:00
|
|
|
}
|
|
|
|
|
2011-02-22 23:21:32 +00:00
|
|
|
__cdist_type_explorer_dir()
|
2011-02-22 23:21:11 +00:00
|
|
|
{
|
2011-02-24 23:14:26 +00:00
|
|
|
echo "${__cdist_type_dir}/$1/${__cdist_name_explorer}"
|
2011-02-22 23:21:11 +00:00
|
|
|
}
|
|
|
|
|
2011-02-24 15:33:08 +00:00
|
|
|
__cdist_remote_type_explorer_dir()
|
|
|
|
{
|
2011-02-24 23:14:26 +00:00
|
|
|
echo "${__cdist_remote_type_dir}/$1/${__cdist_name_explorer}"
|
2011-02-24 15:33:08 +00:00
|
|
|
}
|
|
|
|
|
2011-02-16 18:44:04 +00:00
|
|
|
__cdist_type_gencode()
|
|
|
|
{
|
2011-02-25 00:17:48 +00:00
|
|
|
echo "${__cdist_type_dir}/$1/${__cdist_name_gencode}"
|
2011-02-16 18:44:04 +00:00
|
|
|
}
|
|
|
|
|
2011-02-16 22:04:02 +00:00
|
|
|
__cdist_type_param_file()
|
|
|
|
{
|
2011-02-24 20:32:01 +00:00
|
|
|
# FIXME: local == posix?
|
2011-02-16 22:04:02 +00:00
|
|
|
local type="$1"; shift
|
|
|
|
local paramtype="$1"; shift
|
|
|
|
|
2011-02-24 23:14:26 +00:00
|
|
|
echo "${__cdist_type_dir}/${type}/${__cdist_name_parameter}/${paramtype}"
|
2011-02-16 22:04:02 +00:00
|
|
|
}
|
|
|
|
|
2011-02-22 23:17:55 +00:00
|
|
|
__cdist_type_from_object()
|
|
|
|
{
|
|
|
|
echo "${1%%/*}"
|
|
|
|
}
|
|
|
|
|
2011-02-23 08:50:30 +00:00
|
|
|
__cdist_object_id_from_object()
|
|
|
|
{
|
|
|
|
echo "${1#*/}"
|
|
|
|
}
|
|
|
|
|
2011-02-24 23:54:49 +00:00
|
|
|
__cdist_object_dir()
|
2011-02-16 18:44:04 +00:00
|
|
|
{
|
2011-02-24 23:54:49 +00:00
|
|
|
echo "${__cdist_object_base_dir}/$1"
|
2011-02-24 16:28:14 +00:00
|
|
|
}
|
2011-02-16 18:44:04 +00:00
|
|
|
|
2011-02-24 23:54:49 +00:00
|
|
|
__cdist_remote_object_dir()
|
2011-02-24 20:24:21 +00:00
|
|
|
{
|
2011-02-24 23:54:49 +00:00
|
|
|
echo "${__cdist_remote_out_object_base_dir}/$1"
|
2011-02-24 20:24:21 +00:00
|
|
|
}
|
|
|
|
|
2011-02-25 00:06:02 +00:00
|
|
|
__cdist_object_code()
|
|
|
|
{
|
|
|
|
echo "$(__cdist_object_dir "$1")/${__cdist_name_code}"
|
|
|
|
}
|
|
|
|
|
2011-02-24 23:54:49 +00:00
|
|
|
__cdist_object_parameter_dir()
|
2011-02-24 20:24:21 +00:00
|
|
|
{
|
2011-02-24 23:54:49 +00:00
|
|
|
echo "$(__cdist_object_dir "$1")/${__cdist_name_parameter}"
|
2011-02-24 20:24:21 +00:00
|
|
|
}
|
|
|
|
|
2011-02-24 23:14:26 +00:00
|
|
|
__cdist_remote_object_parameter_dir()
|
2011-02-24 16:28:14 +00:00
|
|
|
{
|
2011-02-24 23:54:49 +00:00
|
|
|
echo "$(__cdist_remote_object_dir "$1")/${__cdist_name_parameter}"
|
|
|
|
}
|
|
|
|
|
|
|
|
__cdist_object_type_explorer_dir()
|
|
|
|
{
|
|
|
|
echo "$(__cdist_object_dir "$1")/${__cdist_name_explorer}"
|
|
|
|
}
|
|
|
|
|
|
|
|
__cdist_remote_object_type_explorer_dir()
|
|
|
|
{
|
|
|
|
echo "$(__cdist_remote_object_dir "$1")/${__cdist_name_explorer}"
|
2011-02-16 18:44:04 +00:00
|
|
|
}
|
|
|
|
|
2011-02-22 12:04:41 +00:00
|
|
|
# Find objects, remove ./ and /MARKER
|
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" | \
|
2011-02-24 23:14:26 +00:00
|
|
|
sed -e 's;^./;;' -e "s;/${__cdist_name_object_source}\$;;"
|
2011-02-17 08:17:13 +00:00
|
|
|
)
|
2011-02-16 19:12:29 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-02-16 21:11:53 +00:00
|
|
|
__cdist_object_source()
|
|
|
|
{
|
|
|
|
local object_dir="$1"; shift
|
|
|
|
|
2011-02-24 23:14:26 +00:00
|
|
|
cat "${object_dir}/${__cdist_name_object_source}"
|
2011-02-16 21:11:53 +00:00
|
|
|
}
|
|
|
|
|
2011-02-22 10:31:37 +00:00
|
|
|
__cdist_exec_fail_on_error()
|
|
|
|
{
|
2011-02-22 10:39:23 +00:00
|
|
|
sh -e "$@"
|
|
|
|
[ "$?" -eq 0 ] || __cdist_exit_err "Error: $1 exited non-zero."
|
2011-02-22 10:31:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|