Skip to content

Commit 9d0b7cc

Browse files
committed
chore(release): v0.22.1 (#1024)
Release v0.22.1. Signed-off-by: Ryan Johnson <ryan.johnson@broadcom.com>
1 parent 673847c commit 9d0b7cc

File tree

4 files changed

+95
-63
lines changed

4 files changed

+95
-63
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Release History
22

3+
## v0.22.1
4+
5+
> Release Date: 2025-03-05
6+
7+
**Bug Fix**:
8+
9+
- Fixes issue with `config.sh` not creating the default or specified configuration path.
10+
[#1024](https://github.com/vmware-samples/packer-examples-for-vsphere/pull/1024)
11+
312
## v0.22.0
413

514
> Release Date: 2025-02-11

config.sh

Lines changed: 74 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -6,80 +6,95 @@
66
set -e
77

88
follow_link() {
9-
FILE="${1}"
10-
while [ -h "${FILE}" ]; do
11-
# On macOS, readlink -f doesn't work.
12-
FILE="$(readlink "${FILE}")"
9+
local file="$1"
10+
while [[ -h "${file}" ]]; do
11+
file="$(readlink "${file}")"
12+
if [[ ! -e "${file}" ]]; then
13+
echo "Error: Broken symbolic link: $1" >&2
14+
exit 1
15+
fi
1316
done
14-
echo "${FILE}"
17+
printf '%s\n' "${file}"
1518
}
1619

17-
# This function displays the help message.
1820
show_help() {
19-
local exit_after=${1:-"exit"}
20-
script_name=$(basename "$0")
21-
22-
printf "\033[0;32m Usage\033[0m: %s [options] [config_path]\n\n" "$script_name"
23-
printf "\033[0;34m Options:\033[0m\n"
24-
printf " \033[0;34m --help, -h, -H\033[0m Display this help message.\n\n"
25-
printf "\033[0;34m config_path:\033[0m\n"
26-
printf " \033[0m Path to save the generated configuration files. (Optional).\n\n"
27-
28-
# Handle user input or exit.
29-
if [[ -z "$input" ]]; then
30-
[ "$exit_after" = "exit" ] && exit 0
31-
else
32-
press_enter_continue
21+
local exit_after="${1:-exit}"
22+
local script_name="$(basename "$0")"
23+
24+
printf 'Usage: %s [options] [config_path]\n\n' "${script_name}"
25+
printf 'Options:\n'
26+
printf ' --help, -h, -H Display this help message.\n\n'
27+
printf 'config_path:\n'
28+
printf ' Path to save the generated configuration files. (Optional).\n\n'
29+
30+
if [[ -z "${input}" ]]; then
31+
if [[ "${exit_after}" == "exit" ]]; then
32+
exit 0
33+
fi
3334
fi
35+
read -p "Press Enter to continue..."
3436
}
3537

36-
# Define the script and default config paths
37-
follow_link_result=$(follow_link "$0")
38-
if ! SCRIPT_PATH=$(realpath "$(dirname "${follow_link_result}")"); then
39-
echo "Error: follow_link or realpath failed"
38+
script_path="$(dirname "$(follow_link "$0")")"
39+
40+
config_path="${1:-${script_path}/config}"
41+
42+
if [[ "$1" == "--help" || "$1" == "-h" || "$1" == "-H" ]]; then
43+
show_help
44+
exit 0
45+
fi
46+
47+
if ! mkdir -p "${config_path}"; then
48+
echo "Error: Failed to create directory: ${config_path}" >&2
4049
exit 1
4150
fi
4251

43-
# Set config_path if it's not already set
44-
if [ -z "$CONFIG_PATH" ]; then
45-
CONFIG_PATH=$(
46-
cd "${SCRIPT_PATH}/config" || exit
47-
pwd
48-
)
52+
backup_dir=""
53+
backup_taken=0
54+
55+
if [[ -d "${config_path}" && "$(find "${config_path}" -maxdepth 1 -type f -name "*.hcl" -print -quit 2>/dev/null)" ]]; then
56+
echo "> Backing up existing configurations..."
57+
backup_time=$(date +%Y%m%d-%H%M%S)
58+
backup_dir="${config_path}/backup.${backup_time}"
59+
if ! mkdir -p "${backup_dir}"; then
60+
echo "Error: Failed to create backup directory: ${backup_dir}" >&2
61+
exit 1
62+
fi
63+
find "${config_path}" -maxdepth 1 -type f -name "*.hcl" -print0 |
64+
xargs -0 -I {} bash -c 'if mv "$1" "${2}/$(basename "$1")"; then :; else echo "Error moving $1"; exit 1; fi' -- {} "${backup_dir}"
65+
if [[ $? -ne 0 ]]; then
66+
echo "Error: Some configuration files failed to move to backup" >&2
67+
exit 1
68+
fi
69+
if ! rm -f "${config_path}"/*.hcl; then
70+
echo "Error: Failed to remove original configuration files" >&2
71+
exit 1
72+
fi
73+
backup_taken=1
74+
echo "> Backup created: ${backup_dir}"
4975
fi
5076

51-
# Script options.
52-
while (("$#")); do
53-
case "$1" in
54-
--help | -h | -H)
55-
run_show_help=true
56-
show_help
57-
shift
58-
;;
59-
*)
60-
CONFIG_PATH=$(realpath "$1")
61-
shift
62-
;;
63-
esac
64-
done
77+
cp -av "${script_path}"/builds/*.pkrvars.hcl.example "${config_path}" 2>&1 >/dev/null
6578

66-
mkdir -p "${CONFIG_PATH}"
67-
### Copy the example input variables.
68-
echo
69-
echo "> Copying the example input variables..."
70-
cp -av "${SCRIPT_PATH}"/builds/*.pkrvars.hcl.example "${CONFIG_PATH}"
71-
find "${SCRIPT_PATH}"/builds/*/ -type f -name "*.pkrvars.hcl.example" | while IFS= read -r srcfile; do
79+
find "${script_path}"/builds/*/ -type f -name "*.pkrvars.hcl.example" -print0 | while IFS= read -r -d $'\0' srcfile; do
7280
srcdir=$(dirname "${srcfile}" | tr -s /)
73-
dstfile=$(echo "${srcdir#"${SCRIPT_PATH}"/builds/}" | tr '/' '-')
74-
cp -av "${srcfile}" "${CONFIG_PATH}/${dstfile}.pkrvars.hcl.example"
81+
dstfile=$(echo "${srcdir#"${script_path}"/builds/}" | tr '/' '-')
82+
cp -av "${srcfile}" "${config_path}/${dstfile}.pkrvars.hcl.example" 2>&1 >/dev/null
83+
if [[ $? -ne 0 ]]; then
84+
echo "Error: Failed to copy ${srcfile} to ${config_path}/${dstfile}.pkrvars.hcl.example" >&2
85+
fi
7586
done
7687

77-
### Rename the example input variables.
78-
echo
79-
echo "> Renaming the example input variables..."
80-
for file in "${CONFIG_PATH}"/*.pkrvars.hcl.example; do
81-
mv -i -- "${file}" "${file%.example}"
88+
if [[ $? -ne 0 ]]; then
89+
echo "Error: One or more copy operations failed." >&2
90+
exit 1
91+
fi
92+
93+
for file in "${config_path}"/*.pkrvars.hcl.example; do
94+
if ! mv -- "${file}" "${file%.example}"; then
95+
echo "Error: Failed to rename ${file}" >&2
96+
exit 1
97+
fi
8298
done
8399

84-
echo
85-
echo "> Done."
100+
echo "> Configuration setup complete: ${config_path}"

docs/getting-started/get-project.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,19 @@ You can choose between two options to get the source code:
2727
=== ":octicons-repo-clone-24: &nbsp; Clone the Repository"
2828

2929
```shell
30-
TAG_NAME=$(curl -s https://api.github.com/repos/vmware-samples/packer-examples-for-vsphere/releases | jq -r '.[0].tag_name')
30+
TAG_NAME=$(curl -s https://api.github.com/repos/vmware-samples/packer-examples-for-vsphere/releases | jq -r '.[0].tag_name')
3131

32+
BRANCH_NAME="${TAG_NAME//\//-}"
33+
3234
git clone https://github.com/vmware-samples/packer-examples-for-vsphere.git
3335
cd packer-examples-for-vsphere
34-
git switch -c $TAG_NAME $TAG_NAME
36+
37+
if git switch -c "$BRANCH_NAME" "$TAG_NAME"; then
38+
echo "Switched to new branch: $BRANCH_NAME"
39+
else
40+
echo "Failed to switch to branch: $BRANCH_NAME"
41+
exit 1
42+
fi
3543
```
3644

3745
???+ tip "Prerelease Updates"

project.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"project": {
33
"name": "Packer Examples for vSphere",
4-
"version": "develop",
4+
"version": "v0.22.1",
55
"description": "This project provides a collection of opinionated examples that demonstrate how you can use both\nHashiCorp Packer and the Packer Plugin for VMware vSphere (vsphere-iso builder) to automate the\ncreation of virtual machine images for VMware vSphere environments.\n\nWhether you're a developer, systems administrator, or site reliability engineer, this project is\ndesigned to both help and inspire you in streamlining your infrastructure provisioning process and\nmaintain consistency in your virtualization workflow.",
66
"urls": {
77
"github": "https://github.com/vmware-samples/packer-examples-for-vsphere",
@@ -919,7 +919,7 @@
919919
"name": "Red Hat",
920920
"url": "https://redhat.com"
921921
},
922-
"version_requirement": ">= 2.16.0"
922+
"version_requirement": ">= 2.15.0"
923923
},
924924
{
925925
"name": "git",

0 commit comments

Comments
 (0)