#!/bin/sh -ef

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

repobranch=
deps=
GITALTHOST=git.alt
rpmsign=rpm-sign-gpg-agent

while getopts b:d:hH:ngrp:t: opt; do
	case "$opt" in
		b) repobranch="${OPTARG:?}"
			readonly repobranch ;;
		d) deps="${OPTARG:?}"
			readonly deps ;;
		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 build ${repobranch:+-b $repobranch} ${deps:+--deps $deps} srpm `basename $srpm`
done

: <<'__EOF__'

=head1	NAME

girar-nmu-helper-task-for-each-srpm - create a new task for each srpm.

=head1	SYNOPSIS

B<girar-nmu-helper-task-for-each-srpm>
[B<-h>] 
[B<-b> I<repository>]
[B<-d> I<deps>]
[B<-H> I<ssh git.alt alias>]
[B<-n> | B<-g> | B<-r>]
I<srpm ...>

=head1	DESCRIPTION

B<girar-nmu-helper-task-for-each-srpm> 
builds each srpm in a a new task.

=head1	OPTIONS

=over

=item	B<-b> I<repository name>

Name of the repository branch. Values are: sisyphus|5.1|p5|..
Default is sisyphus.

=item	B<-d> I<deps>

Number of the task to depend on. Translates to --deps I<deps> girar option.

=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<-h>

Display this help and exit.

=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

=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__
