#! /bin/bash
# Copyright (C) 2006-2016  CEA/DEN, EDF R&D
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
#
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#

#
DIR=`echo $0 | sed -e "s,[^/]*$,,;s,/$,,;s,^$,.,"`
cd ${DIR}
DIR=`pwd`

REP=`basename $DIR`

if [ -z "$USER" ]
then
    USER=`whoami 2> /dev/null` || true
fi

mkdir -p /tmp/${USER}
\rm -rf /tmp/${USER}/${REP}

cd ${DIR}/..
cp -drf ${REP} /tmp/${USER}/${REP}

cd /tmp/${USER}/${REP}
./root_clean
find . -name "CVS" -depth -exec \rm -rf {} \;
find . -type f -exec chmod u+rw {} \;

cd /tmp/${USER}

TAR_FILE=${REP}`date +_%d.%m.%Y_%H.%M`.tgz

tar cvfz ${TAR_FILE} ${REP}

cp ${TAR_FILE} ${DIR}/..

\rm -rf /tmp/${USER}/${REP} ${TAR_FILE}
