55 lines
		
	
	
		
			958 B
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
		
			958 B
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
| #!/usr/bin/env bash
 | |
| 
 | |
| VERSION="0.1.0"
 | |
| 
 | |
| function help() {
 | |
|   echo -e \
 | |
|     "Usage: $(basename $0) [OPTIONS] [COMMAND]\n\n" \
 | |
|     "Options:\n" \
 | |
|     "   -i, --inv-file <path>       Specify the Ansible inventory to add.\n" \
 | |
|     "   -h, --help                  Show help.\n" \
 | |
|     "   -v, --version               Show version."
 | |
| }
 | |
| 
 | |
| if [[ $# -eq 0 ]]; then
 | |
|   help
 | |
|   exit 1
 | |
| fi
 | |
| 
 | |
| INVENTORY_FILE="$(pwd)/inventory"
 | |
| 
 | |
| while [[ $# -gt 0 ]]; do
 | |
|   case $1 in
 | |
|     -i|--inv-file)
 | |
|       INVENTORY_FILE="$2"
 | |
|       shift
 | |
|       shift
 | |
|       ;;
 | |
|     -h|--help)
 | |
|       help
 | |
|       exit 1
 | |
|       ;;
 | |
|     -v|--version)
 | |
|       echo $VERSION
 | |
|       exit 1
 | |
|       ;;
 | |
|     -*|--*)
 | |
|       echo "hosto: unrecognized option '$1'"
 | |
|       help
 | |
|       exit 1
 | |
|       ;;
 | |
|     *)
 | |
|       break
 | |
|       ;;
 | |
|   esac
 | |
| done
 | |
| 
 | |
| if [ -f $INVENTORY_FILE ]; then
 | |
|   sudo inv-alias add $INVENTORY_FILE
 | |
|   eval $@
 | |
|   sudo inv-alias rm $INVENTORY_FILE
 | |
| else
 | |
|   echo "hosto: Could not find inventory file at $INVENTORY_FILE"
 | |
|   eval $@
 | |
| fi
 |