#! /bin/bash

unset LANG

wait_opt=--wait-for-ok

while true; do
  if [ "$1" = "--dist" -o "$1" = "--target" ] ; then
    dist="--target $2"
    shift
    shift
    continue
  fi

  if [ "$1" = "--package" ] ; then
    package="--package $2"
    shift
    shift
    continue
  fi

  if [ "$1" = "--no-wait" ] ; then
    wait_opt=
    shift
    continue
  fi

  break
done

# we need neither git directory nor JOB_NAME if package has been specified
if [ -z "$package" ] ; then
  job_name=${JOB_NAME%-sr}

  if [ -z "$job_name" -o "$job_name" = "$JOB_NAME" ] ; then
    echo "$JOB_NAME: unexpected job"
    exit 1
  fi

  cd "../$job_name"
fi

tobs $wait_opt --sr $dist $package
