| 
									
										
										
										
											2010-12-01 19:48:57 +01:00
										 |  |  | #!/bin/sh | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # 2010 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/>. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | #  | 
					
						
							| 
									
										
										
										
											2011-02-02 14:23:34 +01:00
										 |  |  | # Let's build a cconfig tree from a configuration | 
					
						
							|  |  |  | # And save it into the cache tree | 
					
						
							| 
									
										
										
										
											2010-12-01 19:48:57 +01:00
										 |  |  | # | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #[ $# -eq 1 ] || __cdist_usage "cconf" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | . cdist-config | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-01 20:07:58 +01:00
										 |  |  | set -au | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-02 14:23:34 +01:00
										 |  |  | cdist_tree_wrapper="$(which cdist_tree_wrapper)" | 
					
						
							| 
									
										
										
										
											2010-12-01 19:48:57 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | # used to build the tree and other stuff | 
					
						
							| 
									
										
										
										
											2011-02-02 14:23:34 +01:00
										 |  |  | __cdist_bindir="${__cdist_tmp_dir}/bin" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # FIXME: create cache/bin dir only once / do that in its | 
					
						
							|  |  |  | # own function | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Save output in cache | 
					
						
							|  |  |  | __cdist_output="${__cdist_cache_hosts}/${__cdist_target_host}" | 
					
						
							| 
									
										
										
										
											2010-12-01 20:01:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | cdist_type_prefix="__" | 
					
						
							| 
									
										
										
										
											2010-12-01 19:48:57 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | ################################################################################ | 
					
						
							|  |  |  | # Begin execution | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | cdist_tree_wrapper_name=${cdist_tree_wrapper##*/} | 
					
						
							|  |  |  | cdist_tree_wrapper_absdir=$(cd ${cdist_tree_wrapper%/*} && pwd -P) | 
					
						
							|  |  |  | cdist_tree_wrapper_abs="$cdist_tree_wrapper_absdir/$cdist_tree_wrapper_name" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-02 14:23:34 +01:00
										 |  |  | rm -rf "${__cdist_tmp_dir}" | 
					
						
							| 
									
										
										
										
											2010-12-01 19:48:57 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | # contains cdist-tree binaries | 
					
						
							|  |  |  | mkdir -p "${cdist_bindir}" | 
					
						
							|  |  |  | #ln -s "${cdist_tree_wrapper_abs}" "${bindir}" | 
					
						
							| 
									
										
										
										
											2011-01-14 12:46:51 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Create our binaries, will are called from the manifest - temporary | 
					
						
							| 
									
										
										
										
											2010-12-01 19:48:57 +01:00
										 |  |  | ( | 
					
						
							|  |  |  |    set -e | 
					
						
							| 
									
										
										
										
											2011-02-02 14:23:34 +01:00
										 |  |  |    cd "${__cdist_type_dir}" | 
					
						
							|  |  |  |    # FIXME: replace with redirect to file + read | 
					
						
							|  |  |  |    for bin in *; do | 
					
						
							| 
									
										
										
										
											2010-12-01 20:01:39 +01:00
										 |  |  |       ln -s "${cdist_tree_wrapper_abs}" "${cdist_type_prefix}${bin}" | 
					
						
							| 
									
										
										
										
											2011-02-02 14:23:34 +01:00
										 |  |  |    cd "${cdist_bindir}" | 
					
						
							| 
									
										
										
										
											2010-12-01 19:48:57 +01:00
										 |  |  |    done | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Cdist_tree_wrapper does not need any other tool, so remove them from the path. | 
					
						
							| 
									
										
										
										
											2011-01-15 01:23:18 +01:00
										 |  |  | # but the manifest may need so - FIXME: think about it. | 
					
						
							| 
									
										
										
										
											2010-12-01 20:01:39 +01:00
										 |  |  | #unset PATH | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # prepend our path | 
					
						
							|  |  |  | PATH="${cdist_bindir}:$PATH" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-01 20:48:15 +01:00
										 |  |  | # create output dir | 
					
						
							|  |  |  | mkdir -p "${cdist_confdir}" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-01 20:01:39 +01:00
										 |  |  | # force -x, so the user is aware the file is executed | 
					
						
							| 
									
										
										
										
											2011-02-02 14:01:21 +01:00
										 |  |  | if [ -x "${__cdist_manifest_init}" ]; then | 
					
						
							|  |  |  |    "${__cdist_manifest_init}" | 
					
						
							| 
									
										
										
										
											2010-12-01 20:01:39 +01:00
										 |  |  | else | 
					
						
							|  |  |  |    echo Throw some error, as you forgot to +x it. | 
					
						
							|  |  |  |    exit 1 | 
					
						
							|  |  |  | fi | 
					
						
							| 
									
										
										
										
											2010-12-01 20:48:15 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | echo "Finished tree generation, have a look at ${cdist_confdir}." |