Skip to content

Commit

Permalink
common: Implement helper functions from dbscripts
Browse files Browse the repository at this point in the history
This implements our current debug package detection logic.
Mostly taken from our dbscripts project.
  • Loading branch information
Foxboron committed Dec 25, 2021
1 parent c731789 commit 72761b9
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions lib/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,57 @@ check_package_validity(){
die "PKGBUILD $hashsum mismatch: expected $pkgbuild_hash"
fi
}


# usage: _grep_pkginfo pkgfile pattern _grep_pkginfo() { local _ret=() mapfile -t _ret < <(/usr/bin/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}
local pkgbase="$(getpkgbase "${pkgfile}")"
local pkgname="$(getpkgname "${pkgfile}")"
local pkgdesc="$(getpkgdesc "${pkgfile}")"
[[ ${pkgdesc} == "Detached debugging symbols for "* && ${pkgbase}-debug = ${pkgname} ]]
}

0 comments on commit 72761b9

Please sign in to comment.