summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2014-01-04 23:48:38 -0500
committerLuke Shumaker <LukeShu@sbcglobal.net>2014-01-04 23:48:38 -0500
commit6223f9fca6803d814ba026cb5b88c9c2ed48b540 (patch)
tree1fdec1424a55471032ac4edd5b08157b005720e3 /lib
parent021653a0acecc8763e1bbe90dbb770b4e6df4390 (diff)
parent40ea1b3ca5c6f6fdbeda230f4048ac7934d68acf (diff)
Merge branch 'devtools'
Conflicts: checkpkg.in lib/common.sh makechrootpkg.in
Diffstat (limited to 'lib')
-rw-r--r--lib/common.sh74
1 files changed, 74 insertions, 0 deletions
diff --git a/lib/common.sh b/lib/common.sh
index 1baab9c..dff9b43 100644
--- a/lib/common.sh
+++ b/lib/common.sh
@@ -1,6 +1,8 @@
# Avoid any encoding problems
export LANG=C
+shopt -s extglob
+
# check if messages are to be printed using color
declare ALL_OFF= BOLD= BLUE= GREEN= RED= YELLOW=
if [[ -t 2 ]]; then
@@ -184,3 +186,75 @@ lock_close() {
local fd=$1
eval "exec $fd>&-"
}
+
+##
+# usage: pkgver_equal( $pkgver1, $pkgver2 )
+##
+pkgver_equal() {
+ local left right
+
+ if [[ $1 = *-* && $2 = *-* ]]; then
+ # if both versions have a pkgrel, then they must be an exact match
+ [[ $1 = "$2" ]]
+ else
+ # otherwise, trim any pkgrel and compare the bare version.
+ [[ ${1%%-*} = "${2%%-*}" ]]
+ fi
+}
+
+##
+# usage: find_cached_package( $pkgname, $pkgver, $arch )
+#
+# $pkgver can be supplied with or without a pkgrel appended.
+# If not supplied, any pkgrel will be matched.
+##
+find_cached_package() {
+ local searchdirs=("$PWD" "$PKGDEST") results=()
+ local targetname=$1 targetver=$2 targetarch=$3
+ local dir pkg pkgbasename pkgparts name ver rel arch size r results
+
+ for dir in "${searchdirs[@]}"; do
+ [[ -d $dir ]] || continue
+
+ for pkg in "$dir"/*.pkg.tar?(.?z); do
+ [[ -f $pkg ]] || continue
+
+ # avoid adding duplicates of the same inode
+ for r in "${results[@]}"; do
+ [[ $r -ef $pkg ]] && continue 2
+ done
+
+ # split apart package filename into parts
+ pkgbasename=${pkg##*/}
+ pkgbasename=${pkgbasename%.pkg.tar?(.?z)}
+
+ arch=${pkgbasename##*-}
+ pkgbasename=${pkgbasename%-"$arch"}
+
+ rel=${pkgbasename##*-}
+ pkgbasename=${pkgbasename%-"$rel"}
+
+ ver=${pkgbasename##*-}
+ name=${pkgbasename%-"$ver"}
+
+ if [[ $targetname = "$name" && $targetarch = "$arch" ]] &&
+ pkgver_equal "$targetver" "$ver-$rel"; then
+ results+=("$pkg")
+ fi
+ done
+ done
+
+ case ${#results[*]} in
+ 0)
+ return 1
+ ;;
+ 1)
+ printf '%s\n' "$results"
+ return 0
+ ;;
+ *)
+ error 'Multiple packages found:'
+ printf '\t%s\n' "${results[@]}" >&2
+ return 1
+ esac
+}