#!/bin/sh

: ${BF_SAVEDIR=.}

if [ ! -z "$BF_SAVEDIR" ] ; then
    NAME=`basename $0 | sed s@^t\.@@`
    DATE=`date +"%Y%m%d"`
    if [ -d $NAME.$DATE ] ; then
	rm -rf $NAME.$DATE
    fi
    mkdir $NAME.$DATE
    ( cd $TMPDIR ; tar cf - *) | ( cd $NAME.$DATE ; tar xf - )
    while {
	fname=$NAME.`date +"%Y%m%d-%H%M%S"`.tar.gz
	test -f $fname
    } ; do sleep 1 ; done
    tar czf $fname $TMPDIR
fi
