# Copyright © 1996 Heiko Schlittermann
# Copyright © 1999 Stephane Bortzmeyer
# Copyright © 2002, 2003 Josip Rodin <joy-packages@debian.org>
# Copyright © 2011 Frank Lichtenheld <djpig@debian.org>
# Copyright © 2017, 2019-2020, 2022 Guillem Jover <guillem@debian.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
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

=head1 NAME

dupload.conf - configuration file for dupload

=head1 DESCRIPTION

The configuration file is rather straight forward Perl code as it is
included by the B<dupload> script via C<do $config>.  I<The config file
is read as Perl code!>

Any B<dupload.conf> must begin with C<package config;> because C<config> is
the namespace expected by B<dupload>.

For examples of the configuration please refer to the global configuration
file F</etc/dupload.conf>.

It contains associative arrays, each indexed by the nickname (see B<--to>
option of B<dupload>), for the following items:

=over 4

=item B<fqdn> [required]

The fully qualified domain name (FQDN) of the nickname.

For the B<copy> method, this option is ignored and the local
FQDN will be used instead.

=item B<method> [optional]

The transfer method. The available methods are:

=over 2

=item *

B<ftp> (default)

=item *

B<http> (since 2.9.9)

=item *

B<https> (since 2.9.9)

=item *

B<scp> (since 1.8)

=item *

B<scpb> (since 1.17)

=item *

B<rsync> (over SSH; since 2.4.1)

=item *

B<copy> (local filesystem; since 2.9.0)

=back

If you are using an upload queue, use B<ftp> because it is fast.
If you are using an authenticated host, B<always> use B<https>, or one
of B<scp> or B<rsync> via SSH, because B<ftp> transmits the password in
clear text.

For B<scp> and B<rsync> to work properly, you have to setup the remote
and local host to establish a ssh/slogin connection using F<.shosts/.rhosts>
or the files in F<~/.ssh/>. If you do not want or cannot do that,
you may find the B<scpb> more convenient since it uploads in batch,
reducing the number of password prompts.

The only major caveat of the B<rsync> and B<scpb> options is that the files are
processed in a batch mode, i.e. not separately, so in case of an error
B<dupload> will not be able to detect which part of the transfer failed, and
just delete the B<.upload> file completely.

=item B<login> [optional]

The account name used to log into the remote host.
For B<ftp> the default is B<anonymous>, which should work with firewall
logins too.
For B<scp>, B<scpb> and B<rsync> the default is delegated to SSH and its
own configuration.
For B<http> and B<https> there is no default.

=item B<passwordcmd> [optional] (since 2.9.9)

The command to retrieve a password.
It is expected to output the password on stdout.

If this option has not been specified, and the B<secret-tool> program is
installed, the following command will be used to retrieve the password
from a system secrets store via the Secret Service interface:
Z<>
  B<secret-tool lookup host >I<host>B< user >I<user>B< service dupload>

If the command fails, then the password will be requested from a prompt.

=item B<password> [optional]

The FTP password for anonymous logins.

=item B<filemode> [optional] (since 2.9.1)

The destination files mode, in octal. If the value is B<undef>, the mode
will not be modified. The default is B<0644>.

=item B<incoming> [required]

Incoming directory, the directory we try to upload to.

=item B<queuedir> [optional]

The directory we move the uploaded files to (after successful upload to
I<incoming>. Usually necessary only with some special upload queues.

=item B<distallowlist> [optional] (since 2.9.6)

The regex of the distributions allowed for this host. This check is done
against the B<Distribution> field in the F<.changes> file.

=item B<distblocklist> [optional] (since 2.9.6)

The regex of the distributions blocked for this host. This check is done
against the B<Distribution> field in the F<.changes> file.

=item B<mail> [optional] (since 2.9.9)

The email addresses (C<to> and C<cc>) where the announcement about the upload
for the C<match> distribution should be sent.

This is an array of hashes with the following keys:

=over

=item B<match> [required]

The regex of the distribution that needs to match to send an announcement.

=item B<to> [required]

Email address where the announcement about the packages is sent.

=item B<cc> [optional]

Email address where to send a copy address of the announcement.

=back

=item B<fullname> [optional]

Your full name, one that should appear in the announcement.

If you leave this setting empty, the default will depend on your mail
system. Usually the full name will be copied from the GCOS field in
F</etc/passwd>.

=item B<visibleuser> [optional]

Your username that should appear in the announcement. Defaults to
C<getlogin()>.

=item B<visiblename> [optional]

The host/domain name that appears as the part to the right of the B<@>
character in the I<from>-part of the announcement. Defaults to the value
your local MTA likes.

=item B<passive> [optional] (since 2.0)

Set the passive mode for FTP transfers. Since B<dupload> uses L<Net::FTP>,
you can also use the environment variable B<FTP_PASSIVE>.

=item B<options> [optional] (since 2.6.3.1)

An array reference containing option strings (since 2.10.2),
that will be added verbatim to the command line of any
B<scp> or B<rsync> calls done.

For backwards compatibility it can also be specified as a scalar string,
but this usage is discouraged and will be deprecated in the future.

=item B<dinstall_runs> [optional] (since 2.1)

Tells B<dupload> that the remote host runs dinstall (or equivalent)
so that B<dupload> will not send a duplicate announcement mail.
The default is 0 (false), set it to 1 to enable it.

=item B<archive> [optional] (since 2.0)

If set to 0 (false), adds a B<X-No-Archive: yes> header in the announcement.
The default is 1 (true).

=back

The configuration files also contain the following global variables:

=over 4

=item B<default_host> [optional] (since 2.1)

The default host to upload to. The default value of this variable is set
depending on the current vendor, but if there is no configuration for that
vendor it will be left unset.

=item B<mta> [optional] (since 2.9.8)

The pathname to a B<sendmail> compatible I<MTA>.
The MTA specified must support the B<-f> option to set the envelope sender
address, and the B<-F> option to set the sender's full name.
The default is F</usr/sbin/sendmail>.

=item B<no_parentheses_to_fullname> [optional] (since 2.1)

Prevents B<dupload> to add parentheses around the full name when making
mail announcements. Default is 0 (false), set it to 1 to enable it.

=back

=head1 HOOKS

Hooks are a powerful way to add actions which will be run before or
after a dupload (like the preinst and postinst script of B<dpkg>).

You have two sorts of hooks: pre-upload and post-upload. Both are simple
shell commands (executed by C<sh -c> so you can use any shell tricks).
Pre-uploads are
always run (even in dry mode) and stop B<dupload> if they fail
(failure being measured by the hook's exit status). Post-uploads
are only run when you are not in dry mode and only if the uploading succeeded.

Hooks get information about themselves and the nickname acted on through the
environment (since 2.10.0), with several matching the configuration options
for the current nickname:

=over 4

=item DUPLOAD_HOOK

The hook category.

=item DUPLOAD_HOST

The host nickname.

=item DUPLOAD_METHOD

Same as the B<method> option.

=item DUPLOAD_FQDN

Same as the B<fqdn> option.

=item DUPLOAD_LOGIN

Same as the B<login> option.

=item DUPLOAD_INCOMING

Same as the B<incomingdir> option.

=item DUPLOAD_QUEUEDIR

Same as the B<queuedir> option.

=item DUPLOAD_SSH_OPTIONS

Same as the B<options> option.

=item DUPLOAD_FTP_PASSIVE

Same as the B<queuedir> option.

=back

Both sorts of hooks are run for a given category: B<changes>, B<sourcepackage>,
B<package>, B<file>, B<deb> and B<host>.

=over 4

=item changes

This hook is run once per F<changes> file (given as an argument to B<dupload>)
with the filename as its parameter.

=item sourcepackage

This hook is run once per F<changes> file
with the source package name and its version as its two parameters.

=item package

This hook is run once per binary package (a F<deb> file) with
the package name and its version as its two parameters.

=item file

This hook is run once per uploaded file, with the file name as its parameter.

=item deb

This hook is run once per binary package (a F<deb> file) with
the filename as its parameter.

=item host (since 2.10.0)

This hook is run once before any other pre hook and after any post hook,
with the host name as its parameter.

=back

=head2 Syntax

Hooks are defined in two Perl hashes, C<%preupload> and C<%postupload>, each
indexed by category. In addition to the global hashes, each host entry has
two fields with the same names, for the host-specific hooks.

Hooks are defined as array references with each item executed in sequence.

The shell command will be substituted first: C<%1> will be replace by the first
argument, etc.

=head2 Per-host or global hooks

Hooks can be global (for all the hosts) or can be for a specific host.
Host specific hooks override the global ones for each category.

=head2 Examples

This one runs B<lintian> before uploading. It is global and guarantees
that you will always upload lintian-clean packages (thanks to B<lintian>
return status).

     $preupload{'deb'} = [ 'lintian -v -i %1' ];

This one just display the name and versions of successfully uploaded packages.

     $postupload{'package'} = [ 'echo PACKAGE %1 %2 uploaded' ];

Unlike the two others, this one is specific to one host, I<debian-ssh>, and
overrides the default global hook in charge of checking the OpenPGP signatures:

     $cfg{'debian-ssh'}{preupload}{'changes'} = [ 'echo Uploading %1' ];

=head1 FILES

=over

=item F</etc/dupload.conf>

=item F<~/.dupload.conf>

=item B<--configfile> I<config-file>

The configuration files are loaded if available in the order listed,
overriding previous files.

=back

=head1 ENVIRONMENT

=over

=item B<FTP_FIREWALL>

=item B<FTP_PASSIVE>

Those of L<Net::FTP> for the B<ftp> method.

=item B<http_proxy> or B<HTTP_PROXY>

=item B<https_proxy> or B<HTTPS_PROXY>

=item B<all_proxy> or B<ALL_PROXY>

=item B<no_proxy>

=item B<REQUEST_METHOD>

Those of L<HTTP::Tiny> for the B<http> and B<https> methods.

=back
