| 
									
										
										
										
											2010-09-19 14:13:13 +02:00
										 |  |  | #!/bin/sh | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2011-02-17 17:46:18 +01:00
										 |  |  | # 2010-2011 Nico Schottelius (nico-cdist at schottelius.org) | 
					
						
							| 
									
										
										
										
											2010-09-19 14:13:13 +02: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-04-19 22:43:18 +02:00
										 |  |  | __cdist_version="1.6.2" | 
					
						
							| 
									
										
										
										
											2011-03-11 19:25:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-11 19:09:36 +01:00
										 |  |  | # Fail if something bogus is going on | 
					
						
							| 
									
										
										
										
											2011-02-24 14:28:29 +01:00
										 |  |  | set -u | 
					
						
							| 
									
										
										
										
											2011-02-05 19:32:29 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-03 14:49:48 +01:00
										 |  |  | ################################################################################ | 
					
						
							|  |  |  | # cconf standard vars prefixed with cdist | 
					
						
							| 
									
										
										
										
											2011-03-04 02:08:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-03 14:49:48 +01: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" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ################################################################################ | 
					
						
							|  |  |  | # Names / Constants | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2011-02-25 01:48:18 +01:00
										 |  |  | # Most values can be overriden from outside, so you can | 
					
						
							| 
									
										
										
										
											2011-02-02 21:49:01 +01:00
										 |  |  | # customise paths as you like (for distributors, geeks and hackers) | 
					
						
							| 
									
										
										
										
											2011-03-03 14:49:48 +01:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2011-02-02 14:23:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-05 19:41:47 +01:00
										 |  |  | : ${__cdist_name_bin:=bin} | 
					
						
							| 
									
										
										
										
											2011-03-25 23:35:11 +01:00
										 |  |  | : ${__cdist_name_cache:=cache} | 
					
						
							| 
									
										
										
										
											2011-02-08 00:26:26 +01:00
										 |  |  | : ${__cdist_name_code:=code} | 
					
						
							| 
									
										
										
										
											2011-02-25 00:14:26 +01:00
										 |  |  | : ${__cdist_name_conf_dir:=conf} | 
					
						
							| 
									
										
										
										
											2011-03-21 16:18:04 +01:00
										 |  |  | : ${__cdist_name_dot_cdist:=.cdist} | 
					
						
							| 
									
										
										
										
											2011-02-24 21:32:01 +01:00
										 |  |  | : ${__cdist_name_explorer:=explorer} | 
					
						
							| 
									
										
										
										
											2011-02-14 11:28:14 +01:00
										 |  |  | : ${__cdist_name_gencode:=gencode} | 
					
						
							| 
									
										
										
										
											2011-03-19 22:19:44 +01:00
										 |  |  | : ${__cdist_name_gencode_local:=local} | 
					
						
							|  |  |  | : ${__cdist_name_gencode_remote:=remote} | 
					
						
							| 
									
										
										
										
											2011-03-03 10:37:11 +01:00
										 |  |  | : ${__cdist_name_global:=global} | 
					
						
							| 
									
										
										
										
											2011-02-24 21:32:01 +01:00
										 |  |  | : ${__cdist_name_host:=host} | 
					
						
							| 
									
										
										
										
											2011-02-05 19:41:47 +01:00
										 |  |  | : ${__cdist_name_init:=init} | 
					
						
							| 
									
										
										
										
											2011-02-24 14:47:52 +01:00
										 |  |  | : ${__cdist_name_manifest:=manifest} | 
					
						
							| 
									
										
										
										
											2011-02-24 15:34:17 +01:00
										 |  |  | : ${__cdist_name_object:=object} | 
					
						
							| 
									
										
										
										
											2011-03-23 11:45:50 +01:00
										 |  |  | : ${__cdist_name_object_finished:=done} | 
					
						
							| 
									
										
										
										
											2011-04-05 22:55:46 +02:00
										 |  |  | : ${__cdist_name_object_prepared:=prepared} | 
					
						
							| 
									
										
										
										
											2011-02-24 15:34:17 +01:00
										 |  |  | : ${__cdist_name_object_id:=object_id} | 
					
						
							| 
									
										
										
										
											2011-03-23 11:45:50 +01:00
										 |  |  | : ${__cdist_name_object_source:=source} | 
					
						
							| 
									
										
										
										
											2011-03-29 14:36:35 +02:00
										 |  |  | : ${__cdist_name_objects_created:=.objects_created} | 
					
						
							| 
									
										
										
										
											2011-02-25 00:14:26 +01:00
										 |  |  | : ${__cdist_name_out_dir:=out} | 
					
						
							| 
									
										
										
										
											2011-02-24 21:32:01 +01:00
										 |  |  | : ${__cdist_name_parameter:=parameter} | 
					
						
							|  |  |  | : ${__cdist_name_parameter_required:=required} | 
					
						
							|  |  |  | : ${__cdist_name_parameter_optional:=optional} | 
					
						
							| 
									
										
										
										
											2011-03-16 15:49:28 +01:00
										 |  |  | : ${__cdist_name_require:=require} | 
					
						
							| 
									
										
										
										
											2011-03-29 15:27:17 +02:00
										 |  |  | : ${__cdist_name_self:=self} | 
					
						
							| 
									
										
										
										
											2011-03-09 22:09:44 +01:00
										 |  |  | : ${__cdist_name_singleton:=singleton} | 
					
						
							| 
									
										
										
										
											2011-02-24 15:05:31 +01:00
										 |  |  | : ${__cdist_name_target_host:=target_host} | 
					
						
							| 
									
										
										
										
											2011-03-20 02:44:31 +01:00
										 |  |  | : ${__cdist_name_target_user:=target_user} | 
					
						
							| 
									
										
										
										
											2011-02-24 21:32:01 +01:00
										 |  |  | : ${__cdist_name_type:=type} | 
					
						
							| 
									
										
										
										
											2011-02-23 18:40:58 +01:00
										 |  |  | : ${__cdist_name_type_bin:=type_bin} | 
					
						
							| 
									
										
										
										
											2011-02-24 21:32:01 +01:00
										 |  |  | : ${__cdist_name_type_explorer:=type_explorer} | 
					
						
							| 
									
										
										
										
											2011-03-29 14:36:35 +02:00
										 |  |  | : ${__cdist_name_type_explorer_pushed:=.explorer_pushed} | 
					
						
							| 
									
										
										
										
											2011-02-24 21:32:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-10 17:19:25 +01:00
										 |  |  | # Used for IDs: Allow everything not starting with - and . | 
					
						
							| 
									
										
										
										
											2011-03-10 17:25:24 +01:00
										 |  |  | : ${__cdist_sane_regexp:=[^-\.].*} | 
					
						
							| 
									
										
										
										
											2011-02-17 09:17:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-03 14:49:48 +01:00
										 |  |  | # Default remote user | 
					
						
							|  |  |  | : ${__cdist_remote_user:=root} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ################################################################################ | 
					
						
							|  |  |  | # Exported variable names (usable for non core | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2011-02-24 14:24:47 +01:00
										 |  |  | : ${__cdist_name_var_explorer:=__$__cdist_name_explorer} | 
					
						
							| 
									
										
										
										
											2011-02-24 21:32:01 +01:00
										 |  |  | : ${__cdist_name_var_type_explorer:=__$__cdist_name_type_explorer} | 
					
						
							| 
									
										
										
										
											2011-03-03 10:37:11 +01:00
										 |  |  | : ${__cdist_name_var_global:=__$__cdist_name_global} | 
					
						
							| 
									
										
										
										
											2011-02-24 21:32:01 +01:00
										 |  |  | : ${__cdist_name_var_manifest:=__$__cdist_name_manifest} | 
					
						
							| 
									
										
										
										
											2011-02-24 15:05:31 +01:00
										 |  |  | : ${__cdist_name_var_target_host:=__$__cdist_name_target_host} | 
					
						
							| 
									
										
										
										
											2011-03-20 02:44:31 +01:00
										 |  |  | : ${__cdist_name_var_target_user:=__$__cdist_name_target_user} | 
					
						
							| 
									
										
										
										
											2011-02-24 15:34:17 +01:00
										 |  |  | : ${__cdist_name_var_object:=__$__cdist_name_object} | 
					
						
							|  |  |  | : ${__cdist_name_var_object_id:=__$__cdist_name_object_id} | 
					
						
							| 
									
										
										
										
											2011-03-29 15:27:17 +02:00
										 |  |  | : ${__cdist_name_var_self:=__$__cdist_name_self} | 
					
						
							| 
									
										
										
										
											2011-02-25 18:42:38 +01:00
										 |  |  | : ${__cdist_name_var_type:=__$__cdist_name_type} | 
					
						
							| 
									
										
										
										
											2011-02-17 09:17:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-16 20:12:29 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-03 15:27:51 +01:00
										 |  |  | ################################################################################ | 
					
						
							|  |  |  | # Tempfiles | 
					
						
							|  |  |  | #  | 
					
						
							| 
									
										
										
										
											2011-04-08 10:51:27 +02:00
										 |  |  | : ${__cdist_tmp_base_dir=/tmp} | 
					
						
							|  |  |  | __cdist_tmp_dir=$(mktemp -d "$__cdist_tmp_base_dir/cdist.XXXXXXXXXXXX") | 
					
						
							| 
									
										
										
										
											2011-03-03 15:27:51 +01:00
										 |  |  | __cdist_tmp_file=$(mktemp "$__cdist_tmp_dir/cdist.XXXXXXXXXXXX") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-03 14:49:48 +01:00
										 |  |  | ################################################################################ | 
					
						
							| 
									
										
										
										
											2011-03-03 10:37:11 +01:00
										 |  |  | # Local Base | 
					
						
							| 
									
										
										
										
											2011-03-03 14:49:48 +01:00
										 |  |  | #  | 
					
						
							| 
									
										
										
										
											2011-03-03 15:27:51 +01:00
										 |  |  | : ${__cdist_local_base_dir:=$__cdist_tmp_dir} | 
					
						
							| 
									
										
										
										
											2011-03-31 15:40:08 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Cache may *NOT* be below __cdist_local_base_dir! | 
					
						
							| 
									
										
										
										
											2011-03-25 23:35:11 +01:00
										 |  |  | : ${__cdist_local_base_cache_dir:=$__cdist_abs_mydir/../$__cdist_name_cache} | 
					
						
							| 
									
										
										
										
											2011-03-03 15:27:51 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | : ${__cdist_conf_dir:="$(cd "$__cdist_abs_mydir/../conf" && pwd -P)"} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-23 19:01:29 +01:00
										 |  |  | : ${__cdist_explorer_dir:=$__cdist_conf_dir/$__cdist_name_explorer} | 
					
						
							| 
									
										
										
										
											2011-02-24 21:32:01 +01:00
										 |  |  | : ${__cdist_manifest_dir:=$__cdist_conf_dir/$__cdist_name_manifest} | 
					
						
							| 
									
										
										
										
											2011-02-05 19:41:47 +01:00
										 |  |  | : ${__cdist_manifest_init:=$__cdist_manifest_dir/$__cdist_name_init} | 
					
						
							| 
									
										
										
										
											2011-02-23 19:01:29 +01:00
										 |  |  | : ${__cdist_type_dir:=$__cdist_conf_dir/$__cdist_name_type} | 
					
						
							| 
									
										
										
										
											2011-02-02 14:01:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-03 14:49:48 +01:00
										 |  |  | ################################################################################ | 
					
						
							|  |  |  | # Local output | 
					
						
							|  |  |  | #  | 
					
						
							| 
									
										
										
										
											2011-03-03 10:37:11 +01: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} | 
					
						
							| 
									
										
										
										
											2011-03-29 14:36:35 +02:00
										 |  |  | : ${__cdist_out_type_dir:=$__cdist_out_dir/$__cdist_name_type} | 
					
						
							| 
									
										
										
										
											2011-03-03 10:37:11 +01:00
										 |  |  | : ${__cdist_out_type_bin_dir:=$__cdist_out_dir/$__cdist_name_type_bin} | 
					
						
							| 
									
										
										
										
											2011-02-22 20:40:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-29 16:27:57 +02:00
										 |  |  | : ${__cdist_objects_created:=$__cdist_out_object_dir/$__cdist_name_objects_created} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-03 14:49:48 +01:00
										 |  |  | ################################################################################ | 
					
						
							| 
									
										
										
										
											2011-02-23 16:19:41 +01:00
										 |  |  | # Remote base | 
					
						
							| 
									
										
										
										
											2011-03-03 14:49:48 +01:00
										 |  |  | #  | 
					
						
							| 
									
										
										
										
											2011-02-04 14:38:17 +01:00
										 |  |  | : ${__cdist_remote_base_dir:=/var/lib/cdist} | 
					
						
							| 
									
										
										
										
											2011-03-03 15:27:51 +01:00
										 |  |  | : ${__cdist_remote_bin_dir:=$__cdist_remote_base_dir/$__cdist_name_bin} | 
					
						
							| 
									
										
										
										
											2011-02-23 16:19:41 +01:00
										 |  |  | : ${__cdist_remote_conf_dir:=$__cdist_remote_base_dir/$__cdist_name_conf_dir} | 
					
						
							| 
									
										
										
										
											2011-03-03 15:27:51 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-23 16:19:41 +01:00
										 |  |  | : ${__cdist_remote_explorer_dir:=$__cdist_remote_conf_dir/$__cdist_name_explorer} | 
					
						
							| 
									
										
										
										
											2011-02-24 16:33:08 +01:00
										 |  |  | : ${__cdist_remote_type_dir:=$__cdist_remote_conf_dir/$__cdist_name_type} | 
					
						
							| 
									
										
										
										
											2011-02-23 16:19:41 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-03 14:49:48 +01:00
										 |  |  | ################################################################################ | 
					
						
							|  |  |  | # Remote output | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2011-02-23 16:19:41 +01: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-03-26 01:43:55 +01:00
										 |  |  | : ${__cdist_remote_out_object_dir:=$__cdist_remote_out_dir/$__cdist_name_object} | 
					
						
							| 
									
										
										
										
											2011-02-04 14:38:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-29 14:36:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-02 14:01:21 +01:00
										 |  |  | ################################################################################ | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  | # Internal functions | 
					
						
							| 
									
										
										
										
											2011-02-02 14:01:21 +01:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2011-04-06 20:00:36 +02:00
										 |  |  | __cdist_echo() | 
					
						
							| 
									
										
										
										
											2010-09-25 12:36:30 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-04-06 20:00:36 +02:00
										 |  |  |    __cdist_echo_type="$1"; shift | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-06 20:31:19 +02:00
										 |  |  |    set +u | 
					
						
							| 
									
										
										
										
											2011-04-06 20:11:39 +02:00
										 |  |  |    if [ "$__cdist_object_self" ]; then | 
					
						
							| 
									
										
										
										
											2011-04-06 20:35:27 +02:00
										 |  |  |       __cdist_echo_prefix="${__cdist_object_self}:" | 
					
						
							| 
									
										
										
										
											2011-04-06 20:34:46 +02:00
										 |  |  |    else | 
					
						
							| 
									
										
										
										
											2011-04-06 21:50:49 +02:00
										 |  |  |       __cdist_echo_prefix="core: " | 
					
						
							| 
									
										
										
										
											2011-04-06 20:11:39 +02:00
										 |  |  |    fi | 
					
						
							| 
									
										
										
										
											2011-04-06 20:31:19 +02:00
										 |  |  |    set -u | 
					
						
							| 
									
										
										
										
											2011-04-06 20:11:39 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-06 20:00:36 +02:00
										 |  |  |    case "$__cdist_echo_type" in | 
					
						
							|  |  |  |       debug) | 
					
						
							|  |  |  |          if [ "$__cdist_debug" ]; then | 
					
						
							| 
									
										
										
										
											2011-04-06 20:11:39 +02:00
										 |  |  |             echo $__cdist_echo_prefix "Debug: $@" | 
					
						
							| 
									
										
										
										
											2011-04-06 20:00:36 +02:00
										 |  |  |          fi | 
					
						
							|  |  |  |       ;; | 
					
						
							|  |  |  |       info) | 
					
						
							| 
									
										
										
										
											2011-04-06 20:11:39 +02:00
										 |  |  |          echo $__cdist_echo_prefix "$@" | 
					
						
							| 
									
										
										
										
											2011-04-06 20:00:36 +02:00
										 |  |  |       ;; | 
					
						
							| 
									
										
										
										
											2011-04-06 21:18:15 +02:00
										 |  |  |       warn) | 
					
						
							| 
									
										
										
										
											2011-04-06 20:11:39 +02:00
										 |  |  |          echo $__cdist_echo_prefix "Warning: $@" | 
					
						
							| 
									
										
										
										
											2011-04-06 20:04:34 +02:00
										 |  |  |       ;; | 
					
						
							| 
									
										
										
										
											2011-04-06 20:00:36 +02:00
										 |  |  |       error) | 
					
						
							| 
									
										
										
										
											2011-04-06 20:11:39 +02:00
										 |  |  |          echo $__cdist_echo_prefix "Error: $@" >&2 | 
					
						
							| 
									
										
										
										
											2011-04-06 20:00:36 +02:00
										 |  |  |       ;; | 
					
						
							| 
									
										
										
										
											2011-04-06 20:52:14 +02:00
										 |  |  |       *) | 
					
						
							| 
									
										
										
										
											2011-04-06 21:19:47 +02:00
										 |  |  |          echo "CORE BUG, who created the broken commit in $0?" >&2 | 
					
						
							| 
									
										
										
										
											2011-04-06 20:52:14 +02:00
										 |  |  |          exit 23 | 
					
						
							|  |  |  |       ;; | 
					
						
							| 
									
										
										
										
											2011-04-06 20:00:36 +02:00
										 |  |  |    esac | 
					
						
							| 
									
										
										
										
											2010-09-25 12:36:30 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2010-09-19 14:30:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  | __cdist_exec_fail_on_error() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-04-06 20:18:31 +02:00
										 |  |  |    set +e | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  |    sh -e "$@" | 
					
						
							| 
									
										
										
										
											2011-04-06 20:00:36 +02:00
										 |  |  |    if [ "$?" -ne 0 ]; then | 
					
						
							| 
									
										
										
										
											2011-04-06 20:55:53 +02:00
										 |  |  |       __cdist_echo error  "$1 exited non-zero" | 
					
						
							| 
									
										
										
										
											2011-04-06 21:18:15 +02:00
										 |  |  |       __cdist_echo warn "Faulty code:" | 
					
						
							| 
									
										
										
										
											2011-04-06 20:05:58 +02:00
										 |  |  |       cat "$1" | 
					
						
							|  |  |  |       __cdist_exit_err "Aborting due to non-zero exit code." | 
					
						
							| 
									
										
										
										
											2011-04-06 20:00:36 +02:00
										 |  |  |    fi | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-02 14:55:28 +01:00
										 |  |  | __cdist_exit_err() | 
					
						
							| 
									
										
										
										
											2010-09-29 18:55:18 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-04-06 20:00:36 +02:00
										 |  |  |    __cdist_echo error "$@" | 
					
						
							| 
									
										
										
										
											2010-09-29 18:55:18 +02:00
										 |  |  |    exit 1 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-02 14:55:28 +01:00
										 |  |  | __cdist_usage() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |    __cdist_exit_err "$__cdist_myname: $@" | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-03 09:43:04 +01:00
										 |  |  | __cdist_init_deploy() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-04-06 21:51:43 +02:00
										 |  |  |    __cdist_echo info "Creating clean directory structure " | 
					
						
							| 
									
										
										
										
											2011-03-03 09:43:04 +01: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-03-31 15:40:08 +02:00
										 |  |  | ################################################################################ | 
					
						
							|  |  |  | # Cache | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | __cdist_cache_dir() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |    cd "${__cdist_local_base_cache_dir}" && pwd -P | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | __cdist_host_cache_dir() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |    echo "$(__cdist_cache_dir)/$1"  | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  | ################################################################################ | 
					
						
							|  |  |  | # Object | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2011-02-24 17:28:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  | __cdist_object_code() | 
					
						
							| 
									
										
										
										
											2011-02-07 17:50:25 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-04-28 14:45:14 +02:00
										 |  |  |    echo "$(__cdist_object_dir "$1")/${__cdist_name_code}-$2" | 
					
						
							| 
									
										
										
										
											2011-02-07 17:50:25 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-05 22:55:46 +02:00
										 |  |  | __cdist_object_prepared() | 
					
						
							| 
									
										
										
										
											2011-03-30 22:46:49 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-04-05 22:55:46 +02:00
										 |  |  |    echo "$(__cdist_object_dir "$1")/${__cdist_name_object_prepared}" | 
					
						
							| 
									
										
										
										
											2011-03-30 22:46:49 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-28 14:55:58 +02:00
										 |  |  | __cdist_object_finished() | 
					
						
							| 
									
										
										
										
											2011-02-23 00:21:11 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-28 14:55:58 +02:00
										 |  |  |    echo "$(__cdist_object_dir "$1")/${__cdist_name_object_finished}" | 
					
						
							| 
									
										
										
										
											2011-02-23 00:21:11 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-23 11:19:05 +01:00
										 |  |  | __cdist_object_dir() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-23 13:38:14 +01:00
										 |  |  |    echo "$(__cdist_object_base_dir "$1")/${__cdist_name_dot_cdist}" | 
					
						
							| 
									
										
										
										
											2011-03-23 13:33:26 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-23 13:38:14 +01:00
										 |  |  | __cdist_object_base_dir() | 
					
						
							| 
									
										
										
										
											2011-03-23 13:33:26 +01:00
										 |  |  | { | 
					
						
							|  |  |  |    echo "${__cdist_out_object_dir}/$1" | 
					
						
							| 
									
										
										
										
											2011-03-23 11:19:05 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | __cdist_object_id_from_object() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |    echo "${1#*/}" | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  | # Find objects, remove ./ and /MARKER | 
					
						
							|  |  |  | __cdist_object_list() | 
					
						
							| 
									
										
										
										
											2011-02-24 16:33:08 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  |    local basedir="$1"; shift | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    # Use subshell to prevent changing cwd in program | 
					
						
							|  |  |  |    ( | 
					
						
							|  |  |  |       cd "${basedir}" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-23 16:39:06 +01:00
										 |  |  |       find . -name "$__cdist_name_dot_cdist" |    \ | 
					
						
							|  |  |  |          sed -e 's;^./;;' -e "s;/${__cdist_name_dot_cdist}\$;;" | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  |    ) | 
					
						
							| 
									
										
										
										
											2011-02-16 19:44:04 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  | __cdist_object_parameter_dir() | 
					
						
							| 
									
										
										
										
											2011-02-16 23:04:02 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  |    echo "$(__cdist_object_dir "$1")/${__cdist_name_parameter}" | 
					
						
							| 
									
										
										
										
											2011-03-07 23:55:46 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-02-16 23:04:02 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  | __cdist_object_require() | 
					
						
							| 
									
										
										
										
											2011-03-10 17:41:08 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  |    echo "$(__cdist_object_dir "$1")/${__cdist_name_require}" | 
					
						
							| 
									
										
										
										
											2011-03-10 17:41:08 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-23 11:30:22 +01:00
										 |  |  | __cdist_object_source_name() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |    echo "$1/${__cdist_name_object_source}" | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-23 11:19:05 +01:00
										 |  |  | __cdist_object_source() | 
					
						
							| 
									
										
										
										
											2011-02-23 09:50:30 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-23 11:30:22 +01:00
										 |  |  |    cat "$(__cdist_object_source_name "$1")" | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | __cdist_object_source_add() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |    echo "$__cdist_manifest" >> "$(__cdist_object_source_name "$1")" | 
					
						
							| 
									
										
										
										
											2011-02-23 09:50:30 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-23 11:19:05 +01:00
										 |  |  | __cdist_object_type_explorer_dir() | 
					
						
							| 
									
										
										
										
											2011-02-16 19:44:04 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-23 11:19:05 +01:00
										 |  |  |    echo "$(__cdist_object_dir "$1")/${__cdist_name_explorer}" | 
					
						
							| 
									
										
										
										
											2011-02-24 17:28:14 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-02-16 19:44:04 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  | ################################################################################ | 
					
						
							|  |  |  | # Remote | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-26 01:43:55 +01:00
										 |  |  | __cdist_remote_object_base_dir() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |    echo "${__cdist_remote_out_object_dir}/$1" | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-25 00:54:49 +01:00
										 |  |  | __cdist_remote_object_dir() | 
					
						
							| 
									
										
										
										
											2011-02-24 21:24:21 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-26 01:43:55 +01:00
										 |  |  |    echo "$(__cdist_remote_object_base_dir "$1")/${__cdist_name_dot_cdist}" | 
					
						
							| 
									
										
										
										
											2011-02-24 21:24:21 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-23 11:19:05 +01:00
										 |  |  | __cdist_remote_object_parameter_dir() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |    echo "$(__cdist_remote_object_dir "$1")/${__cdist_name_parameter}" | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  | __cdist_remote_object_type_explorer_dir() | 
					
						
							| 
									
										
										
										
											2011-02-25 01:06:02 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  |    echo "$(__cdist_remote_object_dir "$1")/${__cdist_name_explorer}" | 
					
						
							| 
									
										
										
										
											2011-02-25 01:06:02 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | __cdist_remote_type_explorer_dir() | 
					
						
							| 
									
										
										
										
											2011-03-18 01:31:30 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  |    echo "${__cdist_remote_type_dir}/$1/${__cdist_name_explorer}" | 
					
						
							| 
									
										
										
										
											2011-03-18 01:31:30 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | ################################################################################ | 
					
						
							|  |  |  | # Temp clenup | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | __cdist_tmp_removal() | 
					
						
							| 
									
										
										
										
											2011-02-24 21:24:21 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  |    rm -rf "${__cdist_tmp_dir}" | 
					
						
							| 
									
										
										
										
											2011-02-24 21:24:21 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  | trap __cdist_tmp_removal EXIT | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ################################################################################ | 
					
						
							|  |  |  | # Type | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | __cdist_type_dir() | 
					
						
							| 
									
										
										
										
											2011-02-24 17:28:14 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  |    echo "${__cdist_type_dir}/$1" | 
					
						
							| 
									
										
										
										
											2011-02-25 00:54:49 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  | __cdist_type_explorer_dir() | 
					
						
							| 
									
										
										
										
											2011-03-16 15:49:28 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  |    echo "${__cdist_type_dir}/$1/${__cdist_name_explorer}" | 
					
						
							| 
									
										
										
										
											2011-03-16 15:49:28 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  | __cdist_type_from_object() | 
					
						
							| 
									
										
										
										
											2011-02-25 00:54:49 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  |    echo "${1%%/*}" | 
					
						
							| 
									
										
										
										
											2011-02-25 00:54:49 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  | __cdist_type_has_explorer() | 
					
						
							| 
									
										
										
										
											2011-02-25 00:54:49 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01: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-16 19:44:04 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-29 14:36:35 +02:00
										 |  |  | __cdist_type_explorer_pushed() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |    [ -f "${__cdist_out_type_dir}/${__cdist_name_type_explorer_pushed}" ] \ | 
					
						
							|  |  |  |       && grep -q "$1" "${__cdist_out_type_dir}/${__cdist_name_type_explorer_pushed}" | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | __cdist_type_explorer_pushed_add() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |    [ -d "$__cdist_out_type_dir" ] || mkdir "$__cdist_out_type_dir" | 
					
						
							|  |  |  |    echo "$1" >> "${__cdist_out_type_dir}/${__cdist_name_type_explorer_pushed}" | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  | __cdist_type_gencode() | 
					
						
							| 
									
										
										
										
											2011-02-16 20:12:29 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-04-28 14:46:35 +02:00
										 |  |  |    echo "${__cdist_type_dir}/$1/${__cdist_name_gencode}-$2" | 
					
						
							| 
									
										
										
										
											2011-02-16 20:12:29 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-23 16:33:16 +01:00
										 |  |  | __cdist_type_manifest() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |    echo "${__cdist_type_dir}/$1/${__cdist_name_manifest}" | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  | __cdist_type_parameter_dir() | 
					
						
							| 
									
										
										
										
											2011-02-16 22:11:53 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  |    echo "$(__cdist_type_dir "$1")/${__cdist_name_parameter}" | 
					
						
							| 
									
										
										
										
											2011-02-16 22:11:53 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  | __cdist_type_parameter_optional() | 
					
						
							| 
									
										
										
										
											2011-02-22 11:31:37 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  |    echo "$(__cdist_type_parameter_dir "$1")/$__cdist_name_parameter_optional" | 
					
						
							| 
									
										
										
										
											2011-02-22 11:31:37 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  | __cdist_type_parameter_required() | 
					
						
							| 
									
										
										
										
											2011-02-05 19:32:29 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  |    echo "$(__cdist_type_parameter_dir "$1")/$__cdist_name_parameter_required" | 
					
						
							| 
									
										
										
										
											2011-02-05 19:32:29 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-23 11:12:39 +01:00
										 |  |  | __cdist_type_singleton() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |    echo "${__cdist_type_dir}/$1/${__cdist_name_singleton}" | 
					
						
							|  |  |  | } |