]> Untitled Git - hvutilities.git/commitdiff
tarbz2: use DEST directory name in tar archive
authorHugo Villeneuve <hugo@hugovil.com>
Wed, 1 Apr 2026 16:57:25 +0000 (12:57 -0400)
committerHugo Villeneuve <hugo@hugovil.com>
Thu, 2 Apr 2026 23:34:04 +0000 (19:34 -0400)
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>
scripts/tarbz2

index c8305040e1863cb252246ca38cd214611d177f83..3ea891cd1fe58f7f158adc8451d84ee772b1dc21 100755 (executable)
@@ -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 $?