diff --git a/CHANGELOG.md b/CHANGELOG.md index 28ba97c47..8bd314169 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ - Adds an example `.gitlab.yml` file for GitLab CI/CD. [GH-675](https://github.com/vmware-samples/packer-examples-for-vsphere/pull/675) - Adds a `build-ci.tmpl` that can be used to create or update the `.gitlab-ci.yml` file using gomplate. [GH-675](https://github.com/vmware-samples/packer-examples-for-vsphere/pull/675) - Adds Packer logging settings to `set-envvars.sh`. [GH-705](https://github.com/vmware-samples/packer-examples-for-vsphere/pull/705) +- Adds a debug option (`--debug` or `-d`) to`./build.sh` to enable debug logging for Packer. [GH-706](https://github.com/vmware-samples/packer-examples-for-vsphere/pull/706) :bug: **Bugfix**: diff --git a/build.sh b/build.sh index e41948067..1442603ec 100755 --- a/build.sh +++ b/build.sh @@ -1,4 +1,6 @@ #!/usr/bin/env bash +# Copyright 2023 VMware, Inc. All rights reserved. +# SPDX-License-Identifier: BSD-2 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR @@ -16,16 +18,52 @@ follow_link() { echo "$FILE" } +if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then + echo "Usage: script.sh [OPTIONS] [CONFIG_PATH]" + echo "Options:" + echo " -h, --help Show this help message and exit." + echo " -d, --debug Run builds in debug mode." + exit 0 +fi + +if [ "$1" == "--debug" ] || [ "$1" == "-d" ]; then + debug_mode=true + debug_option="-debug" + shift +else + debug_mode=false + debug_option="" +fi + SCRIPT_PATH=$(realpath "$(dirname "$(follow_link "$0")")") -CONFIG_PATH=$(realpath "${1:-${SCRIPT_PATH}/config}") + +if [ -n "$1" ]; then + CONFIG_PATH=$(realpath "$1") +else + CONFIG_PATH=$(realpath "${SCRIPT_PATH}/config") +fi + +menu_banner=$(cat << "EOF" + ____ __ ____ _ __ __ + / __ \____ ______/ /_____ _____ / __ )__ __(_) /___/ /____ + / /_/ / __ / ___/ //_/ _ \/ ___/ / __ / / / / / / __ / ___/ + / ____/ /_/ / /__/ ,< / __/ / / /_/ / /_/ / / / /_/ (__ ) +/_/ \__,_/\___/_/|_|\___/_/ /_____/\__,_/_/_/\__,_/____/ +EOF +) + +menu_message="Select a HashiCorp Packer build for VMware vSphere." + +if [ "$debug_mode" = true ]; then + menu_message+=" \e[31m(Debug Mode)\e[0m" +fi menu_option_1() { INPUT_PATH="$SCRIPT_PATH"/builds/linux/photon/5/ echo -e "\nCONFIRM: Build a VMware Photon OS 5 Template for VMware vSphere?" echo -e "\nContinue? (y/n)" read -r REPLY - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi @@ -38,7 +76,8 @@ menu_option_1() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + echo "packer build -force -on-error=ask $debug_option" + packer build -force -on-error=ask $debug_option \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -46,8 +85,8 @@ menu_option_1() { -var-file="$CONFIG_PATH/common.pkrvars.hcl" \ "$INPUT_PATH" - ### All done. ### - echo "Done." + ### Build Complete. ### + echo "Build Complete." } menu_option_2() { @@ -55,8 +94,7 @@ menu_option_2() { echo -e "\nCONFIRM: Build a VMware Photon OS 4 Template for VMware vSphere?" echo -e "\nContinue? (y/n)" read -r REPLY - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi @@ -69,7 +107,8 @@ menu_option_2() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + echo "packer build -force -on-error=ask $debug_option" + packer build -force -on-error=ask $debug_option \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -77,8 +116,8 @@ menu_option_2() { -var-file="$CONFIG_PATH/common.pkrvars.hcl" \ "$INPUT_PATH" - ### All done. ### - echo "Done." + ### Build Complete. ### + echo "Build Complete." } menu_option_3() { @@ -86,8 +125,7 @@ menu_option_3() { echo -e "\nCONFIRM: Build a Debian 12 Template for VMware vSphere?" echo -e "\nContinue? (y/n)" read -r REPLY - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi @@ -100,7 +138,8 @@ menu_option_3() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + echo "packer build -force -on-error=ask $debug_option" + packer build -force -on-error=ask $debug_option \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -108,8 +147,8 @@ menu_option_3() { -var-file="$CONFIG_PATH/common.pkrvars.hcl" \ "$INPUT_PATH" - ### All done. ### - echo "Done." + ### Build Complete. ### + echo "Build Complete." } menu_option_4() { @@ -117,8 +156,7 @@ menu_option_4() { echo -e "\nCONFIRM: Build a Debian 11 Template for VMware vSphere?" echo -e "\nContinue? (y/n)" read -r REPLY - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi @@ -131,7 +169,8 @@ menu_option_4() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + echo "packer build -force -on-error=ask $debug_option" + packer build -force -on-error=ask $debug_option \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -139,8 +178,8 @@ menu_option_4() { -var-file="$CONFIG_PATH/common.pkrvars.hcl" \ "$INPUT_PATH" - ### All done. ### - echo "Done." + ### Build Complete. ### + echo "Build Complete." } menu_option_5() { @@ -148,8 +187,7 @@ menu_option_5() { echo -e "\nCONFIRM: Build a Ubuntu Server 22.04 LTS (cloud-init) Template for VMware vSphere?" echo -e "\nContinue? (y/n)" read -r REPLY - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi @@ -162,7 +200,8 @@ menu_option_5() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + echo "packer build -force -on-error=ask $debug_option" + packer build -force -on-error=ask $debug_option \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -170,8 +209,8 @@ menu_option_5() { -var-file="$CONFIG_PATH/common.pkrvars.hcl" \ "$INPUT_PATH" - ### All done. ### - echo "Done." + ### Build Complete. ### + echo "Build Complete." } menu_option_6() { @@ -179,8 +218,7 @@ menu_option_6() { echo -e "\nCONFIRM: Build a Ubuntu Server 20.04 LTS (cloud-init) Template for VMware vSphere?" echo -e "\nContinue? (y/n)" read -r REPLY - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi @@ -193,7 +231,8 @@ menu_option_6() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + echo "packer build -force -on-error=ask $debug_option" + packer build -force -on-error=ask $debug_option \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -201,8 +240,8 @@ menu_option_6() { -var-file="$CONFIG_PATH/common.pkrvars.hcl" \ "$INPUT_PATH" - ### All done. ### - echo "Done." + ### Build Complete. ### + echo "Build Complete." } menu_option_7() { @@ -210,8 +249,7 @@ menu_option_7() { echo -e "\nCONFIRM: Build a Red Hat Enterprise Linux 9 Template for VMware vSphere?" echo -e "\nContinue? (y/n)" read -r REPLY - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi @@ -224,7 +262,8 @@ menu_option_7() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + echo "packer build -force -on-error=ask $debug_option" + packer build -force -on-error=ask $debug_option \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -233,8 +272,8 @@ menu_option_7() { -var-file="$CONFIG_PATH/rhsm.pkrvars.hcl" \ "$INPUT_PATH" - ### All done. ### - echo "Done." + ### Build Complete. ### + echo "Build Complete." } menu_option_8() { @@ -242,8 +281,7 @@ menu_option_8() { echo -e "\nCONFIRM: Build a Red Hat Enterprise Linux 8 Template for VMware vSphere?" echo -e "\nContinue? (y/n)" read -r REPLY - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi @@ -256,7 +294,8 @@ menu_option_8() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + echo "packer build -force -on-error=ask $debug_option" + packer build -force -on-error=ask $debug_option \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -265,8 +304,8 @@ menu_option_8() { -var-file="$CONFIG_PATH/rhsm.pkrvars.hcl" \ "$INPUT_PATH" - ### All done. ### - echo "Done." + ### Build Complete. ### + echo "Build Complete." } menu_option_9() { @@ -274,8 +313,7 @@ menu_option_9() { echo -e "\nCONFIRM: Build a Red Hat Enterprise Linux 7 Template for VMware vSphere?" echo -e "\nContinue? (y/n)" read -r REPLY - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi @@ -288,7 +326,8 @@ menu_option_9() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + echo "packer build -force -on-error=ask $debug_option" + packer build -force -on-error=ask $debug_option \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -297,8 +336,8 @@ menu_option_9() { -var-file="$CONFIG_PATH/rhsm.pkrvars.hcl" \ "$INPUT_PATH" - ### All done. ### - echo "Done." + ### Build Complete. ### + echo "Build Complete." } menu_option_10() { @@ -306,8 +345,7 @@ menu_option_10() { echo -e "\nCONFIRM: Build a AlmaLinux OS 9 Template for VMware vSphere?" echo -e "\nContinue? (y/n)" read -r REPLY - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi @@ -320,7 +358,8 @@ menu_option_10() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + echo "packer build -force -on-error=ask $debug_option" + packer build -force -on-error=ask $debug_option \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -328,8 +367,8 @@ menu_option_10() { -var-file="$CONFIG_PATH/common.pkrvars.hcl" \ "$INPUT_PATH" - ### All done. ### - echo "Done." + ### Build Complete. ### + echo "Build Complete." } menu_option_11() { @@ -337,8 +376,7 @@ menu_option_11() { echo -e "\nCONFIRM: Build a AlmaLinux OS 8 Template for VMware vSphere?" echo -e "\nContinue? (y/n)" read -r REPLY - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi @@ -351,7 +389,8 @@ menu_option_11() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + echo "packer build -force -on-error=ask $debug_option" + packer build -force -on-error=ask $debug_option \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -359,8 +398,8 @@ menu_option_11() { -var-file="$CONFIG_PATH/common.pkrvars.hcl" \ "$INPUT_PATH" - ### All done. ### - echo "Done." + ### Build Complete. ### + echo "Build Complete." } menu_option_12() { @@ -368,8 +407,7 @@ menu_option_12() { echo -e "\nCONFIRM: Build a Rocky Linux 9 Template for VMware vSphere?" echo -e "\nContinue? (y/n)" read -r REPLY - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi @@ -382,7 +420,8 @@ menu_option_12() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + echo "packer build -force -on-error=ask $debug_option" + packer build -force -on-error=ask $debug_option \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -390,8 +429,8 @@ menu_option_12() { -var-file="$CONFIG_PATH/common.pkrvars.hcl" \ "$INPUT_PATH" - ### All done. ### - echo "Done." + ### Build Complete. ### + echo "Build Complete." } menu_option_13() { @@ -399,8 +438,7 @@ menu_option_13() { echo -e "\nCONFIRM: Build a Rocky Linux 8 Template for VMware vSphere?" echo -e "\nContinue? (y/n)" read -r REPLY - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi @@ -413,7 +451,8 @@ menu_option_13() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + echo "packer build -force -on-error=ask $debug_option" + packer build -force -on-error=ask $debug_option \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -421,8 +460,8 @@ menu_option_13() { -var-file="$CONFIG_PATH/common.pkrvars.hcl" \ "$INPUT_PATH" - ### All done. ### - echo "Done." + ### Build Complete. ### + echo "Build Complete." } menu_option_14() { @@ -430,8 +469,7 @@ menu_option_14() { echo -e "\nCONFIRM: Build a CentOS Stream 9 Template for VMware vSphere?" echo -e "\nContinue? (y/n)" read -r REPLY - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi @@ -444,7 +482,8 @@ menu_option_14() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + echo "packer build -force -on-error=ask $debug_option" + packer build -force -on-error=ask $debug_option \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -452,8 +491,8 @@ menu_option_14() { -var-file="$CONFIG_PATH/common.pkrvars.hcl" \ "$INPUT_PATH" - ### All done. ### - echo "Done." + ### Build Complete. ### + echo "Build Complete." } menu_option_15() { @@ -461,8 +500,7 @@ menu_option_15() { echo -e "\nCONFIRM: Build a CentOS Stream 8 Template for VMware vSphere?" echo -e "\nContinue? (y/n)" read -r REPLY - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi @@ -475,7 +513,8 @@ menu_option_15() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + echo "packer build -force -on-error=ask $debug_option" + packer build -force -on-error=ask $debug_option \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -483,8 +522,8 @@ menu_option_15() { -var-file="$CONFIG_PATH/common.pkrvars.hcl" \ "$INPUT_PATH" - ### All done. ### - echo "Done." + ### Build Complete. ### + echo "Build Complete." } menu_option_16() { @@ -492,8 +531,7 @@ menu_option_16() { echo -e "\nCONFIRM: Build a CentOS Linux 7 Template for VMware vSphere?" echo -e "\nContinue? (y/n)" read -r REPLY - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi @@ -506,7 +544,8 @@ menu_option_16() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + echo "packer build -force -on-error=ask $debug_option" + packer build -force -on-error=ask $debug_option \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -514,8 +553,8 @@ menu_option_16() { -var-file="$CONFIG_PATH/common.pkrvars.hcl" \ "$INPUT_PATH" - ### All done. ### - echo "Done." + ### Build Complete. ### + echo "Build Complete." } menu_option_17() { @@ -523,8 +562,7 @@ menu_option_17() { echo -e "\nCONFIRM: Build a SUSE Linux Enterprise Server 15 Template for VMware vSphere?" echo -e "\nContinue? (y/n)" read -r REPLY - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi @@ -537,7 +575,8 @@ menu_option_17() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + echo "packer build -force -on-error=ask $debug_option" + packer build -force -on-error=ask $debug_option \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -546,8 +585,8 @@ menu_option_17() { -var-file="$CONFIG_PATH/scc.pkrvars.hcl" \ "$INPUT_PATH" - ### All done. ### - echo "Done." + ### Build Complete. ### + echo "Build Complete." } menu_option_18() { @@ -555,8 +594,7 @@ menu_option_18() { echo -e "\nCONFIRM: Build a Oracle Enterprise Linux 9 Template for VMware vSphere?" echo -e "\nContinue? (y/n)" read -r REPLY - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi @@ -569,7 +607,8 @@ menu_option_18() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + echo "packer build -force -on-error=ask $debug_option" + packer build -force -on-error=ask $debug_option \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -577,8 +616,8 @@ menu_option_18() { -var-file="$CONFIG_PATH/common.pkrvars.hcl" \ "$INPUT_PATH" - ### All done. ### - echo "Done." + ### Build Complete. ### + echo "Build Complete." } menu_option_19() { @@ -586,8 +625,7 @@ menu_option_19() { echo -e "\nCONFIRM: Build a Oracle Enterprise Linux 8 Template for VMware vSphere?" echo -e "\nContinue? (y/n)" read -r REPLY - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi @@ -600,7 +638,8 @@ menu_option_19() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + echo "packer build -force -on-error=ask $debug_option" + packer build -force -on-error=ask $debug_option \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/ansible.pkrvars.hcl" \ @@ -608,8 +647,8 @@ menu_option_19() { -var-file="$CONFIG_PATH/common.pkrvars.hcl" \ "$INPUT_PATH" - ### All done. ### - echo "Done." + ### Build Complete. ### + echo "Build Complete." } @@ -618,8 +657,7 @@ menu_option_20() { echo -e "\nCONFIRM: Build all Windows Server 2022 Templates for VMware vSphere?" echo -e "\nContinue? (y/n)" read -r REPLY - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi @@ -632,14 +670,15 @@ menu_option_20() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + echo "packer build -force -on-error=ask $debug_option" + packer build -force -on-error=ask $debug_option \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/common.pkrvars.hcl" \ "$INPUT_PATH" - ### All done. ### - echo "Done." + ### Build Complete. ### + echo "Build Complete." } menu_option_21() { @@ -647,8 +686,7 @@ menu_option_21() { echo -e "\nCONFIRM: Build Microsoft Windows Server 2022 Standard Templates for VMware vSphere?" echo -e "\nContinue? (y/n)" read -r REPLY - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi @@ -661,15 +699,16 @@ menu_option_21() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + echo "packer build -force -on-error=ask $debug_option" + packer build -force -on-error=ask $debug_option \ --only vsphere-iso.windows-server-standard-dexp,vsphere-iso.windows-server-standard-core \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/common.pkrvars.hcl" \ "$INPUT_PATH" - ### All done. ### - echo "Done." + ### Build Complete. ### + echo "Build Complete." } menu_option_22() { @@ -677,8 +716,7 @@ menu_option_22() { echo -e "\nCONFIRM: Build Microsoft Windows Server 2022 Datacenter Templates for VMware vSphere?" echo -e "\nContinue? (y/n)" read -r REPLY - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi @@ -691,15 +729,16 @@ menu_option_22() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + echo "packer build -force -on-error=ask $debug_option" + packer build -force -on-error=ask $debug_option \ --only vsphere-iso.windows-server-datacenter-dexp,vsphere-iso.windows-server-datacenter-core \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/common.pkrvars.hcl" \ "$INPUT_PATH" - ### All done. ### - echo "Done." + ### Build Complete. ### + echo "Build Complete." } menu_option_23() { @@ -707,8 +746,7 @@ menu_option_23() { echo -e "\nCONFIRM: Build all Windows Server 2019 Templates for VMware vSphere?" echo -e "\nContinue? (y/n)" read -r REPLY - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi @@ -721,14 +759,15 @@ menu_option_23() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + echo "packer build -force -on-error=ask $debug_option" + packer build -force -on-error=ask $debug_option \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/common.pkrvars.hcl" \ "$INPUT_PATH" - ### All done. ### - echo "Done." + ### Build Complete. ### + echo "Build Complete." } menu_option_24() { @@ -736,8 +775,7 @@ menu_option_24() { echo -e "\nCONFIRM: Build Microsoft Windows Server 2019 Standard Templates for VMware vSphere?" echo -e "\nContinue? (y/n)" read -r REPLY - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi @@ -750,15 +788,16 @@ menu_option_24() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + echo "packer build -force -on-error=ask $debug_option" + packer build -force -on-error=ask $debug_option \ --only vsphere-iso.windows-server-standard-dexp,vsphere-iso.windows-server-standard-core \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/common.pkrvars.hcl" \ "$INPUT_PATH" - ### All done. ### - echo "Done." + ### Build Complete. ### + echo "Build Complete." } menu_option_25() { @@ -766,8 +805,7 @@ menu_option_25() { echo -e "\nCONFIRM: Build Microsoft Windows Server 2019 Datacenter Templates for VMware vSphere?" echo -e "\nContinue? (y/n)" read -r REPLY - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi @@ -780,29 +818,29 @@ menu_option_25() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + echo "packer build -force -on-error=ask $debug_option" + packer build -force -on-error=ask $debug_option \ --only vsphere-iso.windows-server-datacenter-dexp,vsphere-iso.windows-server-datacenter-core \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/common.pkrvars.hcl" \ "$INPUT_PATH" - ### All done. ### - echo "Done." + ### Build Complete. ### + echo "Build Complete." } menu_option_26() { INPUT_PATH="$SCRIPT_PATH"/builds/windows/desktop/11/ - echo -e "\nCONFIRM: Build a Windows 11 - All Template for VMware vSphere?" + echo -e "\nCONFIRM: Build all Windows 11 Templates for VMware vSphere?" echo -e "\nContinue? (y/n)" read -r REPLY - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi - ### Build a Windows 11 - All Template for VMware vSphere. ### - echo "Building a Windows 11 - All Template for VMware vSphere..." + ### Build all Windows 11 Templates for VMware vSphere. ### + echo "Building all Windows 11 Templates for VMware vSphere..." ### Initialize HashiCorp Packer and required plugins. ### echo "Initializing HashiCorp Packer and required plugins..." @@ -810,14 +848,15 @@ menu_option_26() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + echo "packer build -force -on-error=ask $debug_option" + packer build -force -on-error=ask $debug_option \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/common.pkrvars.hcl" \ "$INPUT_PATH" - ### All done. ### - echo "Done." + ### Build Complete. ### + echo "Build Complete." } menu_option_27() { @@ -825,8 +864,7 @@ menu_option_27() { echo -e "\nCONFIRM: Build a Windows 11 - Enterprise Only Template for VMware vSphere?" echo -e "\nContinue? (y/n)" read -r REPLY - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi @@ -839,15 +877,16 @@ menu_option_27() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + echo "packer build -force -on-error=ask $debug_option" + packer build -force -on-error=ask $debug_option \ --only vsphere-iso.windows-desktop-ent \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/common.pkrvars.hcl" \ "$INPUT_PATH" - ### All done. ### - echo "Done." + ### Build Complete. ### + echo "Build Complete." } menu_option_28() { @@ -855,8 +894,7 @@ menu_option_28() { echo -e "\nCONFIRM: Build a Windows 11 - Professional Only Template for VMware vSphere?" echo -e "\nContinue? (y/n)" read -r REPLY - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi @@ -869,29 +907,29 @@ menu_option_28() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + echo "packer build -force -on-error=ask $debug_option" + packer build -force -on-error=ask $debug_option \ --only vsphere-iso.windows-desktop-pro \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/common.pkrvars.hcl" \ "$INPUT_PATH" - ### All done. ### - echo "Done." + ### Build Complete. ### + echo "Build Complete." } menu_option_29() { INPUT_PATH="$SCRIPT_PATH"/builds/windows/desktop/10/ - echo -e "\nCONFIRM: Build a Windows 10 - All Template for VMware vSphere?" + echo -e "\nCONFIRM: Build all Windows 10 Templates for VMware vSphere?" echo -e "\nContinue? (y/n)" read -r REPLY - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi - ### Build a Windows 10 - All Template for VMware vSphere. ### - echo "Building a Windows 10 - All Template for VMware vSphere..." + ### Build all Windows 10 Templates for VMware vSphere. ### + echo "Building all Windows 10 Templates for VMware vSphere..." ### Initialize HashiCorp Packer and required plugins. ### echo "Initializing HashiCorp Packer and required plugins..." @@ -899,14 +937,15 @@ menu_option_29() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + echo "packer build -force -on-error=ask $debug_option" + packer build -force -on-error=ask $debug_option \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/common.pkrvars.hcl" \ "$INPUT_PATH" - ### All done. ### - echo "Done." + ### Build Complete. ### + echo "Build Complete." } menu_option_30() { @@ -914,8 +953,7 @@ menu_option_30() { echo -e "\nCONFIRM: Build a Windows 10 - Enterprise Only Template for VMware vSphere?" echo -e "\nContinue? (y/n)" read -r REPLY - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi @@ -928,15 +966,16 @@ menu_option_30() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + echo "packer build -force -on-error=ask $debug_option" + packer build -force -on-error=ask $debug_option \ --only vsphere-iso.windows-desktop-ent \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/common.pkrvars.hcl" \ "$INPUT_PATH" - ### All done. ### - echo "Done." + ### Build Complete. ### + echo "Build Complete." } menu_option_31() { @@ -944,8 +983,7 @@ menu_option_31() { echo -e "\nCONFIRM: Build a Windows 10 - Professional Only Template for VMware vSphere?" echo -e "\nContinue? (y/n)" read -r REPLY - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi @@ -958,15 +996,16 @@ menu_option_31() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + echo "packer build -force -on-error=ask $debug_option" + packer build -force -on-error=ask $debug_option \ --only vsphere-iso.windows-desktop-pro \ -var-file="$CONFIG_PATH/vsphere.pkrvars.hcl" \ -var-file="$CONFIG_PATH/build.pkrvars.hcl" \ -var-file="$CONFIG_PATH/common.pkrvars.hcl" \ "$INPUT_PATH" - ### All done. ### - echo "Done." + ### Build Complete. ### + echo "Build Complete." } press_enter() { @@ -977,28 +1016,23 @@ press_enter() { } info() { + echo "Copyright 2023 VMware, Inc. All rights reserved." echo "License: BSD-2" echo "" - echo "For more information, review the project README." echo "GitHub Repository: github.com/vmware-samples/packer-examples-for-vsphere/" read -r } incorrect_selection() { - echo "Do or do not. There is no try." + echo "Invalid selection, please try again." } until [ "$selection" = "0" ]; do clear echo "" - echo " ____ __ ____ _ __ __ " - echo " / __ \____ ______/ /_____ _____ / __ )__ __(_) /___/ /____ " - echo " / /_/ / __ / ___/ //_/ _ \/ ___/ / __ / / / / / / __ / ___/ " - echo " / ____/ /_/ / /__/ ,< / __/ / / /_/ / /_/ / / / /_/ (__ ) " - echo "/_/ \__,_/\___/_/|_|\___/_/ /_____/\__,_/_/_/\__,_/____/ " - echo "" - echo -n " Select a HashiCorp Packer build for VMware vSphere:" + echo -e "$menu_banner" echo "" + echo -e "$menu_message" echo "" echo " Linux Distribution:" echo "" diff --git a/build.tmpl b/build.tmpl index 46f30c3ac..649a6e7cb 100644 --- a/build.tmpl +++ b/build.tmpl @@ -1,4 +1,6 @@ #!/usr/bin/env bash +# Copyright 2023 VMware, Inc. All rights reserved. +# SPDX-License-Identifier: BSD-2 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR @@ -16,8 +18,45 @@ follow_link() { echo "$FILE" } +if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then + echo "Usage: script.sh [OPTIONS] [CONFIG_PATH]" + echo "Options:" + echo " -h, --help Show this help message and exit." + echo " -d, --debug Run builds in debug mode." + exit 0 +fi + +if [ "$1" == "--debug" ] || [ "$1" == "-d" ]; then + debug_mode=true + debug_option="-debug" + shift +else + debug_mode=false + debug_option="" +fi + SCRIPT_PATH=$(realpath "$(dirname "$(follow_link "$0")")") -CONFIG_PATH=$(realpath "${1:-${SCRIPT_PATH}/config}") + +if [ -n "$1" ]; then + CONFIG_PATH=$(realpath "$1") +else + CONFIG_PATH=$(realpath "${SCRIPT_PATH}/config") +fi + +menu_banner=$(cat << "EOF" + ____ __ ____ _ __ __ + / __ \____ ______/ /_____ _____ / __ )__ __(_) /___/ /____ + / /_/ / __ / ___/ //_/ _ \/ ___/ / __ / / / / / / __ / ___/ + / ____/ /_/ / /__/ ,< / __/ / / /_/ / /_/ / / / /_/ (__ ) +/_/ \__,_/\___/_/|_|\___/_/ /_____/\__,_/_/_/\__,_/____/ +EOF +) + +menu_message="Select a HashiCorp Packer build for VMware vSphere." + +if [ "$debug_mode" = true ]; then + menu_message+=" \e[31m(Debug Mode)\e[0m" +fi {{- $func_index := 0 }} {{ range $menu := (ds "build").menu -}} @@ -34,8 +73,7 @@ menu_option_{{ $func_index }}() { echo -e "\nCONFIRM: Build {{ $message }} for VMware vSphere?" echo -e "\nContinue? (y/n)" read -r REPLY - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi @@ -48,7 +86,8 @@ menu_option_{{ $func_index }}() { ### Start the Build. ### echo "Starting the build...." - packer build -force \ + echo "packer build -force -on-error=ask $debug_option" + packer build -force -on-error=ask $debug_option \ {{- if (coll.Has $submenu.build "only") }} --only {{ join $submenu.build.only "," }} \ {{- end -}} @@ -64,8 +103,8 @@ menu_option_{{ $func_index }}() { {{- end }} "$INPUT_PATH" - ### All done. ### - echo "Done." + ### Build Complete. ### + echo "Build Complete." } {{ end }} {{ end -}} @@ -78,28 +117,23 @@ press_enter() { } info() { + echo "Copyright 2023 VMware, Inc. All rights reserved." echo "License: BSD-2" echo "" - echo "For more information, review the project README." echo "GitHub Repository: github.com/vmware-samples/packer-examples-for-vsphere/" read -r } incorrect_selection() { - echo "Do or do not. There is no try." + echo "Invalid selection, please try again." } until [ "$selection" = "0" ]; do clear echo "" - echo " ____ __ ____ _ __ __ " - echo " / __ \____ ______/ /_____ _____ / __ )__ __(_) /___/ /____ " - echo " / /_/ / __ / ___/ //_/ _ \/ ___/ / __ / / / / / / __ / ___/ " - echo " / ____/ /_/ / /__/ ,< / __/ / / /_/ / /_/ / / / /_/ (__ ) " - echo "/_/ \__,_/\___/_/|_|\___/_/ /_____/\__,_/_/_/\__,_/____/ " - echo "" - echo -n " Select a HashiCorp Packer build for VMware vSphere:" + echo -e "$menu_banner" echo "" + echo -e "$menu_message" echo "" {{- $menu_index := 0 }} {{- range $menu := (ds "build").menu }} diff --git a/build.yaml b/build.yaml index 6dad111b5..f7cf464dd 100644 --- a/build.yaml +++ b/build.yaml @@ -119,6 +119,7 @@ menu: - vsphere-iso.windows-server-datacenter-dexp - vsphere-iso.windows-server-datacenter-core - entry: "Windows 11 - All" + message: "all Windows 11 Templates" build: path: "builds/windows/desktop/11/" - entry: "Windows 11 - Enterprise Only" @@ -132,6 +133,7 @@ menu: only: - vsphere-iso.windows-desktop-pro - entry: "Windows 10 - All" + message: "all Windows 10 Templates" build: path: "builds/windows/desktop/10/" - entry: "Windows 10 - Enterprise Only"