#!/bin/sh
#
# This simple script wrapper proceses an upload with reprepro with the right
# configuration location and with GnuPG pointed at the appropriate keyring.
# The first argument to the script must be the repository to which the package
# was uploaded.

set -e

if [ -z "$1" ] ; then
    echo 'No repository specified' >&2
    exit 1
fi
repo="$1"

umask 002
GNUPGHOME="/srv/repos/$repo/keyring"; export GNUPGHOME
reprepro -b "/srv/repos/$repo" --waitforlock 2 processincoming default
reprepro -b "/srv/repos/$repo" --waitforlock 2 pull
exit 0

DOCS=<<__END_OF_DOCS__

=for stopwords
Allbery GnuPG passphrase processincoming reprepro reprepro-upload
subdirectory

=head1 NAME

reprepro-upload - Wrapper around reprepro processincoming

=head1 SYNOPSIS

B<reprepro-upload> I<repository>

=head1 DESCRIPTION

B<reprepro-upload> is a wrapper around C<reprepro processincoming> that
handles multiple repositories and configures GnuPG for repository
signing.  It should be called with the repository as an argument, normally
from one's F<~/.dput.cf>.  For example:

    [local]
    method = scp
    fqdn = genesis.stanford.edu
    incoming = /srv/repos/local/incoming
    post_upload_command = ssh genesis.stanford.edu reprepro-upload local

It will automatically run C<reprepro pull> after successful processing
to perform any automatic pulls between distributions.

All calls made to the C<reprepro> script are made with the C<--waitforlock
2> option in case more than one person (or service) is calling
reprepro-upload at the same time; see the man page for C<reprepro> for
more information on the C<--waitforlock> option.

=head1 FILES

=over 4

=item /srv/repos

The expected base path for all repositories.  Each repository will live in
a subdirectory in this directory, with all the normal reprepro
directories.

=item /srv/repos/I<repository>/keyring

The GnuPG home directory for signing for I<repository>.  The secret key
for the repository should live in this directory and should not have a
passphrase, unless people need to type a passphrase for each upload.

=back

=head1 SEE ALSO

gpg(1), reprepro(1)

=head1 AUTHOR

Russ Allbery <rra@stanford.edu>

=cut

__END_OF_DOCS__
