#!/bin/bash
# Accepts directories to build packages from on the commandline, but defaults
# to building: perl-xCAT and xCAT-client

major=`cat Version`
lintian="" # TODO: lintian fails currently
#lintian="--svn-lintian"

if [ "$1" = "-s" ]; then
  shift
  snap=true
  date="$( date +'%F' )"
  version="$major-snapshot-$( date +'%Y%m%d' )"
fi

packages="${@:-perl-xCAT xCAT-client}"

for pkg in $packages; do
  mkdir -p debs/$pkg
  echo "*** Building Debian package for $pkg."
  cd $pkg
  if $snap; then
    debchange --distribution unstable --newversion $version "snapshot of $pkg from $date"
  fi
  svn-buildpackage --svn-ignore $lintian --svn-move-to=../debs/$pkg
  cd -
done