From 39a99e1664ea196d31ccec5bf35c473ff74efe74 Mon Sep 17 00:00:00 2001 From: Morten Linderud Date: Sat, 25 Dec 2021 15:05:48 +0100 Subject: common: Implement helper functions from dbscripts This implements our current debug package detection logic. Mostly taken from our dbscripts project. Signed-off-by: Morten Linderud Signed-off-by: Levente Polyak --- lib/common.sh | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'lib') diff --git a/lib/common.sh b/lib/common.sh index a3f2f26..0996247 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -202,3 +202,60 @@ check_package_validity(){ die "PKGBUILD $hashsum mismatch: expected $pkgbuild_hash" fi } + + +# usage: grep_pkginfo pkgfile pattern +grep_pkginfo() { + local _ret=() + mapfile -t _ret < <(bsdtar -xOqf "$1" ".PKGINFO" | grep "^${2} = ") + printf '%s\n' "${_ret[@]#${2} = }" +} + + +# Get the package name +getpkgname() { + local _name + + _name="$(grep_pkginfo "$1" "pkgname")" + if [[ -z $_name ]]; then + error "Package '%s' has no pkgname in the PKGINFO. Fail!" "$1" + exit 1 + fi + + echo "$_name" +} + + +# Get the package base or name as fallback +getpkgbase() { + local _base + + _base="$(grep_pkginfo "$1" "pkgbase")" + if [[ -z $_base ]]; then + getpkgname "$1" + else + echo "$_base" + fi +} + + +getpkgdesc() { + local _desc + + _desc="$(grep_pkginfo "$1" "pkgdesc")" + if [[ -z $_desc ]]; then + error "Package '%s' has no pkgdesc in the PKGINFO. Fail!" "$1" + exit 1 + fi + + echo "$_desc" +} + + +is_debug_package() { + local pkgfile=${1} pkgbase pkgname pkgdesc + pkgbase="$(getpkgbase "${pkgfile}")" + pkgname="$(getpkgname "${pkgfile}")" + pkgdesc="$(getpkgdesc "${pkgfile}")" + [[ ${pkgdesc} == "Detached debugging symbols for "* && ${pkgbase}-debug = "${pkgname}" ]] +} -- cgit v1.2.3-70-g09d2