Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apt-utils.sh: get base-files package version from GHA #7473

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 19 additions & 26 deletions lib/functions/general/apt-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,22 @@
function apt_find_upstream_package_version_and_download_url() {
declare sought_package_name="${1}"

declare -a package_info_download_urls=()
declare first_letter_of_sought_package_name="${sought_package_name:0:1}"
declare mirror_with_slash="undetermined/"

case "${DISTRIBUTION}" in
Ubuntu)
# Only LTS releases have an "-updates" repo that is worth looking into
if [[ "${RELEASE}" == "focal" || "${RELEASE}" == "jammy" ]]; then # @TODO: release info information, is_ubuntu_release_lts() or similar
package_info_download_urls+=("https://packages.ubuntu.com/${RELEASE}-updates/${ARCH}/${sought_package_name}/download")
package_download_release=${RELEASE}-updates
else
package_info_download_urls+=("https://packages.ubuntu.com/${RELEASE}/${ARCH}/${sought_package_name}/download")
package_download_release=${RELEASE}
fi
mirror_with_slash="${UBUNTU_MIRROR}"
;;

Debian)
package_info_download_urls+=("https://packages.debian.org/${RELEASE}/${ARCH}/${sought_package_name}/download")
package_download_release=${RELEASE}
mirror_with_slash="${DEBIAN_MIRROR}"
;;

Expand All @@ -41,35 +40,29 @@ function apt_find_upstream_package_version_and_download_url() {

declare base_down_url="http://${mirror_with_slash}pool/main/${first_letter_of_sought_package_name}/${sought_package_name}"

declare index package_info_download_url
# loop over the package_info_download_urls with index and value
for index in "${!package_info_download_urls[@]}"; do
package_info_download_url="${package_info_download_urls[$index]}"
display_alert "Testing URL" "${package_info_download_url}" "debug"

declare package_info_download_url_file
package_info_download_url_file="$(mktemp)"
curl --silent --show-error --max-time 10 "${package_info_download_url}" > "${package_info_download_url_file}" || true # don't fail
declare package_info_download_url_file_package_name # grep the file for the package name. parse "<kbd>name</kbd>"
package_info_download_url_file_package_name="$(grep -oP '(?<=<kbd>)[^<]+' "${package_info_download_url_file}" | grep "^${sought_package_name}_" | head -n 1)"
rm -f "${package_info_download_url_file}"

display_alert "Package name parsed" "${package_info_download_url_file_package_name}" "debug"
if [[ "${package_info_download_url_file_package_name}" == "${sought_package_name}_"* ]]; then
found_package_filename="${package_info_download_url_file_package_name}"
found_package_down_url="${base_down_url}/${found_package_filename}"
display_alert "Found package filename" "${found_package_filename} in url ${package_info_download_url}" "debug"
break
fi
done
# get json with latest pacakge info generated by GHA
case "${GITHUB_MIRROR}" in
"ghproxy")
package_info_download_url="https://ghp.ci/https://raw.githubusercontent.com/armbian/armbian.github.io/refs/heads/data/data/${sought_package_name}.json"
igorpecovnik marked this conversation as resolved.
Show resolved Hide resolved
;;
*)
package_info_download_url="https://github.armbian.com/${sought_package_name}.json"
;;
esac
package_info_download_url_file="$(mktemp)"
curl --silent --show-error --max-time 10 $package_info_download_url -o $package_info_download_url_file
found_package_filename=$(jq -r .[\"${package_download_release}\"].${ARCH} $package_info_download_url_file)

if [[ "${found_package_filename}" == "${sought_package_name}_"* ]]; then
display_alert "Found upstream base-files package filename" "${found_package_filename}" "info"
else
display_alert "Could not find package filename for '${sought_package_name}' in '${package_info_download_urls[*]}'" "looking for ${sought_package_name}" "warn"
display_alert "Could not find package filename for '${sought_package_name}' in distro repo" "looking for ${sought_package_name}, found_package_filename is ${found_package_filename}" "warn"
return 1
fi

found_package_down_url="${base_down_url}/${found_package_filename}"
display_alert "Found package filename" "${found_package_filename} in url ${found_package_down_url}" "debug"

# Now we have the package name, lets parse out the version.
found_package_version="$(echo "${found_package_filename}" | grep -oP '(?<=_)[^_]+(?=_)')"
display_alert "Found base-files upstream package version" "${found_package_version}" "info"
Expand Down
Loading