| 
									
										
										
										
											2010-12-01 19:52:34 +01:00
										 |  |  | #!/bin/sh | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2011-02-02 15:02:26 +01:00
										 |  |  | # 2010-2011 Nico Schottelius (nico-cdist at schottelius.org) | 
					
						
							| 
									
										
										
										
											2010-12-01 19:52:34 +01: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/>. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | #  | 
					
						
							|  |  |  | # Wrapper script that generates cconfig from arguments | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2011-01-14 12:46:51 +01:00
										 |  |  | # This script will be called everytime the manifest decides to create | 
					
						
							|  |  |  | # a new type | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2010-12-01 19:52:34 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | . cdist-config | 
					
						
							| 
									
										
										
										
											2011-02-05 19:10:48 +01:00
										 |  |  | set -eu | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-23 10:47:13 +01:00
										 |  |  | ################################################################################ | 
					
						
							|  |  |  | # Prepare object and type | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-23 09:20:34 +01:00
										 |  |  | __cdist_type="$__cdist_myname" | 
					
						
							| 
									
										
										
										
											2010-12-01 20:33:25 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-10 13:21:21 +01:00
										 |  |  | # Find out whether type is a singleton or regular type | 
					
						
							| 
									
										
										
										
											2011-03-09 22:09:44 +01:00
										 |  |  | if [ -f "$(__cdist_type_singleton "$__cdist_type")" ]; then | 
					
						
							| 
									
										
										
										
											2011-03-23 10:47:13 +01:00
										 |  |  |    __cdist_object_id="$__cdist_name_singleton" | 
					
						
							| 
									
										
										
										
											2011-03-09 22:09:44 +01:00
										 |  |  | else | 
					
						
							|  |  |  |    [ $# -ge 1 ] || __cdist_usage "<id> <options>" | 
					
						
							|  |  |  |    __cdist_object_id="$1"; shift | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-23 10:47:13 +01:00
										 |  |  | # Verify object id | 
					
						
							|  |  |  | __cdist_object_id_sane=$(echo "$__cdist_object_id" | grep "^${__cdist_sane_regexp}\$") | 
					
						
							|  |  |  | if [ -z "$__cdist_object_id_sane" ]; then | 
					
						
							| 
									
										
										
										
											2011-02-07 23:59:21 +01:00
										 |  |  |    __cdist_usage "Insane object id, ${__cdist_object_id}." | 
					
						
							| 
									
										
										
										
											2011-03-23 10:47:13 +01:00
										 |  |  | fi | 
					
						
							| 
									
										
										
										
											2010-12-01 20:33:25 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-23 10:47:13 +01:00
										 |  |  | # Prevent double slash if id begins with / | 
					
						
							| 
									
										
										
										
											2011-03-22 08:57:19 +01:00
										 |  |  | if [ "$(echo $__cdist_object_id | grep "^/")" ]; then | 
					
						
							| 
									
										
										
										
											2011-03-23 10:47:13 +01:00
										 |  |  |    __cdist_object_self="${__cdist_type}${__cdist_object_id}" | 
					
						
							| 
									
										
										
										
											2011-03-22 08:57:19 +01:00
										 |  |  | else | 
					
						
							| 
									
										
										
										
											2011-03-23 10:47:13 +01:00
										 |  |  |    __cdist_object_self="${__cdist_type}/${__cdist_object_id}" | 
					
						
							| 
									
										
										
										
											2011-03-22 08:57:19 +01:00
										 |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-23 10:47:13 +01:00
										 |  |  | ################################################################################ | 
					
						
							|  |  |  | # Verify object | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-16 12:57:13 +01:00
										 |  |  | __cdist_ddir="$(__cdist_object_dir "$__cdist_object")" | 
					
						
							|  |  |  | __cdist_parameter_dir="$(__cdist_object_parameter_dir "$__cdist_object")" | 
					
						
							| 
									
										
										
										
											2010-12-01 20:53:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-17 16:17:41 +01:00
										 |  |  | # Append id for error messages | 
					
						
							|  |  |  | __cdist_myname="$__cdist_myname ($__cdist_object_id)" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-23 10:39:45 +01:00
										 |  |  | # if [ -e "${__cdist_ddir}" ]; then | 
					
						
							|  |  |  | #    source="$(__cdist_object_source "${__cdist_ddir}")" | 
					
						
							|  |  |  | #    __cdist_exit_err "${__cdist_object} already exists (source: $source)" | 
					
						
							|  |  |  | # fi | 
					
						
							| 
									
										
										
										
											2010-12-01 20:48:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-02 15:02:26 +01:00
										 |  |  | mkdir -p "${__cdist_ddir}" | 
					
						
							| 
									
										
										
										
											2011-02-24 21:37:55 +01:00
										 |  |  | mkdir -p "${__cdist_parameter_dir}" | 
					
						
							| 
									
										
										
										
											2010-12-01 20:48:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-05 19:20:59 +01:00
										 |  |  | # Record (correct ;-) source | 
					
						
							| 
									
										
										
										
											2011-02-16 22:11:53 +01:00
										 |  |  | echo "${__cdist_manifest}" > "${__cdist_ddir}/${__cdist_name_object_source}" | 
					
						
							| 
									
										
										
										
											2011-02-05 19:20:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-23 10:21:43 +01:00
										 |  |  | # Record parameters to tmpdir | 
					
						
							| 
									
										
										
										
											2011-02-24 21:37:55 +01:00
										 |  |  | tempparameter="${__cdist_tmp_dir}/${__cdist_name_parameter}" | 
					
						
							|  |  |  | mkdir -p "$tempparameter" | 
					
						
							| 
									
										
										
										
											2011-02-16 23:04:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-01 20:48:15 +01:00
										 |  |  | while [ $# -gt 0 ]; do | 
					
						
							|  |  |  |    opt="$1"; shift | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-16 23:04:33 +01:00
										 |  |  |    echo "$opt" | grep -q "^--${__cdist_sane_regexp}\$" || \ | 
					
						
							|  |  |  |       __cdist_usage "Provide sane options" | 
					
						
							| 
									
										
										
										
											2010-12-01 20:48:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-01 20:53:26 +01:00
										 |  |  |    opt_file="$(echo $opt | sed 's/^--//')" | 
					
						
							| 
									
										
										
										
											2010-12-01 20:48:15 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |    [ $# -ge 1 ] || __cdist_usage "Missing value for $opt" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    value="$1"; shift | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-24 21:37:55 +01:00
										 |  |  |    echo "${value}" > "${tempparameter}/${opt_file}" | 
					
						
							| 
									
										
										
										
											2010-12-01 20:48:15 +01:00
										 |  |  | done | 
					
						
							| 
									
										
										
										
											2011-02-16 23:04:33 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Ensure required parameters are given | 
					
						
							| 
									
										
										
										
											2011-03-10 17:41:08 +01:00
										 |  |  | if [ -f "$(__cdist_type_parameter_required "$__cdist_type")" ]; then | 
					
						
							|  |  |  |    while read required; do | 
					
						
							|  |  |  |       if [ ! -f "${tempparameter}/${required}" ]; then | 
					
						
							|  |  |  |          __cdist_usage "Missing required parameter $required" | 
					
						
							|  |  |  |       fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       mv "${tempparameter}/${required}" "${__cdist_parameter_dir}" | 
					
						
							|  |  |  |    done < "$(__cdist_type_parameter_required "$__cdist_type")" | 
					
						
							|  |  |  | fi | 
					
						
							| 
									
										
										
										
											2011-02-16 23:04:33 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Allow optional parameters | 
					
						
							| 
									
										
										
										
											2011-03-10 17:41:08 +01:00
										 |  |  | if [ -f "$(__cdist_type_parameter_optional "$__cdist_type")" ]; then | 
					
						
							|  |  |  |    while read optional; do | 
					
						
							|  |  |  |       if [ -f "${tempparameter}/${optional}" ]; then | 
					
						
							|  |  |  |          mv "${tempparameter}/${optional}" "${__cdist_parameter_dir}" | 
					
						
							|  |  |  |       fi | 
					
						
							|  |  |  |    done < "$(__cdist_type_parameter_optional "$__cdist_type")" | 
					
						
							|  |  |  | fi | 
					
						
							| 
									
										
										
										
											2011-02-16 23:04:33 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Error out on other paramaters | 
					
						
							| 
									
										
										
										
											2011-02-24 21:37:55 +01:00
										 |  |  | cd "${tempparameter}" | 
					
						
							| 
									
										
										
										
											2011-02-16 23:04:33 +01:00
										 |  |  | other="$(ls)" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if [ "$other" ]; then | 
					
						
							|  |  |  |    __cdist_usage "Unsupported parameter: $other" | 
					
						
							|  |  |  | fi | 
					
						
							| 
									
										
										
										
											2011-03-16 15:49:44 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Record requirements | 
					
						
							| 
									
										
										
										
											2011-03-18 00:01:14 +01:00
										 |  |  | # it's fine, if it's not set | 
					
						
							|  |  |  | set +u | 
					
						
							| 
									
										
										
										
											2011-03-16 15:49:44 +01:00
										 |  |  | for requirement in $require; do | 
					
						
							|  |  |  |    echo $requirement >> "$(__cdist_object_require "$__cdist_object")" | 
					
						
							| 
									
										
										
										
											2011-03-21 08:31:32 +01:00
										 |  |  |    echo Recording: $__cdist_object requires $requirement | 
					
						
							| 
									
										
										
										
											2011-03-16 15:49:44 +01:00
										 |  |  | done |