#!/bin/sh

# Rebuild a source package and then trigger a binary build.

set -eu

while getopts "d:r:q:" opt ; do
  case $opt in
    d) distribution="$OPTARG" ;;
    r) revision="$OPTARG" ;;
    q) queue="$OPTARG" ;;
    *) exit 5 ;;
  esac
done
# shift away args
shift $(($OPTIND - 1))

PACKAGE="$1"

./trigger-source-rebuild -r "${revision:-1}" ${distribution:+-d "$distribution"} "$PACKAGE"
echo "https://pgdgbuild.dus.dg-i.net/job/$PACKAGE-source"
echo -n "Continue? "
read reply
./trigger-job ${distribution:+-d "$distribution"} ${queue:+-q "$queue"} "$PACKAGE-binaries"
