Skip to content

Commit af5fe6b

Browse files
committed
update-template-alpine.sh: improve --version-major-minor parameter validation
also add mention about `latest-stable` on `--version-major-minor` Signed-off-by: Norio Nomura <[email protected]>
1 parent 22dfeda commit af5fe6b

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

hack/update-template-alpine.sh

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function alpine_print_help() {
1414
$(basename "${BASH_SOURCE[0]}"): Update the Alpine Linux image location in the specified templates
1515
1616
Usage:
17-
$(basename "${BASH_SOURCE[0]}") [--version-major-minor <major>.<minor>] <template.yaml>...
17+
$(basename "${BASH_SOURCE[0]}") [--version-major-minor (<major>.<minor>|latest-stable)] <template.yaml>...
1818
1919
Description:
2020
This script updates the Alpine Linux image location in the specified templates.
@@ -39,9 +39,9 @@ Examples:
3939
$ limactl factory-reset alpine
4040
4141
Flags:
42-
--version-major-minor <major>.<minor> Use the specified <major>.<minor> version.
43-
The version must be 3.18 or later.
44-
-h, --help Print this help message
42+
--version-major-minor (<major>.<minor>|latest-stable) Use the specified <major>.<minor> version or alias "latest-stable".
43+
The <major>.<minor> version must be 3.18 or later.
44+
-h, --help Print this help message
4545
HELP
4646
}
4747

@@ -178,30 +178,27 @@ while [[ $# -gt 0 ]]; do
178178
;;
179179
-d | --debug) set -x ;;
180180
--version-major-minor)
181-
if [[ -n $2 && $2 != -* ]]; then
182-
overriding=$(
183-
version="${2#v}"
184-
[[ ${version} == "latest-stable" ]] && exit
185-
version="$(echo "${version}" | cut -d. -f1-2)"
186-
[[ ${version%%.*} -gt 3 || (${version%%.*} -eq 3 && ${version#*.} -ge 18) ]] || error_exit "Alpine Linux version must be 3.18 or later"
187-
# shellcheck disable=2034
188-
path_version="v${version}"
189-
json_vars path_version <<<"${overriding}"
190-
)
181+
if [[ -n ${2:-} && $2 != -* ]]; then
182+
version="$2"
191183
shift
192184
else
193-
error_exit "--version requires a value"
185+
error_exit "--version-major-minor requires a value"
194186
fi
195-
;;
187+
;&
196188
--version-major-minor=*)
189+
version=${version:-${1#*=}}
197190
overriding=$(
198-
version="${1#*=}"
199191
version="${version#v}"
200-
[[ ${version} == "latest-stable" ]] && exit
201-
version="$(echo "${version}" | cut -d. -f1-2)"
202-
[[ ${version%%.*} -gt 3 || (${version%%.*} -eq 3 && ${version#*.} -ge 18) ]] || error_exit "Alpine Linux version must be 3.18 or later"
192+
if [[ ${version} =~ ^v?[0-9]+.[0-9]+ ]]; then
193+
version="$(echo "${version}" | cut -d. -f1-2)"
194+
[[ ${version%%.*} -gt 3 || (${version%%.*} -eq 3 && ${version#*.} -ge 18) ]] || error_exit "Alpine Linux version must be 3.18 or later"
195+
path_version="v${version}"
196+
elif [[ ${version} == "latest-stable" ]]; then
197+
path_version="latest-stable"
198+
else
199+
error_exit "--version-major-minor requires a value in the format <major>.<minor> or latest-stable"
200+
fi
203201
# shellcheck disable=2034
204-
path_version="v${version}"
205202
json_vars path_version <<<"${overriding}"
206203
)
207204
;;

0 commit comments

Comments
 (0)