From f7e75308cedaefb0c839ac0fb5ea57ea8cbdfe64 Mon Sep 17 00:00:00 2001 From: Brielle Bruns Date: Wed, 11 Apr 2018 17:01:16 -0600 Subject: [PATCH] Move usage function up to avoid issues, adjust help option --- virt-install-cloud.sh | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/virt-install-cloud.sh b/virt-install-cloud.sh index 881af86..e8e0f25 100755 --- a/virt-install-cloud.sh +++ b/virt-install-cloud.sh @@ -24,20 +24,6 @@ if [[ $USER != "root" ]]; then echo "This script must be run as root!" && exit 1 fi -while getopts "hcr:s:n:d:iob" opt; do - case $opt in - c) cpucount=("$OPTARG");; - r) ram=("$OPTARG");; - s) storage=("$OPTARG");; - n) hostname=("$OPTARG");; - d) domain=("$OPTARG");; - i) distro=("$OPTARG");; - o) ostype=("$OPTARG");; - b) bridge=("$OPTARG");; - h) usage;; - esac -done - usage() { echo "${0} Help" echo "-h show this help" @@ -51,7 +37,22 @@ usage() { echo "-o OS type and variant (default: generic:generic - also set by distro option when available)" } -if [[ -z $ram || -z $storage || -z $hostname || -z $domain || -z $bridge ]]; then +while getopts "hcr:s:n:d:iob" opt; do + case $opt in + c) cpucount=("$OPTARG");; + r) ram=("$OPTARG");; + s) storage=("$OPTARG");; + n) hostname=("$OPTARG");; + d) domain=("$OPTARG");; + i) distro=("$OPTARG");; + o) ostype=("$OPTARG");; + b) bridge=("$OPTARG");; + h) help="yes";; + esac +done + + +if [[ -z $ram || -z $storage || -z $hostname || -z $domain || -z $bridge || $help = "yes" ]]; then echo "Error: Incorrect command usage, must provide all * flags." usage exit 1