| 
									
										
										
										
											2011-02-14 11:28:14 +01: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 16:07:07 +01:00
										 |  |  | # WARNING: OUTPUT ON STDOUT, ERRORS NEED TO BE ON STDERR! | 
					
						
							| 
									
										
										
										
											2011-02-14 11:28:14 +01:00
										 |  |  | # | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | . cdist-config | 
					
						
							| 
									
										
										
										
											2011-04-28 14:45:14 +02:00
										 |  |  | [ $# -eq 3 ] || __cdist_usage "<target host>" "<object>" "<type>" | 
					
						
							| 
									
										
										
										
											2011-02-17 16:13:35 +01:00
										 |  |  | set -eu | 
					
						
							| 
									
										
										
										
											2011-02-14 11:28:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-25 01:17:32 +01:00
										 |  |  | __cdist_target_host="$1"; shift | 
					
						
							| 
									
										
										
										
											2011-04-06 21:41:40 +02:00
										 |  |  | __cdist_object_self="$1"; shift | 
					
						
							| 
									
										
										
										
											2011-03-19 22:15:54 +01:00
										 |  |  | __cdist_gencode_type="$1"; shift | 
					
						
							| 
									
										
										
										
											2011-02-14 11:28:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-06 21:41:40 +02:00
										 |  |  | __cdist_type="$(__cdist_type_from_object "$__cdist_object_self")" | 
					
						
							| 
									
										
										
										
											2011-04-28 14:59:57 +02:00
										 |  |  | __cdist_type_gencode="$(__cdist_type_gencode "$__cdist_type" "$__cdist_gencode_type")" | 
					
						
							| 
									
										
										
										
											2011-04-28 15:07:13 +02:00
										 |  |  | __cdist_code_output="$(__cdist_object_code "$__cdist_object_self" "$__cdist_gencode_type")" | 
					
						
							| 
									
										
										
										
											2011-02-14 11:28:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-28 15:07:13 +02:00
										 |  |  | # export variables for the gencode script | 
					
						
							|  |  |  | export __object_id="$(__cdist_object_id_from_object "$__cdist_object_self")" | 
					
						
							|  |  |  | export __object="$(__cdist_object_dir "$__cdist_object_self")" | 
					
						
							| 
									
										
										
										
											2011-03-03 10:37:11 +01:00
										 |  |  | export __global="$__cdist_out_dir" | 
					
						
							| 
									
										
										
										
											2011-02-25 01:17:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-28 14:59:57 +02:00
										 |  |  | if [ -x "$__cdist_type_gencode" ]; then | 
					
						
							| 
									
										
										
										
											2011-04-28 15:07:13 +02:00
										 |  |  |    __cdist_exec_fail_on_error "$__cdist_type_gencode" > "$__cdist_tmp_file" | 
					
						
							| 
									
										
										
										
											2011-02-22 22:40:34 +01:00
										 |  |  | else | 
					
						
							| 
									
										
										
										
											2011-04-28 15:07:13 +02:00
										 |  |  |    if [ -e "$__cdist_type_gencode" ]; then | 
					
						
							| 
									
										
										
										
											2011-04-28 14:59:57 +02:00
										 |  |  |       __cdist_exit_err "$__cdist_type_gencode exists, but is not executable" | 
					
						
							| 
									
										
										
										
											2011-02-22 22:40:34 +01:00
										 |  |  |    fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-28 14:59:57 +02:00
										 |  |  |    # Ensure it's empty, if there is no gencode | 
					
						
							|  |  |  |    : > "$__cdist_tmp_file" | 
					
						
							| 
									
										
										
										
											2011-02-22 22:40:34 +01:00
										 |  |  | fi | 
					
						
							| 
									
										
										
										
											2011-04-28 14:37:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-28 14:59:57 +02: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 14:37:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-28 14:59:57 +02:00
										 |  |  | eof | 
					
						
							|  |  |  |    chmod u+x "${__cdist_code_output}" | 
					
						
							|  |  |  | fi |