diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2010-04-10 02:33:02 +0200 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2010-04-10 02:33:02 +0200 |
commit | ce1d818e401e640dea188926ab66b7113d0c067f (patch) | |
tree | 7a3795071fb62ca62700a11a845cebe06f16214a /getpkgbase | |
download | repo-tools-ce1d818e401e640dea188926ab66b7113d0c067f.tar.gz repo-tools-ce1d818e401e640dea188926ab66b7113d0c067f.tar.xz |
initial commit
Diffstat (limited to 'getpkgbase')
-rwxr-xr-x | getpkgbase | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/getpkgbase b/getpkgbase new file mode 100755 index 0000000..2206a08 --- /dev/null +++ b/getpkgbase @@ -0,0 +1,43 @@ +#!/bin/bash + +# usage: _grep_pkginfo pkgfile pattern +_grep_pkginfo() { + local _ret + + _ret="$(/usr/bin/bsdtar -xOqf "$1" .PKGINFO | /bin/grep -m 1 -E "$2" | /bin/sed 's|\w*\s*=\s*\(.*\)|\1|')" + echo "$_ret" +} + +# Get the package name +getpkgname() { + local _name + + _name="$(_grep_pkginfo "$1" "^pkgname")" + if [ -z "$_name" ]; then + echo "ERROR: Package '$1' has no pkgname in the PKGINFO. Fail!" >&2 + 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" + return 0 + fi + + echo "$_base" +} + + +if [ $# -ne 1 ]; then + echo "usage: $(basename $0) <pkgfile>" + exit 1 +fi + +getpkgbase "${1}" |