@@ -12,7 +12,7 @@ set -eu -o pipefail
12
12
# - Use 'shopt -s inherit_errexit' (Bash 4.4+) to avoid repeated 'set -e' in all '$(...)'.
13
13
shopt -s inherit_errexit || error_exit " inherit_errexit not supported. Please use bash 4.4 or later."
14
14
15
- function almalinux_print_help () {
15
+ function almalinux_kitten_print_help () {
16
16
cat << HELP
17
17
$( basename " ${BASH_SOURCE[0]} " ) : Update the AlmaLinux Kitten image location in the specified templates
18
18
54
54
}
55
55
56
56
# print the URL spec for the given location
57
- function almalinux_url_spec_from_location () {
57
+ function almalinux_kitten_url_spec_from_location () {
58
58
local location=$1 jq_filter url_spec
59
59
jq_filter=' capture(
60
60
"^https://kitten\\.repo\\.almalinux\\.org/(?<path_version>\\d+)-kitten/cloud/(?<path_arch>[^/]+)/images/" +
@@ -69,35 +69,35 @@ function almalinux_url_spec_from_location() {
69
69
echo " ${url_spec} "
70
70
}
71
71
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)" '
74
74
75
75
# print the location for the given URL spec
76
- function almalinux_location_from_url_spec () {
76
+ function almalinux_kitten_location_from_url_spec () {
77
77
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} " ||
79
79
error_exit " Failed to get the location for ${url_spec} "
80
80
}
81
81
82
- function almalinux_image_directory_from_url_spec () {
82
+ function almalinux_kitten_image_directory_from_url_spec () {
83
83
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} " ||
85
85
error_exit " Failed to get the image directory for ${url_spec} "
86
86
}
87
87
88
- function almalinux_image_filename_from_url_spec () {
88
+ function almalinux_kitten_image_filename_from_url_spec () {
89
89
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} " ||
91
91
error_exit " Failed to get the image filename for ${url_spec} "
92
92
}
93
93
94
94
#
95
- function almalinux_latest_image_entry_for_url_spec () {
95
+ function almalinux_kitten_latest_image_entry_for_url_spec () {
96
96
local url_spec=$1 arch major_version_url_spec major_version_image_directory downloaded_page links_in_page latest_minor_version_info
97
97
arch=$( jq -r ' .arch' <<< " ${url_spec}" )
98
98
# to detect minor version updates, we need to get the major version URL
99
99
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} " )
101
101
downloaded_page=$( download_to_cache " ${major_version_image_directory} " )
102
102
if command -v htmlq >/dev/null; then
103
103
links_in_page=$( htmlq ' pre a' --attribute href < " ${downloaded_page} " )
@@ -122,34 +122,34 @@ function almalinux_latest_image_entry_for_url_spec() {
122
122
local newer_url_spec location directory checksum_location downloaded_sha256sum filename digest
123
123
# prefer the major_minor_version in the path
124
124
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} " )
127
127
checksum_location=" ${directory} CHECKSUM"
128
128
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} " )
130
130
digest=$( awk " /${filename} /{print \" sha256:\"\$ 1}" " ${downloaded_sha256sum} " )
131
131
[[ -n ${digest} ]] || error_exit " Failed to get the SHA256 digest for ${filename} "
132
132
json_vars location arch digest
133
133
}
134
134
135
- function almalinux_cache_key_for_image_kernel () {
135
+ function almalinux_kitten_cache_key_for_image_kernel () {
136
136
local location=$1 url_spec
137
- url_spec=$( almalinux_url_spec_from_location " ${location} " )
137
+ url_spec=$( almalinux_kitten_url_spec_from_location " ${location} " )
138
138
jq -r '[" almalinux-kitten" , .major_minor_version // .major_version, .target_vendor,
139
139
if .date then " timestamped" else " latest" end,
140
140
.arch, .file_extension] | join(" :" )' <<<" ${url_spec} "
141
141
}
142
142
143
- function almalinux_image_entry_for_image_kernel () {
143
+ function almalinux_kitten_image_entry_for_image_kernel () {
144
144
local location=$1 kernel_is_not_supported=$2 overriding=${3:- " {}" } url_spec image_entry=''
145
145
[[ ${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} " )
147
147
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} " )
149
149
else
150
150
image_entry=$(
151
151
# shellcheck disable=SC2030
152
- location=$( almalinux_location_from_url_spec " ${url_spec} " )
152
+ location=$( almalinux_kitten_location_from_url_spec " ${url_spec} " )
153
153
location=$( validate_url_without_redirect " ${location} " )
154
154
arch=$( jq -r ' .path_arch' <<< " ${url_spec}" )
155
155
json_vars location arch
@@ -194,7 +194,7 @@ declare overriding="{}"
194
194
while [[ $# -gt 0 ]]; do
195
195
case " $1 " in
196
196
-h | --help)
197
- almalinux_print_help
197
+ almalinux_kitten_print_help
198
198
exit 0
199
199
;;
200
200
-d | --debug) set -x ;;
@@ -232,7 +232,7 @@ while [[ $# -gt 0 ]]; do
232
232
done
233
233
234
234
if [[ ${# templates[@]} -eq 0 ]]; then
235
- almalinux_print_help
235
+ almalinux_kitten_print_help
236
236
exit 0
237
237
fi
238
238
@@ -257,7 +257,7 @@ for template in "${templates[@]}"; do
257
257
set +e # Disable 'set -e' to avoid exiting on error for the next assignment.
258
258
cache_key=$(
259
259
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} "
261
261
) # Check exit status separately to prevent disabling 'set -e' by using the function call in the condition.
262
262
# shellcheck disable=2181
263
263
[[ $? -eq 0 ]] || continue
@@ -266,7 +266,7 @@ for template in "${templates[@]}"; do
266
266
if [[ -v image_entry_cache[${cache_key} ] ]]; then
267
267
echo " ${image_entry_cache[${cache_key}]} "
268
268
else
269
- almalinux_image_entry_for_image_kernel " ${location} " " ${kernel_location} " " ${overriding} "
269
+ almalinux_kitten_image_entry_for_image_kernel " ${location} " " ${kernel_location} " " ${overriding} "
270
270
fi
271
271
) # Check exit status separately to prevent disabling 'set -e' by using the function call in the condition.
272
272
# shellcheck disable=2181
0 commit comments