2023-05-12 16:11:51 +00:00
#
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2023 Ricardo Pardini <ricardo@pardini.net>
# This file is a part of the Armbian Build Framework https://github.com/armbian/build/
#
# tl;dr: this function will return the version and download URL of a package.
# it is very naive, and will only look into a few repos across Debian/Ubuntu.
function apt_find_upstream_package_version_and_download_url( ) {
declare sought_package_name = " ${ 1 } "
declare first_letter_of_sought_package_name = " ${ sought_package_name : 0 : 1 } "
declare mirror_with_slash = "undetermined/"
case " ${ DISTRIBUTION } " in
2023-10-20 11:56:48 +00:00
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
2024-11-14 09:06:40 +00:00
package_download_release = ${ RELEASE } -updates
2023-10-20 11:56:48 +00:00
else
2024-11-14 09:06:40 +00:00
package_download_release = ${ RELEASE }
2023-10-20 11:56:48 +00:00
fi
2023-05-12 16:11:51 +00:00
mirror_with_slash = " ${ UBUNTU_MIRROR } "
; ;
Debian)
2024-11-14 09:06:40 +00:00
package_download_release = ${ RELEASE }
2023-05-12 16:11:51 +00:00
mirror_with_slash = " ${ DEBIAN_MIRROR } "
; ;
*)
exit_with_error " Unknown distribution ' ${ DISTRIBUTION } ' "
; ;
esac
# if mirror_with_slash does not end with a slash, add it
if [ [ " ${ mirror_with_slash } " != */ ] ] ; then
mirror_with_slash = " ${ mirror_with_slash } / "
fi
2023-08-16 14:37:20 +00:00
declare base_down_url = " http:// ${ mirror_with_slash } pool/main/ ${ first_letter_of_sought_package_name } / ${ sought_package_name } "
2023-05-12 16:11:51 +00:00
2024-11-14 09:06:40 +00:00
# get json with latest pacakge info generated by GHA
case " ${ GITHUB_MIRROR } " in
"ghproxy" )
2024-12-18 03:52:34 +00:00
package_info_download_url = " https:// ${ GHPROXY_ADDRESS } /https://raw.githubusercontent.com/armbian/armbian.github.io/refs/heads/data/data/ ${ sought_package_name } .json "
2024-11-14 09:06:40 +00:00
; ;
*)
2024-11-14 17:06:42 +00:00
package_info_download_url = " https://github.armbian.com/ ${ sought_package_name } .json "
2024-11-14 09:06:40 +00:00
; ;
esac
package_info_download_url_file = " $( mktemp) "
curl --silent --show-error --max-time 10 $package_info_download_url -o $package_info_download_url_file
2025-04-17 15:58:50 +00:00
found_package_filename = $(
jq -r --arg release " ${ package_download_release } " --arg arch " ${ ARCH } " \
'.[$release][$arch]' $package_info_download_url_file
)
2023-05-12 16:11:51 +00:00
if [ [ " ${ found_package_filename } " = = " ${ sought_package_name } _ " * ] ] ; then
display_alert "Found upstream base-files package filename" " ${ found_package_filename } " "info"
else
2024-11-14 09:06:40 +00:00
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"
2023-05-12 16:11:51 +00:00
return 1
fi
2024-11-14 09:06:40 +00:00
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"
2023-05-12 16:11:51 +00:00
# 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"
# Sanity check...
declare wanted_package_name = " ${ sought_package_name } _ ${ found_package_version } _ ${ ARCH } .deb "
if [ [ " ${ found_package_filename } " != " ${ wanted_package_name } " ] ] ; then
display_alert " Found package filename ' ${ found_package_filename } ' does not match wanted package name ' ${ wanted_package_name } ' " " looking for ${ sought_package_name } " "warn"
return 1
fi
# show found_package_down_url
display_alert "Found package download url" " ${ found_package_down_url } " "debug"
return 0
}