[pacman-dev] [PATCH 4/4] repo-add: add source package information to sync db

Allan McRae allan at archlinux.org
Thu Mar 27 03:27:12 EDT 2014


When using the -S/--source option, add source package information to the
sync db if one is found alongside the package file. This could be potentially
used by a libalpm frontend to build package from source or provide a simple
replacement to the Arch Build System.

Signed-off-by: Allan McRae <allan at archlinux.org>
---
 doc/repo-add.8.txt     |  4 +++
 scripts/repo-add.sh.in | 74 ++++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/doc/repo-add.8.txt b/doc/repo-add.8.txt
index d44a8a7..fd7aafb 100644
--- a/doc/repo-add.8.txt
+++ b/doc/repo-add.8.txt
@@ -82,6 +82,10 @@ repo-add Options
 	Remove old package files from the disk when updating their entry in the
 	database.
 
+*-S, \--source*::
+	Add information about source package files to the database if found next to
+	the package file.
+
 Example
 -------
 
diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
index 4325dbf..b9175e4 100644
--- a/scripts/repo-add.sh.in
+++ b/scripts/repo-add.sh.in
@@ -30,6 +30,7 @@ declare -r confdir='@sysconfdir@'
 
 QUIET=0
 DELTA=0
+SOURCE=0
 ONLYADDNEW=0
 RMEXISTING=0
 WITHFILES=0
@@ -61,6 +62,7 @@ Multiple packages to add can be specified on the command line.\n")"
 		printf -- "$(gettext "  -n, --new         only add packages that are not already in the database\n")"
 		printf -- "$(gettext "  -R, --remove      remove package file from disk when updating database entry\n")"
 		printf -- "$(gettext "  -f, --files       update database's file list\n")"
+		printf -- "$(gettext "  -S, --source      add source package information to the database\n")"
 	elif [[ $cmd == "repo-remove" ]] ; then
 		printf -- "$(gettext "Usage: repo-remove [options] <path-to-db> <packagename|delta> ...\n")"
 		printf -- "\n"
@@ -124,6 +126,31 @@ find_pkgentry() {
 	return 1
 }
 
+find_sourcepkg() {
+	local -a files
+
+	for i in $@; do
+		if [[ ${i##*.} != "sig" ]]; then
+			files+=("$i")
+		fi
+	done
+
+    case ${#files[@]} in
+      0|1)
+        if [[ ! -f $1 ]]; then
+          warning "$(gettext "No source package found")"
+          return 1
+        fi
+        ;;
+      *)
+        warning "$(gettext "Cannot determine source package - multiple matches found:")"
+        msg2 '%s' "$@"
+        return 1
+        ;;
+    esac
+    echo "$files"
+}
+
 # Get the package name from the delta filename
 get_delta_pkgname() {
 	local tmp
@@ -193,6 +220,37 @@ db_remove_delta() {
 	return 1
 } # end db_remove_delta
 
+# write source entry
+db_write_source() {
+	local sourcepkg pgpsigsize pgpsig czise md5sum sha256sum
+
+	sourcepkg=$1
+
+	if [[ -f "$sourcepkg.sig" ]]; then
+		pgpsigsize=$(@SIZECMD@ -L "$sourcepkg.sig")
+		if (( pgpsigsize > 16384 )); then
+			error "$(gettext "Invalid package signature file '%s'.")" "$sourcepkg.sig"
+			return 1
+		fi
+		local pgpsig=$(openssl base64 -in "$sourcepkg.sig" | tr -d '\n')
+	fi
+
+	csize=$(@SIZECMD@ -L "$sourcepkg")
+
+	md5sum=$(openssl dgst -md5 "$sourcepkg")
+	md5sum=${md5sum##* }
+	sha256sum=$(openssl dgst -sha256 "$sourcepkg")
+	sha256sum=${sha256sum##* }
+
+	{
+		format_entry "FILENAME"  "${sourcepkg##*/}"
+		format_entry "CSIZE"     "$csize"
+		format_entry "MD5SUM"    "$md5sum"
+		format_entry "SHA256SUM" "$sha256sum"
+		format_entry "PGPSIG"    "$pgpsig"
+	} >"$tmpdir/tree/$pkgname-$pkgver/source"
+}
+
 check_gpg() {
 	if ! type -p gpg >/dev/null; then
 		error "$(gettext "Cannot find the gpg binary! Is GnuPG installed?")"
@@ -264,8 +322,8 @@ db_write_entry() {
 	local pkgfile=$1
 	local -a _groups _licenses _replaces _depends _conflicts _provides \
 		_optdepends _makedepends _checkdepends
-	local pkgname pkgbase pkgver pkgdesc csize size url arch builddate packager \
-		md5sum sha256sum pgpsig pgpsigsize
+	local pkgname pkgbase pkgver basever pkgdesc csize size url arch builddate \
+	packager md5sum sha256sum pgpsig pgpsigsize
 
 	# read info from the zipped package
 	local line var val
@@ -398,6 +456,17 @@ db_write_entry() {
 		bsdtar --exclude='^.*' -tf "$pkgfile" >>"$files_path"
 	fi
 
+	# create a source file
+	if (( SOURCE )); then
+		msg2 "$(gettext "Creating '%s' db entry...")" 'source'
+		local sourcefile
+
+		if sourcefile=$(find_sourcepkg \
+					"${pkgbase:-$pkgname}-${basever:-$pkgver}.src.tar"*); then
+			db_write_source "$sourcefile"
+		fi
+	fi
+
 	# create a delta file
 	if (( DELTA )); then
 		if [[ -n $oldfilename ]]; then
@@ -624,6 +693,7 @@ while (( $# )); do
 		-n|--new) ONLYADDNEW=1;;
 		-R|--remove) RMEXISTING=1;;
 		-f|--files) WITHFILES=1;;
+		-S|--source) SOURCE=1;;
 		--nocolor) USE_COLOR='n';;
 		-s|--sign)
 			check_gpg
-- 
1.9.1



More information about the pacman-dev mailing list