| 
									
										
										
										
											2011-02-23 16:31:28 +01:00
										 |  |  | #!/bin/sh | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2011-02-23 16:45:38 +01:00
										 |  |  | # 2011 Nico Schottelius (nico-cdist at schottelius.org) | 
					
						
							| 
									
										
										
										
											2011-02-23 16:31:28 +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/>. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | . cdist-config | 
					
						
							|  |  |  | if [ $# -lt 3 ]; then | 
					
						
							| 
									
										
										
										
											2011-02-23 16:45:38 +01:00
										 |  |  |    __cdist_usage "<work dir> <explorer dir> <out dir> [explorer args]" | 
					
						
							| 
									
										
										
										
											2011-02-23 16:31:28 +01:00
										 |  |  | fi | 
					
						
							|  |  |  | set -ue | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-23 16:45:38 +01:00
										 |  |  | # cd to this dir | 
					
						
							|  |  |  | __cdist_work_dir="$1"; shift | 
					
						
							| 
									
										
										
										
											2011-02-23 16:31:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-23 16:45:38 +01:00
										 |  |  | # find explorers here | 
					
						
							|  |  |  | __cdist_explorer_dir="$1"; shift | 
					
						
							| 
									
										
										
										
											2011-02-23 16:31:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-23 16:45:38 +01:00
										 |  |  | # write output here | 
					
						
							|  |  |  | __cdist_my_out_dir="$1"; shift | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | cd "${__cdist_work_dir}" | 
					
						
							| 
									
										
										
										
											2011-02-23 16:49:39 +01:00
										 |  |  | mkdir -p "$__cdist_my_out_dir" | 
					
						
							| 
									
										
										
										
											2011-02-23 16:31:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Ensure there is at least one explorer | 
					
						
							| 
									
										
										
										
											2011-02-23 16:45:38 +01:00
										 |  |  | num="$(ls -1 "$__cdist_explorer_dir" | wc -l)" | 
					
						
							| 
									
										
										
										
											2011-02-23 16:31:28 +01:00
										 |  |  | if [ "$num" -lt 1 ]; then | 
					
						
							| 
									
										
										
										
											2011-02-23 16:45:38 +01:00
										 |  |  |    __cdist_exit_err "${__cdist_explorer_dir}: Contains no explorers" | 
					
						
							| 
									
										
										
										
											2011-02-23 16:31:28 +01:00
										 |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Execute all explorers | 
					
						
							| 
									
										
										
										
											2011-02-23 16:45:38 +01:00
										 |  |  | for explorer in "$__cdist_explorer_dir/"*; do | 
					
						
							| 
									
										
										
										
											2011-02-23 16:31:28 +01:00
										 |  |  |    if [ -f "$explorer" ]; then | 
					
						
							|  |  |  |       if [ ! -x "$explorer" ]; then | 
					
						
							|  |  |  |          echo "Explorer \"$explorer\" exists, but is not executable." | 
					
						
							|  |  |  |          continue | 
					
						
							|  |  |  |       fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       # Execute explorers and save results in remote destination directory | 
					
						
							| 
									
										
										
										
											2011-02-23 16:45:38 +01:00
										 |  |  |       "$explorer" "$@" > "${__cdist_my_out_dir}" | 
					
						
							| 
									
										
										
										
											2011-02-23 16:31:28 +01:00
										 |  |  |    else | 
					
						
							|  |  |  |       if [ -e "$explorer" ]; then | 
					
						
							|  |  |  |          echo "Explorer \"$explorer\" exists, but is not a file." | 
					
						
							|  |  |  |          continue | 
					
						
							|  |  |  |       fi | 
					
						
							|  |  |  |    fi | 
					
						
							|  |  |  | done |