From d0386030626fda74e6dd370fcd3157c4d93501af Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 9 Jul 2009 17:24:15 +0200 Subject: Read meta data from .PKGINFO instead of filename Prefer pkgbase over pkgname in getpkgbase() Signed-off-by: Aaron Griffin --- db-functions | 46 +++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) (limited to 'db-functions') diff --git a/db-functions b/db-functions index 966a713..11ef8e7 100644 --- a/db-functions +++ b/db-functions @@ -54,32 +54,48 @@ repo_unlock () { #repo_unlock repo-name arch restore_umask } -# Get the package name from the filename -# hackish, but should work for now +# Get the package base or name +getpkgbase() { + local _base + + _base="$(/usr/bin/bsdtar -xOqf "$1" .PKGINFO | sort | /bin/grep -m 1 -E "^pkg(base|name)" | /bin/sed 's|\w*\s*=\s*\(.*\)|\1|')" + if [ -z "$_base" ]; then + echo "ERROR: Package '$1' has no pkgbase or pkgname in the PKGINFO. Fail!" + exit 1 + fi + + echo "$_base" +} + +# Get the package name getpkgname() { - local tmp + local _name - tmp=${1##*/} - tmp=${tmp%$PKGEXT} - tmp=${tmp%$SRCEXT} - tmp=${tmp%-$CARCH} - echo ${tmp%-*-*} + _name="$(/usr/bin/bsdtar -xOqf "$1" .PKGINFO | /bin/grep -m 1 "^pkgname" | /bin/sed 's|\w*\s*=\s*\(.*\)|\1|')" + if [ -z "$_name" ]; then + echo "ERROR: Package '$1' has no pkgname in the PKGINFO. Fail!" + exit 1 + fi + + echo "$_name" } # Get the pkgver-pkgrel of this package getpkgver() { - local tmp + local _ver + + _ver="$(/usr/bin/bsdtar -xOqf "$1" .PKGINFO | /bin/grep -m 1 "^pkgver" | /bin/sed 's|\w*\s*=\s*\(.*\)|\1|')" + if [ -z "$_ver" ]; then + echo "ERROR: Package '$1' has no pkgver in the PKGINFO. Fail!" + exit 1 + fi - tmp=${1##*/} - tmp=${tmp%$PKGEXT} - tmp=${tmp%$SRCEXT} - tmp=${tmp%-$CARCH} - echo $tmp | sed 's|.*-\(.*-.*\)$|\1|g' + echo "$_ver" } check_pkg_arch () { #check_pkg_arch pkgfile arch local _arch - _arch="$(/usr/bin/bsdtar -xOqf "$1" .PKGINFO | /bin/grep "^arch" | /bin/sed 's|\w*\s*=\s*\(.*\)|\1|')" + _arch="$(/usr/bin/bsdtar -xOqf "$1" .PKGINFO | /bin/grep -m 1 "^arch" | /bin/sed 's|\w*\s*=\s*\(.*\)|\1|')" if [ -z "$_arch" ]; then echo "ERROR: Package '$1' has no arch in the PKGINFO. Fail!" -- cgit v1.2.3-24-g4f1b