From cfa2eebdafc4d2341621e24ce61dd5a74a0de9fc Mon Sep 17 00:00:00 2001
From: Ray Kohler <ataraxia937@gmail.com>
Date: Thu, 24 Mar 2011 18:05:30 -0400
Subject: Fix use of relative paths for packages in repo-add

Move checksum and pgpsig calcluation before changing into the
tmpdir, otherwise we can't find the files if a relative path
was used.

Signed-off-by: Ray Kohler <ataraxia937@gmail.com>
Signed-off-by: Dan McGee <dan@archlinux.org>
---
 scripts/repo-add.sh.in | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)

(limited to 'scripts')

diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
index 59e98cfe..9b57ba76 100644
--- a/scripts/repo-add.sh.in
+++ b/scripts/repo-add.sh.in
@@ -234,8 +234,9 @@ db_write_entry()
 {
 	# blank out all variables
 	local pkgfile="$1"
-	local pkgname pkgver pkgdesc csize size md5sum url arch builddate packager \
-		_groups _licenses _replaces _depends _conflicts _provides _optdepends
+	local pkgname pkgver pkgdesc csize size url arch builddate packager \
+		_groups _licenses _replaces _depends _conflicts _provides _optdepends \
+		md5sum sha256sum pgpsig
 
 	local OLDIFS="$IFS"
 	# IFS (field separator) is only the newline character
@@ -265,6 +266,18 @@ db_write_entry()
 
 	csize=$(@SIZECMD@ "$pkgfile")
 
+	# compute checksums
+	msg2 "$(gettext "Computing checksums...")"
+	md5sum="$(openssl dgst -md5 "$pkgfile")"
+	md5sum="${md5sum##* }"
+	sha256sum="$(openssl dgst -sha256 "$pkgfile")"
+	sha256sum="${sha256sum##* }"
+
+	# compute base64'd PGP signature
+	if [[ -f "$pkgfile.sig" ]]; then
+		pgpsig=$(openssl base64 -in "$pkgfile.sig" | tr -d '\n')
+	fi
+
 	# ensure $pkgname and $pkgver variables were found
 	if [[ -z $pkgname || -z $pkgver ]]; then
 		error "$(gettext "Invalid package file '%s'.")" "$pkgfile"
@@ -284,13 +297,6 @@ db_write_entry()
 		fi
 	fi
 
-	# compute checksums
-	msg2 "$(gettext "Computing checksums...")"
-	md5sum="$(openssl dgst -md5 "$pkgfile")"
-	md5sum="${md5sum##* }"
-	sha256sum="$(openssl dgst -sha256 "$pkgfile")"
-	sha256sum="${sha256sum##* }"
-
 	# remove an existing entry if it exists, ignore failures
 	db_remove_entry "$pkgname"
 
@@ -316,11 +322,8 @@ db_write_entry()
 	echo -e "%MD5SUM%\n$md5sum\n" >>desc
 	echo -e "%SHA256SUM%\n$sha256sum\n" >>desc
 
-	# add base64'd PGP signature
-	if [[ -f $startdir/$pkgfile.sig ]]; then
-		pgpsig=$(openssl base64 -in "$startdir/$pkgfile.sig" | tr -d '\n')
-		echo -e "%PGPSIG%\n$pgpsig\n" >>desc
-	fi
+	# add PGP sig
+	[[ -n $pgpsig ]] && echo -e "%PGPSIG%\n$pgpsig\n" >>desc
 
 	[[ -n $url ]] && echo -e "%URL%\n$url\n" >>desc
 	write_list_entry "LICENSE" "$_licenses" "desc"
-- 
cgit v1.2.3-2-g168b