When specifying the "-f" option, this will allow the decompression to be
done in DEST directory instead of the source directory. This avoids
the necessity to create a copy first, tarbz2 it, and then remove the
temporary copy.
Signed-off-by: Hugo Villeneuve <hugo@hugovil.com>
DIR=${1%/}
-if [ -z ${DEST} ]; then
- DEST=$(basename ${DIR})
-fi
-
# Checking if directory exists.
if [ ! -d ${DIR} ]; then
echo "$0: Directory ${DIR} not found."
exit 1
fi
+if [ -z ${DEST} ]; then
+ DEST=$(basename ${DIR})
+else
+ DIR_OPTS="--transform "s@${DIR}@${DEST}@""
+fi
+
# Decompressing file to standard output and piping result to bzip2
-tar cf - ${DIR} | ${BZIP2_BIN} -9 > ${DEST}.tar.bz2
+tar cf - ${DIR} ${DIR_OPTS} | ${BZIP2_BIN} -9 > ${DEST}.tar.bz2
exit $?