#!/bin/sh -ef

## usage: girar-nmu-helper-task-add-srpm [-t <task id>] path/to/srpm ...

TASKID=
GITALTHOST=git.alt
rpmsign=rpm-sign-gpg-agent

while getopts b:hH:ngrp:t: opt; do
	case "$opt" in
		t) TASKID="${OPTARG:?}"
			readonly TASKID ;;
		n) rpmsign=rpm-sign-no-passphrase ;;
		g) rpmsign=rpm-sign-gpg-agent ;;
		r) rpmsign=rpm ;;
		H) GITALTHOST="${OPTARG:?}"
			readonly GITALTHOST ;;
		h) pod2usage --exit=0 "$0"; exit 0 ;;
		*) pod2usage --exit=2 "$0"; exit 2 ;;
	esac
done
shift "$((OPTIND-1))"

for srpm in "$@"; do
    $rpmsign --resign $srpm
    rsync -v -rlt --partial --stats -e ssh $srpm ${GITALTHOST}:
    ssh $GITALTHOST task add $TASKID srpm `basename $srpm`
done

: <<'__EOF__'

=head1	NAME

girar-nmu-task-helper-add-srpm - add given srpms to the default or given task.

=head1	SYNOPSIS

B<girar-nmu-task-helper-add-srpm>
[B<-h>] 
[B<-H> I<ssh git.alt alias>]
[B<-t> I<task>]
[B<-n> | B<-g> | B<-r>]
I<srpm ...>

=head1	DESCRIPTION

B<girar-nmu-task-helper-add-srpm> 
add given src.rpms to the default or given task in prescribed order.

=head1	OPTIONS

=over

=item	B<-h>

Display this help and exit.

=item	B<-H> [I<git.alt ssh alias>]

By default, git.altlinux.org account should be configured as git.alt in ~/.ssh/config.
If you does not follow that convention, use -H <git.alt your ssh alias> option.

=item  B<-n> | B<-g> | B<-r>

select a rpm sign command to sign a src.rpm.

=over

=item -g) rpm-sign-gpg-agent - use gpg agent to cache passphrase

=item -n) rpm-sign-no-passphrase - useful whan key has no passphrase.

=item -r) rpm use plain rpm.

=back

=item	B<-t> [I<task ID>]

Id of task to add packages to; git.alt task [I<task ID>] add.

=back

=head1	AUTHOR

Written by Igor Vlasenko <viy@altlinux.org>.

=head1	COPYING

Copyright (c) 2010 Igor Vlasenko, ALT Linux Team.

This 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.

=cut

__EOF__
