#!/bin/sh
#
# reprepro-notify -- Send email notification of package uploads.
#
# Called via a changes file hook by reprepro for every upload, this script is
# responsible for sending notification of the upload to the appropriate
# reporting address.  Per the reprepro manual, this script is called with the
# following options:
#
# 1. The word "accepted"
# 2. The codename to which the *.changes was uploaded
# 3. The source name
# 4. The version
# 5. The path to the changes file itself

set -e

# The address to which to send the mail.
address='report-packages@monitoring.stanford.edu'

if [ 'accepted' != "$1" ] ; then
    echo 'reprepro-notify should be called as a reprepro changes hook' >&2
    exit 1
fi
codename="$2"
source="$3"
version="$4"
changes="$5"
if [ ! -f "$changes" ] ; then
    echo "reprepro-notify: cannot read changes file $changes" >&2
    exit 1
fi

# Send a simple mail message.
cat - "$changes" <<EOF | /usr/sbin/sendmail -t -oi -oem
From: ITS Debian Repository <nobody@stanford.edu>
To: $address
Subject: Package $source $version uploaded to $codename

EOF
exit 0

DOCS=<<__END_OF_DOCS__

=for stopwords
Allbery codename reprepro reprepro-notify

=head1 NAME

reprepro-notify - Send email notification of package uploads

=head1 SYNOPSIS

B<reprepro-notify> accepted I<codename> I<source> I<version> I<changes>

=head1 DESCRIPTION

B<reprepro-notify> is a changes file hook script for B<reprepro> that
sends notification of a new upload to an internal IT Services reporting
address.  It takes as arguments the arguments B<reprepro> uses for hook
scripts and constructs a message with that information in the subject and
the changes file in the body.

=head1 SEE ALSO

reprepro(1)

=head1 AUTHOR

Russ Allbery <rra@stanford.edu>

=cut

__END_OF_DOCS__
