summaryrefslogtreecommitdiffstats
path: root/scripts/repo-add.sh.in
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/repo-add.sh.in')
-rw-r--r--scripts/repo-add.sh.in169
1 files changed, 137 insertions, 32 deletions
diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
index dfc93974..820db369 100644
--- a/scripts/repo-add.sh.in
+++ b/scripts/repo-add.sh.in
@@ -4,8 +4,7 @@
# repo-remove - remove a package entry from a given repo database file
# @configure_input@
#
-# Copyright (c) 2006-2008 Aaron Griffin <aaron@archlinux.org>
-# Copyright (c) 2007-2008 Dan McGee <dan@archlinux.org>
+# Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -30,6 +29,8 @@ confdir='@sysconfdir@'
QUIET=0
DELTA=0
WITHFILES=0
+SIGN=0
+VERIFY=0
REPO_DB_FILE=
LOCKFILE=
CLEAN_LOCK=0
@@ -61,34 +62,42 @@ error() {
# print usage instructions
usage() {
- printf "repo-add, repo-remove (pacman) %s\n\n" "$myver"
- printf "$(gettext "Usage: repo-add [-d] [-f] [-q] <path-to-db> <package|delta> ...\n")"
- printf "$(gettext "Usage: repo-remove [-q] <path-to-db> <packagename|delta> ...\n\n")"
- printf "$(gettext "\
+ cmd="$(basename $0)"
+ printf "%s (pacman) %s\n\n" "$cmd" "$myver"
+ if [[ $cmd == "repo-add" ]] ; then
+ printf "$(gettext "Usage: repo-add [options] <path-to-db> <package|delta> ...\n")"
+ printf "$(gettext "\
repo-add will update a package database by reading a package file.\n\
Multiple packages to add can be specified on the command line.\n\n")"
- printf "$(gettext "\
+ printf "$(gettext "Options:\n")"
+ printf "$(gettext " -d, --delta generate and add delta for package update\n")"
+ printf "$(gettext " -f, --files update database's file list\n")"
+ elif [[ $cmd == "repo-remove" ]] ; then
+ printf "$(gettext "Usage: repo-remove [options] <path-to-db> <packagename|delta> ...\n\n")"
+ printf "$(gettext "\
repo-remove will update a package database by removing the package name\n\
specified on the command line from the given repo database. Multiple\n\
packages to remove can be specified on the command line.\n\n")"
- printf "$(gettext "\
-Use the -q/--quiet flag to minimize output to basic messages, warnings,\n\
-and errors.\n\n")"
- printf "$(gettext "\
-Use the -d/--delta flag to automatically generate and add a delta file\n\
-between the old entry and the new one, if the old package file is found\n\
-next to the new one.\n\n")"
- printf "$(gettext "\
-Use the -f/--files flag to update a database including file entries.\n\n")"
- echo "$(gettext "Example: repo-add /path/to/repo.db.tar.gz pacman-3.0.0.pkg.tar.gz")"
- echo "$(gettext "Example: repo-remove /path/to/repo.db.tar.gz kernel26")"
+ printf "$(gettext "Options:\n")"
+ fi
+ printf "$(gettext " -q, --quiet minimize output\n")"
+ printf "$(gettext " -s, --sign sign database with GnuPG after update\n")"
+ printf "$(gettext " -k, --key <key> use the specified key to sign the database\n")"
+ printf "$(gettext " -v, --verify verify database's signature before update\n")"
+ printf "$(gettext "\n\
+See %s(8) for more details and descriptions of the available options.\n\n")" $cmd
+ if [[ $cmd == "repo-add" ]] ; then
+ echo "$(gettext "Example: repo-add /path/to/repo.db.tar.gz pacman-3.0.0-1-i686.pkg.tar.gz")"
+ elif [[ $cmd == "repo-remove" ]] ; then
+ echo "$(gettext "Example: repo-remove /path/to/repo.db.tar.gz kernel26")"
+ fi
}
version() {
- printf "repo-add, repo-remove (pacman) %s\n\n" "$myver"
+ cmd="$(basename $0)"
+ printf "%s (pacman) %s\n\n" "$cmd" "$myver"
printf "$(gettext "\
-Copyright (C) 2006-2008 Aaron Griffin <aaron@archlinux.org>.\n\
-Copyright (c) 2007-2008 Dan McGee <dan@archlinux.org>.\n\n\
+Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>\n\n\
This is free software; see the source for copying conditions.\n\
There is NO WARRANTY, to the extent permitted by law.\n")"
}
@@ -184,14 +193,62 @@ db_remove_delta()
return 1
} # end db_remove_delta
+check_gpg() {
+ if ! type -p gpg >/dev/null; then
+ error "$(gettext "Cannot find the gpg binary! Is gnupg installed?")"
+ exit 1 # $E_MISSING_PROGRAM
+ fi
+}
+
+# sign the package database once repackaged
+create_signature() {
+ (( ! SIGN )) && return
+ local dbfile="$1"
+ local ret=0
+ msg "$(gettext "Signing database...")"
+
+ local SIGNWITHKEY=""
+ if [[ -n $GPGKEY ]]; then
+ SIGNWITHKEY="-u ${GPGKEY}"
+ fi
+ gpg --detach-sign --use-agent ${SIGNWITHKEY} "$dbfile" &>/dev/null || ret=$?
+
+ if (( ! ret )); then
+ msg2 "$(gettext "Created signature file %s.")" "$dbfile.sig"
+ else
+ warning "$(gettext "Failed to sign package database.")"
+ fi
+}
+
+# verify the existing package database signature
+verify_signature() {
+ (( ! VERIFY )) && return
+ local dbfile="$1"
+ local ret=0
+ msg "$(gettext "Verifying database signature...")"
+
+ if [[ ! -f $dbfile.sig ]]; then
+ warning "$(gettext "No existing signature found, skipping verification.")"
+ return
+ fi
+ gpg --verify "$dbfile.sig" || ret=$?
+ if (( ! ret )); then
+ msg2 "$(gettext "Database signature file verified.")"
+ else
+ error "$(gettext "Database signature was NOT valid!")"
+ exit 1
+ fi
+}
+
# write an entry to the pacman database
# arg1 - path to package
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
@@ -219,10 +276,19 @@ db_write_entry()
IFS=$OLDIFS
- # get md5sum and compressed size of package
+ csize=$(@SIZECMD@ "$pkgfile")
+
+ # compute checksums
+ msg2 "$(gettext "Computing checksums...")"
md5sum="$(openssl dgst -md5 "$pkgfile")"
md5sum="${md5sum##* }"
- csize=$(@SIZECMD@ "$pkgfile")
+ 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
@@ -264,9 +330,12 @@ db_write_entry()
[[ -n $csize ]] && echo -e "%CSIZE%\n$csize\n" >>desc
[[ -n $size ]] && echo -e "%ISIZE%\n$size\n" >>desc
- # compute checksums
- msg2 "$(gettext "Computing md5 checksums...")"
+ # add checksums
echo -e "%MD5SUM%\n$md5sum\n" >>desc
+ echo -e "%SHA256SUM%\n$sha256sum\n" >>desc
+
+ # 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"
@@ -352,6 +421,7 @@ check_repo_db()
exit 1
fi
fi
+ verify_signature "$REPO_DB_FILE"
msg "$(gettext "Extracting database to a temporary location...")"
bsdtar -xf "$REPO_DB_FILE" -C "$tmpdir"
else
@@ -477,24 +547,50 @@ trap 'trap_exit "$(gettext "An unknown error has occured. Exiting...")"' ERR
success=0
# parse arguments
-for arg in "$@"; do
- case "$arg" in
+while [[ $# > 0 ]]; do
+ case "$1" in
-q|--quiet) QUIET=1;;
-d|--delta) DELTA=1;;
-f|--files) WITHFILES=1;;
+ -s|--sign)
+ check_gpg
+ SIGN=1
+ if ! gpg --list-key ${GPGKEY} &>/dev/null; then
+ if [[ ! -z $GPGKEY ]]; then
+ error "$(gettext "The key ${GPGKEY} does not exist in your keyring.")"
+ else
+ error "$(gettext "There is no key in your keyring.")"
+ fi
+ exit 1
+ fi
+ ;;
+ -k|--key)
+ check_gpg
+ shift
+ GPGKEY="$1"
+ if ! gpg --list-key ${GPGKEY} &>/dev/null; then
+ error "$(gettext "The key ${GPGKEY} does not exist in your keyring.")"
+ exit 1
+ fi
+ ;;
+ -v|--verify)
+ check_gpg
+ VERIFY=1
+ ;;
*)
if [[ -z $REPO_DB_FILE ]]; then
- REPO_DB_FILE="$arg"
+ REPO_DB_FILE="$1"
LOCKFILE="$REPO_DB_FILE.lck"
check_repo_db
else
case "$cmd" in
- repo-add) add $arg && success=1 ;;
- repo-remove) remove $arg && success=1 ;;
+ repo-add) add $1 && success=1 ;;
+ repo-remove) remove $1 && success=1 ;;
esac
fi
;;
esac
+ shift
done
# if at least one operation was a success, re-zip database
@@ -519,15 +615,24 @@ if (( success )); then
warning "$(gettext "No packages remain, creating empty database.")"
bsdtar -c${TAR_OPT}f "$filename" -T /dev/null
fi
+ create_signature "$filename"
+
popd >/dev/null
[[ -f $REPO_DB_FILE ]] && mv -f "$REPO_DB_FILE" "${REPO_DB_FILE}.old"
+ [[ -f $REPO_DB_FILE.sig ]] && rm -f "$REPO_DB_FILE.sig"
[[ -f $tmpdir/$filename ]] && mv "$tmpdir/$filename" "$REPO_DB_FILE"
+ [[ -f $tmpdir/$filename.sig ]] && mv "$tmpdir/$filename.sig" "$REPO_DB_FILE.sig"
dblink="${REPO_DB_FILE%.tar.*}"
target=${REPO_DB_FILE##*/}
ln -sf "$target" "$dblink" 2>/dev/null || \
ln -f "$target" "$dblink" 2>/dev/null || \
cp "$REPO_DB_FILE" "$dblink"
+ if [[ -f "$target.sig" ]]; then
+ ln -sf "$target.sig" "$dblink.sig" 2>/dev/null || \
+ ln -f "$target.sig" "$dblink.sig" 2>/dev/null || \
+ cp "$REPO_DB_FILE.sig" "$dblink.sig"
+ fi
else
msg "$(gettext "No packages modified, nothing to do.")"
exit 1