Skip to content

Commit

Permalink
Merge duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
ophub committed Jul 2, 2023
1 parent 489101d commit 4081445
Showing 1 changed file with 14 additions and 23 deletions.
37 changes: 14 additions & 23 deletions rebuild
Original file line number Diff line number Diff line change
Expand Up @@ -378,36 +378,27 @@ query_kernel() {
# Identify the kernel <VERSION> and <PATCHLEVEL>, such as [ 6.1 ]
kernel_verpatch="$(echo ${kernel_var} | awk -F '.' '{print $1"."$2}')"

if [[ -n "${gh_token}" ]]; then
latest_version="$(
curl -s \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${gh_token}" \
${kernel_api}/releases/tags/kernel_${kd} |
jq -r '.assets[].name' |
grep -oE "${kernel_verpatch}\.[0-9]+" |
sort -rV | head -n 1
)"
query_api="Authenticated user request"
else
latest_version="$(
curl -s \
-H "Accept: application/vnd.github+json" \
${kernel_api}/releases/tags/kernel_${kd} |
jq -r '.assets[].name' |
grep -oE "${kernel_verpatch}\.[0-9]+" |
sort -rV | head -n 1
)"
query_api="Unauthenticated user request"
fi
# Set the token for api.github.com
[[ -n "${gh_token}" ]] && ght="-H \"Authorization: Bearer ${gh_token}\"" || ght=""

# Query the latest kernel version
latest_version="$(
curl -s \
-H "Accept: application/vnd.github+json" \
${ght} \
${kernel_api}/releases/tags/kernel_${kd} |
jq -r '.assets[].name' |
grep -oE "${kernel_verpatch}\.[0-9]+" |
sort -rV | head -n 1
)"

if [[ "${?}" -eq "0" && -n "${latest_version}" ]]; then
tmp_arr_kernels[${i}]="${latest_version}"
else
tmp_arr_kernels[${i}]="${kernel_var}"
fi

echo -e "${INFO} (${x}.${i}) [ ${k} - ${tmp_arr_kernels[$i]} ] is latest kernel (${query_api}). \n"
echo -e "${INFO} (${x}.${i}) [ ${k} - ${tmp_arr_kernels[$i]} ] is latest kernel. \n"

let i++
done
Expand Down

0 comments on commit 4081445

Please sign in to comment.