#!/bin/bash

function build__find_non_volatile() {
  find "$@" -follow -not -type d -and -not -path '*CVS*' -and -not -name '.#*' -and -not -name '*~' -and -not -path '*.svn*' -and -not -path '*.arch-id*' -and -not -path '*{arch}*' -and -not -path '*.bzr*' -and -not -path '*.git*'
}

branch_dir=$(basename $(pwd))
if [[ $1 ]] ; then
  branch_name=$1
else
  branch_name=$branch_dir
fi

if [ -e ../sorcery ]; then
  echo "We need a blank directory beneath the current one to link sorcery -> $branch_dir"
  exit 1
fi
[[ $branch_name == devel ]] && date "+%Y%m%d" > etc/sorcery/version
pushd .. &>/dev/null
NAMES_TMP=/tmp/sorcery.build.$$
ln -sf $branch_dir sorcery
build__find_non_volatile sorcery > $NAMES_TMP
tar --owner=0 --group=0 -cvjf sorcery-${branch_name}.tar.bz2 -T $NAMES_TMP
rm $NAMES_TMP
rm sorcery
popd .. &>/dev/null

#---------------------------------------------------------------------
##=back
##
##=head1 LICENSE
##
## This software is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This software is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this software; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
##
#---------------------------------------------------------------------
