#!/bin/sh -e

destdir=~/beehive-logs
type=success
repobranch=Sisyphus

while getopts b:d:t: opt; do
	case "$opt" in
		b) repobranch="${OPTARG:?}"
			readonly repobranch ;;
		d) destdir="${OPTARG:?}" 
			readonly destdir ;;
		t) type="${OPTARG:?}" ;;
		h) pod2usage --exit=0 "$0"; exit 0 ;;
		*) pod2usage --exit=2 "$0"; exit 2 ;;
	esac
done
shift "$((OPTIND-1))"

[ -n "$1" ] && destdir="$1"
[ -n "$2" ] && type="$2"

process_arch_logs()
{
    local ARCH=$1
    local TYPE=$2
    rm -rf $destdir/$ARCH $destdir/$TYPE
    mkdir -p $destdir/
    rsync -ap  git.altlinux.org::beehive-logs/$repobranch-$ARCH/latest/$TYPE $destdir/
    mv $destdir/$TYPE $destdir/$ARCH
}

process_arch_logs x86_64 $type
process_arch_logs i586 $type

: <<'__EOF__'

=head1	NAME

repocop-rsync-beehive-logs - helper utility for beehive logs test.

=head1	SYNOPSIS

B<repocop-rsync-beehive-logs>
[B<-h>] 
[B<-b> I<repository branch>]
[B<-d> I<destdir>]
[B<-t> I<type>] 
[<destdir>]
[<type>]


=head1	DESCRIPTION

B<repocop-rsync-beehive-logs> 

TODO

=head1	OPTIONS

=over

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

Name of the repository branch. Values: Sisyphus|p6|t6|..
Default is Sisyphus.

=item	B<-d> I<destdir>

Name of dir to store logs. Default is ~/beehive-logs.

=item	B<-h>

Display this help and exit.

=item	B<-t> [I<type>]

success or error.

=back

=head1	AUTHOR

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

=head1	COPYING

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