2011-02-14 10:28:14 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Generate code from one object (object must be relative path!)
|
2011-02-17 15:07:07 +00:00
|
|
|
# WARNING: OUTPUT ON STDOUT, ERRORS NEED TO BE ON STDERR!
|
2011-02-14 10:28:14 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
. cdist-config
|
2011-04-28 12:45:14 +00:00
|
|
|
[ $# -eq 3 ] || __cdist_usage "<target host>" "<object>" "<type>"
|
2011-02-17 15:13:35 +00:00
|
|
|
set -eu
|
2011-02-14 10:28:14 +00:00
|
|
|
|
2011-02-25 00:17:32 +00:00
|
|
|
__cdist_target_host="$1"; shift
|
2011-04-06 19:41:40 +00:00
|
|
|
__cdist_object_self="$1"; shift
|
2011-03-19 21:15:54 +00:00
|
|
|
__cdist_gencode_type="$1"; shift
|
2011-02-14 10:28:14 +00:00
|
|
|
|
2011-04-06 19:41:40 +00:00
|
|
|
__cdist_object_dir="$(__cdist_object_dir "$__cdist_object_self")"
|
|
|
|
__cdist_type="$(__cdist_type_from_object "$__cdist_object_self")"
|
|
|
|
__cdist_object_id="$(__cdist_object_id_from_object "$__cdist_object_self")"
|
2011-04-28 12:46:35 +00:00
|
|
|
__cdist_code_output="$(__cdist_object_code "$__cdist_object_self" "$__cdist_gencode_type")"
|
2011-04-28 12:59:57 +00:00
|
|
|
__cdist_type_gencode="$(__cdist_type_gencode "$__cdist_type" "$__cdist_gencode_type")"
|
2011-02-14 10:28:14 +00:00
|
|
|
|
2011-02-25 00:17:32 +00:00
|
|
|
# export variables for gencode
|
|
|
|
export __object_id="$__cdist_object_id"
|
|
|
|
export __object="$__cdist_object_dir"
|
2011-03-03 09:37:11 +00:00
|
|
|
export __global="$__cdist_out_dir"
|
2011-02-25 00:17:32 +00:00
|
|
|
|
2011-04-28 12:59:57 +00:00
|
|
|
# FIXME Needed?
|
2011-02-25 00:17:32 +00:00
|
|
|
cd "$__cdist_local_base_dir"
|
2011-02-14 10:28:14 +00:00
|
|
|
|
2011-04-28 12:59:57 +00:00
|
|
|
if [ -x "$__cdist_type_gencode" ]; then
|
2011-04-28 12:37:33 +00:00
|
|
|
__cdist_exec_fail_on_error "$gencode" > "$__cdist_tmp_file"
|
2011-02-22 21:40:34 +00:00
|
|
|
else
|
2011-04-28 12:59:57 +00:00
|
|
|
if [ -f "$__cdist_type_gencode" ]; then
|
|
|
|
__cdist_exit_err "$__cdist_type_gencode exists, but is not executable"
|
2011-02-22 21:40:34 +00:00
|
|
|
fi
|
|
|
|
|
2011-04-28 12:59:57 +00:00
|
|
|
# Ensure it's empty, if there is no gencode
|
|
|
|
: > "$__cdist_tmp_file"
|
2011-02-22 21:40:34 +00:00
|
|
|
fi
|
2011-04-28 12:37:33 +00:00
|
|
|
|
2011-04-28 12:59:57 +00:00
|
|
|
# Only create code, if gencode created output
|
|
|
|
if [ "$(wc -l < "$__cdist_tmp_file")" -gt 0 ]; then
|
|
|
|
cat - "$__cdist_tmp_file" << eof > "$__cdist_code_output"
|
|
|
|
#
|
|
|
|
# The following code was generated by $__cdist_type_gencode
|
|
|
|
#
|
2011-04-28 12:37:33 +00:00
|
|
|
|
2011-04-28 12:59:57 +00:00
|
|
|
eof
|
|
|
|
chmod u+x "${__cdist_code_output}"
|
|
|
|
|
|
|
|
fi
|