Added in-place compression as well as cleaned up some directory handling.

Thu, 18 Feb 2010 14:15:16 -0500

author
Ryan McKern <ryan@orangefort.com>
date
Thu, 18 Feb 2010 14:15:16 -0500
changeset 7
ff62229b657d
parent 6
e57ad9460aef
child 8
61205427eb08

Added in-place compression as well as cleaned up some directory handling.

mktar.sh file | annotate | diff | revisions
     1.1 --- a/mktar.sh	Sun Oct 18 01:51:41 2009 -0400
     1.2 +++ b/mktar.sh	Thu Feb 18 14:15:16 2010 -0500
     1.3 @@ -17,10 +17,11 @@
     1.4  
     1.5  ## Bzip2 is the default
     1.6  #=> We're also enabling effcient sparse file handling, and unresolved links.
     1.7 -SWITCHES="--one-file-system -Scjf"
     1.8 +SWITCHES="--one-file-system -cSjf"
     1.9  EXTENSION="tbz2"
    1.10  TARGET="${2}"
    1.11  VERBOSE=""
    1.12 +USE_TAR="/opt/local/bin/hfstar"
    1.13  
    1.14  if [ $# -eq 0 ]; then # Script invoked with no command-line args?
    1.15    echo "Usage: $0 [-g|-b] [-v] file ..."
    1.16 @@ -39,13 +40,13 @@
    1.17  if [ -d "${TARGET}" -o -f "${TARGET}" ]; then
    1.18  	while getopts gbv option; do	
    1.19  		case "$option" in
    1.20 -		## gzip that file!
    1.21 -		g)	SWITCHES="--one-file-system -Sczf"
    1.22 +		## we CAN gzip...
    1.23 +		g)	SWITCHES="--one-file-system cSzf"
    1.24  			EXTENSION="tgz"
    1.25  		;;
    1.26  		## ... but we bzip2 by default
    1.27 -		b)	SWITCHES="--one-file-system -Scjf"
    1.28 -			EXTENSION="tbz2"
    1.29 +		b)	SWITCHES=$SWITCHES
    1.30 +			EXTENSION=$EXTENSION
    1.31  		;;
    1.32  		## .. ratchet up verbosity
    1.33  		v)	VERBOSE="-v --totals"
    1.34 @@ -54,6 +55,12 @@
    1.35  			exit 1;;
    1.36  		esac
    1.37  	done
    1.38 +	
    1.39 +  OUTPUT=`basename "${TARGET}"`
    1.40 +  if [[ "${TARGET:0:1}" == "/" ]]; then
    1.41 +    RESETROOT="-C $(dirname "$TARGET")"
    1.42 +    TARGET=`basename "$TARGET"`
    1.43 +  fi
    1.44  
    1.45  	if [ -f "${TARGET%/}.$EXTENSION" -o -f "${TARGET%/}.$EXTENSION" ]; then
    1.46  		echo "ERROR: "${TARGET%/}.$EXTENSION" exists, cannot continue."
    1.47 @@ -61,9 +68,9 @@
    1.48  	else
    1.49  		echo "Compressing ${TARGET%/}..."
    1.50  		if [ $DEBUG ]; then
    1.51 -		  echo "tar $VERBOSE $SWITCHES \"${TARGET%/}.$EXTENSION\" \"${TARGET%/}\""
    1.52 +		  echo "$USE_TAR $VERBOSE $SWITCHES \"${OUTPUT%/}.$EXTENSION\" ${RESETROOT%/} \"${TARGET%/}\""
    1.53  		else
    1.54 -		  tar $VERBOSE $SWITCHES "${TARGET%/}.$EXTENSION" "${TARGET%/}" &> /dev/stdout
    1.55 +		  tar $VERBOSE $SWITCHES "${OUTPUT%/}.$EXTENSION" ${RESETROOT} "${TARGET%/}" &> /dev/stdout
    1.56  		fi
    1.57  		echo "Compression complete."
    1.58  	fi

mercurial