summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMorten Linderud <foxboron@archlinux.org>2021-12-25 15:05:48 +0100
committerLevente Polyak <anthraxx@archlinux.org>2022-01-26 21:31:32 +0100
commit39a99e1664ea196d31ccec5bf35c473ff74efe74 (patch)
tree0c1657a06fd81c22fb634f26e52514a05c78d8f1 /lib
parent95d06e0f6056c3fcff87e048468318389786f0b8 (diff)
downloaddevtools-39a99e1664ea196d31ccec5bf35c473ff74efe74.tar.xz
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 <foxboron@archlinux.org> Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/common.sh57
1 files changed, 57 insertions, 0 deletions
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}" ]]
+}