#!/bin/bash

[ ! -f "configure.ac" ] && {
  echo 1>&2 "Must be run from mod-xslt root!"
  exit 1
}

[ ! -d "../http" ] && {
  echo 1>&2 "../http does not exist!"
  exit 1
}

  # Get package version from various sources
rep_version=`grep 'major' < ../http/http/software/releases.xml|tr '\t ' '  '|sed -e 's@<[^0-9]*@\.@g' -e 's/[^\.]*\.//' -e 's/\.[^\.]*$//' |head -n1`
configac_version=`grep AC_INIT < configure.ac |sed -e 's@[^,]*,[^0-9]*@@' -e 's@,.*@@'`
configure_version=`grep '^PACKAGE_VERSION' < ./configure |sed -e "s/[^']*'//" -e "s/'.*//"`

[ "$HOSTNAME" != "joshua" ] && {
  echo 1>&2 "must be run outside chroots..."
  exit 1
}

[ "$configure_version" != "$configac_version" ] && {
  echo 1>&2 "configure.ac and configure not in sync"
  exit 1
}

  # Verify if this is a snapshot or ... (configure version != repository version)
[ "$configac_version" == "$rep_version" ] && {
  echo 1>&2 "snapshot [yes,NO]? rep version: $rep_version, configac: $configac_version"
  read answer
  [ "$answer" == "yes" ] || exit 1
  snapshot="yes"
}

rep=`./tools/rep-id ../http/http/software/archive`

rsync -avz --exclude '.*' --exclude 'build/' \
	--exclude 'LAST_*' --exclude '{arch}' --exclude 'tags' \
	. $rep/modxslt-`basename $rep`/
(
  cd $rep
  tar -cvzf modxslt-`basename $rep`.tar.gz ./modxslt-`basename $rep`
  cc-gpg-sign ./modxslt-`basename $rep`.tar.gz
)

exit 0
[ ! -z "$snapshot" ] && {
  tla tag modxslt2--main--2.0 modxslt2--stable--1.3 
  echo 1>&2 "Enter release update information (ctrl+D): "
  update=`cat`
}
