Move usage function up to avoid issues, adjust help option

master
Brie Bruns 2018-04-11 17:01:16 -06:00
parent 5fc9a39bff
commit f7e75308ce
1 changed files with 16 additions and 15 deletions

View File

@ -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