From: Hugo Villeneuve Date: Wed, 1 Apr 2026 16:57:25 +0000 (-0400) Subject: tarbz2: use DEST directory name in tar archive X-Git-Url: http://gitweb.hugovil.com/sitemap.xml?a=commitdiff_plain;h=c2db9378b90a030ea97c7a90041b7c3c8a39859e;p=hvutilities.git tarbz2: use DEST directory name in tar archive 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 --- diff --git a/scripts/tarbz2 b/scripts/tarbz2 index c830504..3ea891c 100755 --- a/scripts/tarbz2 +++ b/scripts/tarbz2 @@ -48,17 +48,19 @@ fi 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 $?