Skip to content

Commit 52ac972

Browse files
committed
Use unique function and variable names for update-template-almalinux-kitten.sh
All the update-template-* are sourced into update-template.sh, so they must all use unique names that don't conflict with each other. The almalinux-kitten script was a copy of the almalinux script and reused the variable and function names. Signed-off-by: Jan Dubois <jan.dubois@suse.com>
1 parent 1435079 commit 52ac972

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

hack/update-template-almalinux-kitten.sh

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ set -eu -o pipefail
1212
# - Use 'shopt -s inherit_errexit' (Bash 4.4+) to avoid repeated 'set -e' in all '$(...)'.
1313
shopt -s inherit_errexit || error_exit "inherit_errexit not supported. Please use bash 4.4 or later."
1414

15-
function almalinux_print_help() {
15+
function almalinux_kitten_print_help() {
1616
cat <<HELP
1717
$(basename "${BASH_SOURCE[0]}"): Update the AlmaLinux Kitten image location in the specified templates
1818
@@ -54,7 +54,7 @@ HELP
5454
}
5555

5656
# print the URL spec for the given location
57-
function almalinux_url_spec_from_location() {
57+
function almalinux_kitten_url_spec_from_location() {
5858
local location=$1 jq_filter url_spec
5959
jq_filter='capture(
6060
"^https://kitten\\.repo\\.almalinux\\.org/(?<path_version>\\d+)-kitten/cloud/(?<path_arch>[^/]+)/images/" +
@@ -69,35 +69,35 @@ function almalinux_url_spec_from_location() {
6969
echo "${url_spec}"
7070
}
7171
72-
readonly almalinux_jq_filter_directory='"https://kitten.repo.almalinux.org/\(.path_version)-kitten/cloud/\(.path_arch)/images/"'
73-
readonly almalinux_jq_filter_filename='"AlmaLinux-Kitten-\(.target_vendor)-\(.major_version)-\(if .date then .date + ".0" else "latest" end).\(.arch).\(.file_extension)"'
72+
readonly almalinux_kitten_jq_filter_directory='"https://kitten.repo.almalinux.org/\(.path_version)-kitten/cloud/\(.path_arch)/images/"'
73+
readonly almalinux_kitten_jq_filter_filename='"AlmaLinux-Kitten-\(.target_vendor)-\(.major_version)-\(if .date then .date + ".0" else "latest" end).\(.arch).\(.file_extension)"'
7474
7575
# print the location for the given URL spec
76-
function almalinux_location_from_url_spec() {
76+
function almalinux_kitten_location_from_url_spec() {
7777
local -r url_spec=$1
78-
jq -e -r "${almalinux_jq_filter_directory} + ${almalinux_jq_filter_filename}" <<<"${url_spec}" ||
78+
jq -e -r "${almalinux_kitten_jq_filter_directory} + ${almalinux_kitten_jq_filter_filename}" <<<"${url_spec}" ||
7979
error_exit "Failed to get the location for ${url_spec}"
8080
}
8181
82-
function almalinux_image_directory_from_url_spec() {
82+
function almalinux_kitten_image_directory_from_url_spec() {
8383
local -r url_spec=$1
84-
jq -e -r "${almalinux_jq_filter_directory}" <<<"${url_spec}" ||
84+
jq -e -r "${almalinux_kitten_jq_filter_directory}" <<<"${url_spec}" ||
8585
error_exit "Failed to get the image directory for ${url_spec}"
8686
}
8787
88-
function almalinux_image_filename_from_url_spec() {
88+
function almalinux_kitten_image_filename_from_url_spec() {
8989
local -r url_spec=$1
90-
jq -e -r "${almalinux_jq_filter_filename}" <<<"${url_spec}" ||
90+
jq -e -r "${almalinux_kitten_jq_filter_filename}" <<<"${url_spec}" ||
9191
error_exit "Failed to get the image filename for ${url_spec}"
9292
}
9393
9494
#
95-
function almalinux_latest_image_entry_for_url_spec() {
95+
function almalinux_kitten_latest_image_entry_for_url_spec() {
9696
local url_spec=$1 arch major_version_url_spec major_version_image_directory downloaded_page links_in_page latest_minor_version_info
9797
arch=$(jq -r '.arch' <<<"${url_spec}")
9898
# to detect minor version updates, we need to get the major version URL
9999
major_version_url_spec=$(jq -e -r '.path_version = .major_version' <<<"${url_spec}")
100-
major_version_image_directory=$(almalinux_image_directory_from_url_spec "${major_version_url_spec}")
100+
major_version_image_directory=$(almalinux_kitten_image_directory_from_url_spec "${major_version_url_spec}")
101101
downloaded_page=$(download_to_cache "${major_version_image_directory}")
102102
if command -v htmlq >/dev/null; then
103103
links_in_page=$(htmlq 'pre a' --attribute href <"${downloaded_page}")
@@ -122,34 +122,34 @@ function almalinux_latest_image_entry_for_url_spec() {
122122
local newer_url_spec location directory checksum_location downloaded_sha256sum filename digest
123123
# prefer the major_minor_version in the path
124124
newer_url_spec=$(jq -e -r ". + ${latest_minor_version_info} | .path_version = .major_minor_version" <<<"${url_spec}")
125-
location=$(almalinux_location_from_url_spec "${newer_url_spec}")
126-
directory=$(almalinux_image_directory_from_url_spec "${newer_url_spec}")
125+
location=$(almalinux_kitten_location_from_url_spec "${newer_url_spec}")
126+
directory=$(almalinux_kitten_image_directory_from_url_spec "${newer_url_spec}")
127127
checksum_location="${directory}CHECKSUM"
128128
downloaded_sha256sum=$(download_to_cache "${checksum_location}")
129-
filename=$(almalinux_image_filename_from_url_spec "${newer_url_spec}")
129+
filename=$(almalinux_kitten_image_filename_from_url_spec "${newer_url_spec}")
130130
digest=$(awk "/${filename}/{print \"sha256:\"\$1}" "${downloaded_sha256sum}")
131131
[[ -n ${digest} ]] || error_exit "Failed to get the SHA256 digest for ${filename}"
132132
json_vars location arch digest
133133
}
134134
135-
function almalinux_cache_key_for_image_kernel() {
135+
function almalinux_kitten_cache_key_for_image_kernel() {
136136
local location=$1 url_spec
137-
url_spec=$(almalinux_url_spec_from_location "${location}")
137+
url_spec=$(almalinux_kitten_url_spec_from_location "${location}")
138138
jq -r '["almalinux-kitten", .major_minor_version // .major_version, .target_vendor,
139139
if .date then "timestamped" else "latest" end,
140140
.arch, .file_extension] | join(":")' <<<"${url_spec}"
141141
}
142142
143-
function almalinux_image_entry_for_image_kernel() {
143+
function almalinux_kitten_image_entry_for_image_kernel() {
144144
local location=$1 kernel_is_not_supported=$2 overriding=${3:-"{}"} url_spec image_entry=''
145145
[[ ${kernel_is_not_supported} == "null" ]] || echo "Updating kernel information is not supported on AlmaLinux Kitten" >&2
146-
url_spec=$(almalinux_url_spec_from_location "${location}" | jq -r ". + ${overriding}")
146+
url_spec=$(almalinux_kitten_url_spec_from_location "${location}" | jq -r ". + ${overriding}")
147147
if jq -e '.date' <<<"${url_spec}" >/dev/null; then
148-
image_entry=$(almalinux_latest_image_entry_for_url_spec "${url_spec}")
148+
image_entry=$(almalinux_kitten_latest_image_entry_for_url_spec "${url_spec}")
149149
else
150150
image_entry=$(
151151
# shellcheck disable=SC2030
152-
location=$(almalinux_location_from_url_spec "${url_spec}")
152+
location=$(almalinux_kitten_location_from_url_spec "${url_spec}")
153153
location=$(validate_url_without_redirect "${location}")
154154
arch=$(jq -r '.path_arch' <<<"${url_spec}")
155155
json_vars location arch
@@ -194,7 +194,7 @@ declare overriding="{}"
194194
while [[ $# -gt 0 ]]; do
195195
case "$1" in
196196
-h | --help)
197-
almalinux_print_help
197+
almalinux_kitten_print_help
198198
exit 0
199199
;;
200200
-d | --debug) set -x ;;
@@ -232,7 +232,7 @@ while [[ $# -gt 0 ]]; do
232232
done
233233
234234
if [[ ${#templates[@]} -eq 0 ]]; then
235-
almalinux_print_help
235+
almalinux_kitten_print_help
236236
exit 0
237237
fi
238238
@@ -257,7 +257,7 @@ for template in "${templates[@]}"; do
257257
set +e # Disable 'set -e' to avoid exiting on error for the next assignment.
258258
cache_key=$(
259259
set -e # Enable 'set -e' for the next command.
260-
almalinux_cache_key_for_image_kernel "${location}" "${kernel_location}"
260+
almalinux_kitten_cache_key_for_image_kernel "${location}" "${kernel_location}"
261261
) # Check exit status separately to prevent disabling 'set -e' by using the function call in the condition.
262262
# shellcheck disable=2181
263263
[[ $? -eq 0 ]] || continue
@@ -266,7 +266,7 @@ for template in "${templates[@]}"; do
266266
if [[ -v image_entry_cache[${cache_key}] ]]; then
267267
echo "${image_entry_cache[${cache_key}]}"
268268
else
269-
almalinux_image_entry_for_image_kernel "${location}" "${kernel_location}" "${overriding}"
269+
almalinux_kitten_image_entry_for_image_kernel "${location}" "${kernel_location}" "${overriding}"
270270
fi
271271
) # Check exit status separately to prevent disabling 'set -e' by using the function call in the condition.
272272
# shellcheck disable=2181

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy