#!/bin/sh

# copyright 2004 vagrant@freegeek.org, distributed under the terms of the
# GNU General Public License version 2 or any later version.

./makepackage --cvs --clean --long-date-version --upload-queue autobuild --nochecksyntax --dist sarge
status="$?"

if [ "$status" = "0" ] && [ -n "$(which dput)" ]; then
  # FIXME it's pretty dumb to assume the user, but something is borked and this might fix it.
  test -z "$USER" && export USER="builder"
  # TODO move dput into separate script
  umask 0022
  for changes in tmp/*.changes ; do
    dput_opts="-u -f"
    if [ -r tests/autobuild.dput.cf ]; then
      dput_opts="$dput_opts -c tests/autobuild.dput.cf"
    fi
    chmod +r "$changes"
    dput $dput_opts autobuild "$changes"
    echo "dput status: $?"
  done
fi

exit "$status"
