#!/bin/sh

# Copyright (c) 2008-2011 Aleksey Cheusov <vle@gmx.net>
# All rights reserved.
#
# See LICENSE file

######################################################################

set -e
. /usr/pkg/bin/pipestatus

# usage: stage_upload_logs BUILD_ID
test $# -eq 1

# init
BUILD_ID="$1"

: ${DISTBB_CONF:=/usr/pkg/etc/distbb.conf}
. "$DISTBB_CONF"
. /usr/pkg/libexec/distbb/common

# main
verbose_print "  uploading logs... "

a=1
while true; do
    ex=0
    if eval $UPLOAD_LOGS_PROG $REPORT1_DIR $UPLOAD_LOGS_DEST; then
	break
    else
	ex=$?
    fi
    if test "$a" -eq "$UPLOAD_LOGS_ATTEMPTS"; then
	break
    fi
    a=$(($a+1))
    sleep "$UPLOAD_LOGS_PAUSE"
done

verbose_print "done\n"
