@@ -36,12 +36,17 @@ readonly yq_filter="
36
36
parsed=$( yq eval " ${yq_filter} " " ${template} " )
37
37
38
38
# 3. get the image location
39
+ function check_location() {
40
+ local location=$1 http_code
41
+ http_code=$( curl -sIL -w " %{http_code}" " ${location} " -o /dev/null)
42
+ [[ ${http_code} -eq 200 ]]
43
+ }
39
44
while IFS= read -r line; do arr+=(" ${line} " ); done <<< " ${parsed}"
40
45
readonly locations=(" ${arr[@]} " )
41
46
for (( i = 0 ; i < ${# locations[@]} ; i++ )) ; do
42
47
[[ ${locations[i]} != " null" ]] || continue
43
- http_code= $( curl -sIL -w " %{http_code} " " ${locations[i]} " -o /dev/null )
44
- if [[ ${http_code} -eq 200 ]] ; then
48
+ # shellcheck disable=SC2310
49
+ if check_location " ${locations[i]} " ; then
45
50
location=${locations[i]}
46
51
index=${i}
47
52
break
@@ -78,14 +83,18 @@ initrd_digest=$(awk "/${initrd_basename}/{print \"sha256:\"\$1}" <<<"${sha256sum
78
83
initrd_location=" ${location_dirname} /${initrd_basename} "
79
84
80
85
# 6. inject the kernel and initrd location, digest, and cmdline to the template
81
- yq -i eval "
82
- [(.images.[] | select(.arch == \" ${arch} \" ) | path)].[${index} ] + \" kernel\" as \$ path|
83
- setpath(\$ path; { \" location\" : \" ${kernel_location} \" , \" digest\" : \" ${kernel_digest} \" , \" cmdline\" : \" ${cmdline} \" })
84
- " " ${template} "
85
- yq -i eval "
86
- [(.images.[] | select(.arch == \" ${arch} \" ) | path)].[${index} ] + \" initrd\" as \$ path|
87
- setpath(\$ path ; { \" location\" : \" ${initrd_location} \" , \" digest\" : \" ${initrd_digest} \" })
88
- " " ${template} "
86
+ function inject_to() {
87
+ # shellcheck disable=SC2034
88
+ local template=$1 arch=$2 index=$3 key=$4 location=$5 digest=$6 cmdline=${7:- } fields=() IFS=,
89
+ # shellcheck disable=SC2310
90
+ check_location " ${location} " || return 0
91
+ for field_name in location digest cmdline; do
92
+ [[ -z ${! field_name} ]] || fields+=(" \" ${field_name} \" : \" ${! field_name} \" " )
93
+ done
94
+ yq -i -I 2 eval " setpath([(.images[] | select(.arch == \" ${arch} \" ) | path)].[${index} ] + \" ${key} \" ; { ${fields[*]} })" " ${template} "
95
+ }
96
+ inject_to " ${template} " " ${arch} " " ${index} " " kernel" " ${kernel_location} " " ${kernel_digest} " " ${cmdline} "
97
+ inject_to " ${template} " " ${arch} " " ${index} " " initrd" " ${initrd_location} " " ${initrd_digest} "
89
98
90
99
# 7. output kernel_location, kernel_digest, cmdline, initrd_location, initrd_digest
91
100
readonly outputs=(kernel_location kernel_digest cmdline initrd_location initrd_digest)
0 commit comments