diff --git a/abump.in b/abump.in
index 581ed8dba0e4257877956d5387fec36762f59138..76284623d1766c5843e08ee2bfd17355c3e60f73 100755
--- a/abump.in
+++ b/abump.in
@@ -20,14 +20,22 @@ fi
 do_bump() {
 	local p rc=0 pkgname pkgver section message
 	local upgrade="${cvelist:+security }upgrade"
+	local a
 	for p; do
 		pkgname=${p%-[0-9]*}
 		pkgver=${p#${pkgname}-}
 
+		# calculate APKBUILD's path
+		if [ "${pkgname#*/}" != "$pkgname" ] && ! [ -d "$APORTSDIR/${pkgname%/*} ]; then
+			error "'$p' should be of form 'foo-1.2.3' or 'main/foo-1.2.3'"
+			rc=1; continue
+		fi
+		a=$(aports_buildscript "$pkgname" || die "can't find APKBUILD for $pkgname") || { rc=1; continue; }
+
 		(
 		set -e
 
-		cd $HOME/aports/*/$pkgname
+		cd "${a%/*}"
 		section=${PWD%/*}
 		section=${section##*/}
 
@@ -75,6 +83,8 @@ recursive="-r"
 cvelist=
 fixes=
 
+[ -n "$APORTSDIR" ] || error "can't locate \$APORTSDIR"
+
 args=`getopt -o s:Rkqh --long security:,recursive,keep,quiet,help -n "$prog" -- "$@"`
 if [ $? -ne 0 ]; then
 	usage
diff --git a/functions.sh.in b/functions.sh.in
index d71ef38bda51da7c2120736ef720dc874de37428..96b058656ab559a77653af0cf06c796cf0844273 100644
--- a/functions.sh.in
+++ b/functions.sh.in
@@ -19,6 +19,18 @@ if [ -f "$abuild_userconf" ]; then
 fi
 
 
+# expects $1 to be a package directory in the aports tree ('foo' or 'main/foo')
+# outputs APKBUILD's path if successful
+aports_buildscript() {
+	[ -n "$APORTSDIR" ] || return 1
+	if [ "${1#*/}" != "$1" ]; then
+		( cd "$APORTSDIR/$1" && [ -f APKBUILD ] && echo "$PWD/APKBUILD" )
+	else
+		( cd "$APORTSDIR"/*/"$1" && [ -f APKBUILD ] && echo "$PWD/APKBUILD" )
+	fi
+}
+
+
 # output functions
 case $prog in
 abuild)