diff options
author | Aaron Griffin <aaronmgriffin@gmail.com> | 2009-07-14 14:49:29 -0700 |
---|---|---|
committer | Aaron Griffin <aaronmgriffin@gmail.com> | 2009-07-14 14:49:29 -0700 |
commit | 6226ceb54a363573eb18856c1d935197fffbc334 (patch) | |
tree | 1c6a5764daa14e846b4f68422c024a8f0744a3c5 | |
parent | 45dc03f5f91f1940a83a11472ff872478aeef099 (diff) |
Refactor PKGINFO reading into a function
This is just for readability and cleanup
Signed-off-by: Aaron Griffin <aaronmgriffin@gmail.com>
-rw-r--r-- | db-functions | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/db-functions b/db-functions index 11ef8e7..359e4c0 100644 --- a/db-functions +++ b/db-functions @@ -54,11 +54,20 @@ repo_unlock () { #repo_unlock repo-name arch restore_umask } +# usage: _grep_pkginfo pkgfile pattern +_grep_pkginfo() { + local _ret + + _ret="$(/usr/bin/bsdtar -xOqf "$1" .PKGINFO | /bin/grep -m 1 -E "$pattern" | /bin/sed 's|\w*\s*=\s*\(.*\)|\1|')" + echo "$_ret" +} + + # 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|')" + _base="$(_grep_pkginfo "$1" "^pkg(base|name)")" if [ -z "$_base" ]; then echo "ERROR: Package '$1' has no pkgbase or pkgname in the PKGINFO. Fail!" exit 1 @@ -71,7 +80,7 @@ getpkgbase() { getpkgname() { local _name - _name="$(/usr/bin/bsdtar -xOqf "$1" .PKGINFO | /bin/grep -m 1 "^pkgname" | /bin/sed 's|\w*\s*=\s*\(.*\)|\1|')" + _name="$(_grep_pkginfo "$1" "^pkgname")" if [ -z "$_name" ]; then echo "ERROR: Package '$1' has no pkgname in the PKGINFO. Fail!" exit 1 @@ -84,7 +93,7 @@ getpkgname() { getpkgver() { local _ver - _ver="$(/usr/bin/bsdtar -xOqf "$1" .PKGINFO | /bin/grep -m 1 "^pkgver" | /bin/sed 's|\w*\s*=\s*\(.*\)|\1|')" + _ver="$(_grep_pkginfo "$1" "^pkgver")" if [ -z "$_ver" ]; then echo "ERROR: Package '$1' has no pkgver in the PKGINFO. Fail!" exit 1 @@ -95,7 +104,7 @@ getpkgver() { check_pkg_arch () { #check_pkg_arch pkgfile arch local _arch - _arch="$(/usr/bin/bsdtar -xOqf "$1" .PKGINFO | /bin/grep -m 1 "^arch" | /bin/sed 's|\w*\s*=\s*\(.*\)|\1|')" + _arch="$(_grep_pkginfo "$1" "^arch")" if [ -z "$_arch" ]; then echo "ERROR: Package '$1' has no arch in the PKGINFO. Fail!" |