From d9364d5d3b482135d1664d86c1bdb309c95d48e9 Mon Sep 17 00:00:00 2001 From: Glenn Musa <4622125+glennmusa@users.noreply.github.com> Date: Thu, 29 Apr 2021 10:18:05 -0400 Subject: [PATCH] add --help option and handle unexpected arguments (#182) --- src/clean.sh | 16 +++++-- src/deploy.sh | 41 ++++++++++++++---- src/docs/command-line-deployment.md | 4 +- src/docs/ui-deployment.md | 3 +- src/scripts/config/generate_config_file.sh | 49 ++++++++++++++++----- src/scripts/export_docker.sh | 13 +++++- src/scripts/setup_ezdeploy.sh | 50 +++++++++++++++++----- 7 files changed, 137 insertions(+), 39 deletions(-) mode change 100644 => 100755 src/scripts/export_docker.sh diff --git a/src/clean.sh b/src/clean.sh index a5ae57851..cdb55c4a0 100755 --- a/src/clean.sh +++ b/src/clean.sh @@ -21,7 +21,8 @@ show_help() { printf "%20s %2s %s \n" "$long_name" "$char_name" "$desc" } print_formatted "argument" "" "description" - print_formatted "--mlz-env-name" "-z" "[OPTIONAL] Unique name for MLZ environment (defaults to 'mlz' + UNIX timestamp)" + print_formatted "--mlz-env-name" "-z" "Unique name for MLZ environment" + print_formatted "--help" "-h" "Print this message" } usage() { @@ -33,14 +34,23 @@ this_script_path=$(realpath "${BASH_SOURCE%/*}") configuration_output_path="${this_script_path}/generated-configurations" # check for dependencies - "${this_script_path}/scripts/util/checkforazcli.sh" "${this_script_path}/scripts/util/checkforterraform.sh" +mlz_env_name="notset" + # inspect user input while [ $# -gt 0 ] ; do case $1 in - -z | --mlz-env-name) mlz_env_name="$2" ;; + -z | --mlz-env-name) + shift + mlz_env_name="$1" ;; + -h | --help) + show_help + exit 0 ;; + *) + error_log "ERROR: Unexpected argument: ${1}" + usage && exit 1 ;; esac shift done diff --git a/src/deploy.sh b/src/deploy.sh index 70668cb2e..eb9110fb8 100755 --- a/src/deploy.sh +++ b/src/deploy.sh @@ -26,10 +26,11 @@ show_help() { print_formatted "--location" "-l" "[OPTIONAL] The location that you're deploying to (defaults to 'eastus')" print_formatted "--tf-environment" "-e" "[OPTIONAL] Terraform azurerm environment (defaults to 'public') see: https://www.terraform.io/docs/language/settings/backends/azurerm.html#environment" print_formatted "--mlz-env-name" "-z" "[OPTIONAL] Unique name for MLZ environment (defaults to 'mlz' + UNIX timestamp)" - print_formatted "--hub-sub-id" "-h" "[OPTIONAL] subscription ID for the hub network and resources (defaults to the value provided for -s --subscription-id)" + print_formatted "--hub-sub-id" "-u" "[OPTIONAL] subscription ID for the hub network and resources (defaults to the value provided for -s --subscription-id)" print_formatted "--tier0-sub-id" "-0" "[OPTIONAL] subscription ID for tier 0 network and resources (defaults to the value provided for -s --subscription-id)" print_formatted "--tier1-sub-id" "-1" "[OPTIONAL] subscription ID for tier 1 network and resources (defaults to the value provided for -s --subscription-id)" print_formatted "--tier2-sub-id" "-2" "[OPTIONAL] subscription ID for tier 2 network and resources (defaults to the value provided for -s --subscription-id)" + print_formatted "--help" "-h" "Print this message" } usage() { @@ -64,14 +65,36 @@ subs_args=() # inspect user input while [ $# -gt 0 ] ; do case $1 in - -s | --subscription-id) mlz_config_subid="$2" ;; - -l | --location) mlz_config_location="$2" ;; - -e | --tf-environment) tf_environment="$2" ;; - -z | --mlz-env-name) mlz_env_name="$2" ;; - -h | --hub-sub-id) subs_args+=("-h ${2}") ;; - -0 | --tier0-sub-id) subs_args+=("-0 ${2}") ;; - -1 | --tier1-sub-id) subs_args+=("-1 ${2}") ;; - -2 | --tier2-sub-id) subs_args+=("-2 ${2}") ;; + -s | --subscription-id) + shift + mlz_config_subid="$1" ;; + -l | --location) + shift + mlz_config_location="$1" ;; + -e | --tf-environment) + shift + tf_environment="$1" ;; + -z | --mlz-env-name) + shift + mlz_env_name="$1" ;; + -u | --hub-sub-id) + shift + subs_args+=("-u ${1}") ;; + -0 | --tier0-sub-id) + shift + subs_args+=("-0 ${1}") ;; + -1 | --tier1-sub-id) + shift + subs_args+=("-1 ${1}") ;; + -2 | --tier2-sub-id) + shift + subs_args+=("-2 ${1}") ;; + -h | --help) + show_help + exit 0 ;; + *) + error_log "ERROR: Unexpected argument: ${1}" + usage && exit 1 ;; esac shift done diff --git a/src/docs/command-line-deployment.md b/src/docs/command-line-deployment.md index afa578189..30ed4ed76 100644 --- a/src/docs/command-line-deployment.md +++ b/src/docs/command-line-deployment.md @@ -74,7 +74,7 @@ deploy.sh: create all the configuration and deploy Terraform resources with mini --location -l [OPTIONAL] The location that you're deploying to (defaults to 'eastus') --tf-environment -e [OPTIONAL] Terraform azurerm environment (defaults to 'public') see: https://www.terraform.io/docs/language/settings/backends/azurerm.html#environment --mlz-env-name -z [OPTIONAL] Unique name for MLZ environment (defaults to 'mlz' + UNIX timestamp) - --hub-sub-id -h [OPTIONAL] subscription ID for the hub network and resources (defaults to the value provided for -s --subscription-id) + --hub-sub-id -u [OPTIONAL] subscription ID for the hub network and resources (defaults to the value provided for -s --subscription-id) --tier0-sub-id -0 [OPTIONAL] subscription ID for tier 0 network and resources (defaults to the value provided for -s --subscription-id) --tier1-sub-id -1 [OPTIONAL] subscription ID for tier 1 network and resources (defaults to the value provided for -s --subscription-id) --tier2-sub-id -2 [OPTIONAL] subscription ID for tier 2 network and resources (defaults to the value provided for -s --subscription-id) @@ -84,7 +84,7 @@ For example, if I wanted to deploy into four subscriptions (one for each network ```bash src/deploy.sh -s {my_mlz_configuration_subscription_id} \ - -h {my_hub_network_subscription_id} \ + -u {my_hub_network_subscription_id} \ -0 {my_identity_network_subscription_id} \ -1 {my_operations_network_subscription_id} \ -2 {my_shared_services_network_subscription_id} \ diff --git a/src/docs/ui-deployment.md b/src/docs/ui-deployment.md index a47d42fa7..38f960fdf 100644 --- a/src/docs/ui-deployment.md +++ b/src/docs/ui-deployment.md @@ -59,11 +59,12 @@ setup_ezdeploy.sh: Setup the front end for MLZ --tf-environment -e Terraform azurerm environment (defaults to 'public') see: https://www.terraform.io/docs/language/settings/backends/azurerm.html#environment --mlz-env-name -z Unique name for MLZ environment (defaults to 'mlz' + UNIX timestamp) --port -p port to expose the front end web UI on (defaults to '80') - --hub-sub-id -h subscription ID for the hub network and resources (defaults to the value provided for -s --subscription-id) + --hub-sub-id -u subscription ID for the hub network and resources (defaults to the value provided for -s --subscription-id) --tier0-sub-id -0 subscription ID for tier 0 network and resources (defaults to the value provided for -s --subscription-id) --tier1-sub-id -1 subscription ID for tier 1 network and resources (defaults to the value provided for -s --subscription-id) --tier2-sub-id -2 subscription ID for tier 2 network and resources (defaults to the value provided for -s --subscription-id) --zip-file -f Zipped docker file for use with the 'load' docker strategy (defaults to 'mlz.zip') + --help -h Print this message ``` ## Step-by-Step Azure Air Gapped Installation diff --git a/src/scripts/config/generate_config_file.sh b/src/scripts/config/generate_config_file.sh index 491b4f558..8c51c2d61 100755 --- a/src/scripts/config/generate_config_file.sh +++ b/src/scripts/config/generate_config_file.sh @@ -27,10 +27,11 @@ show_help() { print_formatted "--location" "-l" "The location that you're deploying to (e.g. 'eastus')" print_formatted "--config-sub-id" "-s" "Subscription ID for MissionLZ configuration resources" print_formatted "--tenant-id" "-t" "Tenant ID where your subscriptions live" - print_formatted "--hub-sub-id" "-h" "[OPTIONAL]: subscription ID for the hub network and resources" + print_formatted "--hub-sub-id" "-u" "[OPTIONAL]: subscription ID for the hub network and resources" print_formatted "--tier0-sub-id" "-0" "[OPTIONAL]: subscription ID for tier 0 network and resources" print_formatted "--tier1-sub-id" "-1" "[OPTIONAL]: subscription ID for tier 1 network and resources" print_formatted "--tier2-sub-id" "-2" "[OPTIONAL]: subscription ID for tier 2 network and resources" + print_formatted "--help" "-h" "Print this message" } usage() { @@ -49,16 +50,42 @@ mlz_tenant_id="notset" # inspect arguments while [ $# -gt 0 ] ; do case $1 in - -f | --file) dest_file="$2" ;; - -e | --tf-env) tf_environment="$2" ;; - -z | --mlz-env-name) mlz_env_name="$2" ;; - -l | --location) mlz_config_location="$2" ;; - -s | --config-sub-id) mlz_config_subid="$2" ;; - -t | --tenant-id) mlz_tenant_id="$2" ;; - -h | --hub-sub-id) mlz_saca_subid="$2" ;; - -0 | --tier0-sub-id) mlz_tier0_subid="$2" ;; - -1 | --tier1-sub-id) mlz_tier1_subid="$2" ;; - -2 | --tier2-sub-id) mlz_tier2_subid="$2" ;; + -f | --file) + shift + dest_file="$1" ;; + -e | --tf-env) + shift + tf_environment="$1" ;; + -z | --mlz-env-name) + shift + mlz_env_name="$1" ;; + -l | --location) + shift + mlz_config_location="$1" ;; + -s | --config-sub-id) + shift + mlz_config_subid="$1" ;; + -t | --tenant-id) + shift + mlz_tenant_id="$1" ;; + -u | --hub-sub-id) + shift + mlz_saca_subid="$1" ;; + -0 | --tier0-sub-id) + shift + mlz_tier0_subid="$1" ;; + -1 | --tier1-sub-id) + shift + mlz_tier1_subid="$1" ;; + -2 | --tier2-sub-id) + shift + mlz_tier2_subid="$1" ;; + -h | --help) + show_help + exit 0 ;; + *) + error_log "ERROR: Unexpected argument: ${1}" + usage && exit 1 ;; esac shift done diff --git a/src/scripts/export_docker.sh b/src/scripts/export_docker.sh old mode 100644 new mode 100755 index 87cbff3cb..f0e1cc926 --- a/src/scripts/export_docker.sh +++ b/src/scripts/export_docker.sh @@ -9,7 +9,7 @@ # SC1091: Not following. Shellcheck can't follow non-constant source. # SC2154: "var is referenced but not assigned". These values come from an external file. # -# This script locally saves a local docker image for movement between airgapped networks. +# This script locally saves a local docker image for movement between airgapped networks. set -e @@ -26,6 +26,7 @@ show_help() { } print_formatted "argument" "" "description" print_formatted "--output-file" "-f" "Output file name/location, defaults to same directory 'mlz.zip'" + print_formatted "--help" "-h" "Print this message" } usage() { @@ -39,7 +40,15 @@ zip_file="mlz.zip" # inspect user input while [ $# -gt 0 ] ; do case $1 in - -f | --output-file) zip_file="$2" ;; + -f | --output-file) + shift + zip_file="$1" ;; + -h | --help) + show_help + exit 0 ;; + *) + error_log "ERROR: Unexpected argument: ${1}" + usage && exit 1 ;; esac shift done diff --git a/src/scripts/setup_ezdeploy.sh b/src/scripts/setup_ezdeploy.sh index 7a474e2c6..b00592fcf 100755 --- a/src/scripts/setup_ezdeploy.sh +++ b/src/scripts/setup_ezdeploy.sh @@ -34,6 +34,7 @@ show_help() { print_formatted "--tier1-sub-id" "-1" "subscription ID for tier 1 network and resources (defaults to the value provided for -s --subscription-id)" print_formatted "--tier2-sub-id" "-2" "subscription ID for tier 2 network and resources (defaults to the value provided for -s --subscription-id)" print_formatted "--zip-file" "-f" "Zipped docker file for use with the 'load' docker strategy (defaults to 'mlz.zip')" + print_formatted "--help" "-h" "Print this message" } usage() { @@ -64,17 +65,44 @@ subs_args=() # inspect user input while [ $# -gt 0 ] ; do case $1 in - -d | --docker-strategy) docker_strategy="$2" ;; - -s | --subscription-id) mlz_config_subid="$2" ;; - -l | --location) mlz_config_location="$2" ;; - -e | --tf-environment) tf_environment="$2" ;; - -z | --mlz-env-name) mlz_env_name="$2" ;; - -p | --port) web_port="$2" ;; - -h | --hub-sub-id) subs_args+=("-h ${2}") ;; - -0 | --tier0-sub-id) subs_args+=("-0 ${2}") ;; - -1 | --tier1-sub-id) subs_args+=("-1 ${2}") ;; - -2 | --tier2-sub-id) subs_args+=("-2 ${2}") ;; - -f | --zip-file) zip_file="$2" ;; + -d | --docker-strategy) + shift + docker_strategy="$1" ;; + -s | --subscription-id) + shift + mlz_config_subid="$1" ;; + -l | --location) + shift + mlz_config_location="$1" ;; + -e | --tf-environment) + shift + tf_environment="$1" ;; + -z | --mlz-env-name) + shift + mlz_env_name="$1" ;; + -p | --port) + shift + web_port="$1" ;; + -u | --hub-sub-id) + shift + subs_args+=("-u ${1}") ;; + -0 | --tier0-sub-id) + shift + subs_args+=("-0 ${1}") ;; + -1 | --tier1-sub-id) + subs_args+=("-1 ${1}") ;; + -2 | --tier2-sub-id) + shift + subs_args+=("-2 ${1}") ;; + -f | --zip-file) + shift + zip_file="$1" ;; + -h | --help) + show_help + exit 0 ;; + *) + error_log "ERROR: Unexpected argument: ${1}" + usage && exit 1 ;; esac shift done