#!/usr/bin/env bash

source lib/logging.sh

TARGET=$1


if [ -z "$TARGET" ];
then
	log::fatal "No target specified on command line"
fi

log::info"Starting build for for Ul11u4SRU"
log::info "Target: \"${TARGET}\""

JENKINS_TOKEN='1154eb0158729a7d326c1db13e7dca0cea'
JENKINS_SERVER='http://mrshughes.us.oracle.com/jenkins/'

JOB_URL="${JENKINS_SERVER}/job/Solaris_11/job/11.4/job/userland-sru/job/userland-sru-build-11.4/buildWithParameters"

log::info "Using '${JOB_URL}'"

set -x
curl -X POST "${JOB_URL}" \
	--user "pnyc:${JENKINS_TOKEN}" \
	--data-urlencode "Build_Label=${TARGET}" \
	--data-urlencode "hguser=petr.nyc@oracle.com" \
	--data-urlencode "dryrun=false" \
	--data-urlencode "verbose=true" \
	--data-urlencode "debug=true" \
	--data-urlencode "scriptdir=./solaris/userland/sru/" \
	--data-urlencode "do_check_sru_cbe=true" \
	--data-urlencode "prepare_work_area=true" \
	--data-urlencode "do_build=true" \
	--data-urlencode "prepare_delivery=true" \
	--data-urlencode "create_escrow=true" \
	--data-urlencode "create_foss=true" \
	--data-urlencode "delivery=true"

log::info "The job will be started here:"
log::info "    ${JOB_URL%%buildWith*}"
