#!/bin/sh -ef

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

TASKID=
BEFORE_TASK=
GITERYALTHOST=
GIRARALTHOST=girar
rpmsign=rpm-sign-gpg-agent

while getopts a:b:B:hH:R:p:t: opt; do
	case "$opt" in
		a|t) TASKID="${OPTARG:?}"
			readonly TASKID ;;
		B) BEFORE_TASK="${OPTARG:?}"
			readonly BEFORE_TASK ;;
		H) GITERYALTHOST="${OPTARG:?}"
			readonly GITERYALTHOST ;;
		R) GIRARALTHOST="${OPTARG:?}"
			readonly GIRARALTHOST ;;
		h) pod2usage --exit=0 "$0"; exit 0 ;;
		*) pod2usage --exit=2 "$0"; exit 2 ;;
	esac
done

if [ -n "$BEFORE_TASK" ] && [ -z "$TASKID" ]; then
    echo "-B <before_subtask_id> require -t <taskid> option"
    exit 2
fi

shift "$((OPTIND-1))"

for name in "$@"; do
    ssh $GIRARALTHOST task add $TASKID $BEFORE_TASK rebuild "$name"
done

: <<'__EOF__'

=head1	NAME

girar-nmu-task-helper-add-rebuild - add "rebuild <name>" commands to the default or given task.

=head1	SYNOPSIS

B<girar-nmu-task-helper-add-rebuild>
[B<-h>] 
[B<-H> I<ssh gitery(git.alt) alias>]
[B<-R> I<ssh girar alias>]
[B<-t> I<task>]|[B<-a> I<task>]
[B<-B> I<before_subtask_id>]
I<srpm ...>

=head1	DESCRIPTION

B<girar-nmu-task-helper-add-rebuild> 
add "rebuild <name>" commands to the default or given task in prescribed order.

=head1	OPTIONS

=over

=item	B<-h>

Display this help and exit.

=item	B<-R> [I<girar ssh alias>]

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

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

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

=item	B<-t> [I<task ID>] (also B<-a> [I<task ID>])

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

=item	[B<-B> I<before_subtask_id>]

I<before_subtask_id> is used in the extended format of girar-task add coomand:
girar-task add [<task_id> [<before_subtask_id>]] srpm <filename>

=back

=head1	AUTHOR

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

=head1	COPYING

Copyright (c) 2010-2015 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__
