From: Hugo Villeneuve Date: Mon, 17 Jun 2013 18:17:36 +0000 (-0400) Subject: Ajout support pour pbzip2 dans le script tarbz2 X-Git-Url: http://gitweb.hugovil.com/?a=commitdiff_plain;h=656e63c0b6829c67483f0f6171fe89dc012bbcfc;p=hvutilities.git Ajout support pour pbzip2 dans le script tarbz2 Ajout option fichier de sortie pour tarbz2 --- diff --git a/scripts/tarbz2 b/scripts/tarbz2 index e7a6d93..a16c8c1 100755 --- a/scripts/tarbz2 +++ b/scripts/tarbz2 @@ -1,26 +1,64 @@ #!/bin/sh +PROG_NAME=$(basename $0) + +BZIP2_BIN=bzip2 + +if [ -x /usr/bin/pbzip2 ]; then + BZIP2_BIN=pbzip2 +fi + print_usage() { echo "$(basename $0) -- Create bzip2 compressed TAR archive." - echo "Usage: $(basename $0) DIR" + echo "Usage: ${PROG_NAME} [OPTION]... DIR" + echo "Options:" + echo " -f filename Specify the base name of the generated archive." + echo " Default is same name as the input directory." } -if [ $# -ne 1 ]; then - print_usage +while getopts "hf:" flag ;do + case ${flag} in + h) + print_usage + ;; + f) + DEST=${OPTARG} + ;; + ?) + echo "${PROG_NAME}: Invalid option: ${OPTARG}." + echo "Try \`${PROG_NAME} --help' for more information." + exit 1 + ;; + esac +done +shift `expr "${OPTIND}" - 1` + +# `$#' now represents the number of arguments after the options. +# `$1' is the first argument, etc. +if [ ${#} -eq 0 ]; then + echo "${PROG_NAME}: Missing source directory." + echo "Try \`${PROG_NAME} --help' for more information." + exit 1 +elif [ ${#} -gt 1 ]; then + echo "${PROG_NAME}: Too many arguments." + echo "Try \`${PROG_NAME} --help' for more information." exit 1 fi DIR=${1%/} -BASE=$(basename ${DIR}) + +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 - + # Decompressing file to standard output and piping result to bzip2 -tar cvf - ${DIR} | bzip2 -9 > ${BASE}.tar.bz2 +tar cvf - ${DIR} | ${BZIP2_BIN} -9 > ${DEST}.tar.bz2 exit $?