1*d5c9a868SElliott Hughes#!/bin/sh 2*d5c9a868SElliott Hughes# Copyright 1994 David C. Niemi. 3*d5c9a868SElliott Hughes# Copyright 1997,2001,2002 Alain Knaff. 4*d5c9a868SElliott Hughes# This file is part of mtools. 5*d5c9a868SElliott Hughes# 6*d5c9a868SElliott Hughes# Mtools is free software: you can redistribute it and/or modify 7*d5c9a868SElliott Hughes# it under the terms of the GNU General Public License as published by 8*d5c9a868SElliott Hughes# the Free Software Foundation, either version 3 of the License, or 9*d5c9a868SElliott Hughes# (at your option) any later version. 10*d5c9a868SElliott Hughes# 11*d5c9a868SElliott Hughes# Mtools is distributed in the hope that it will be useful, 12*d5c9a868SElliott Hughes# but WITHOUT ANY WARRANTY; without even the implied warranty of 13*d5c9a868SElliott Hughes# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14*d5c9a868SElliott Hughes# GNU General Public License for more details. 15*d5c9a868SElliott Hughes# 16*d5c9a868SElliott Hughes# You should have received a copy of the GNU General Public License 17*d5c9a868SElliott Hughes# along with Mtools. If not, see <http://www.gnu.org/licenses/>. 18*d5c9a868SElliott Hughes# 19*d5c9a868SElliott Hughes# tgz [destination [source...] ] 20*d5c9a868SElliott Hughes# 21*d5c9a868SElliott Hughes# Make a gzip'd tar archive $1 (or stdout) out of specified files 22*d5c9a868SElliott Hughes# (or, if not specified, from everything in the current directory) 23*d5c9a868SElliott Hughes# 24*d5c9a868SElliott Hughes# Requires gzip in the user's path. 25*d5c9a868SElliott Hughes# 26*d5c9a868SElliott Hughes# Requires gnu tar (or something close) in the user's path 27*d5c9a868SElliott Hughes# due to use of --exclude, --totals and -S. 28*d5c9a868SElliott Hughes# 29*d5c9a868SElliott Hughes# 1994/02/19 DCN Created 30*d5c9a868SElliott Hughes# 1994/12/01 DCN Cleanup and major improvements 31*d5c9a868SElliott Hughes# 32*d5c9a868SElliott Hughes# Copyright (C) 1994 David C. Niemi ([email protected]) 33*d5c9a868SElliott Hughes# The author requires that any copies or derived works include this 34*d5c9a868SElliott Hughes# copyright notice; no other restrictions are placed on its use. 35*d5c9a868SElliott Hughes# 36*d5c9a868SElliott Hughes 37*d5c9a868SElliott Hughesset -e 38*d5c9a868SElliott Hughesset -u 39*d5c9a868SElliott Hughes 40*d5c9a868SElliott HughesError () 41*d5c9a868SElliott Hughes{ echo "Error: $0: ${@-}." >&2 42*d5c9a868SElliott Hughes exit 1 43*d5c9a868SElliott Hughes} 44*d5c9a868SElliott Hughes 45*d5c9a868SElliott Hughesif [ $# = 0 ]; then 46*d5c9a868SElliott Hughes dest= 47*d5c9a868SElliott Hughes src=. 48*d5c9a868SElliott Hughes tar cvf - . | gzip -9v 49*d5c9a868SElliott Hughes exit 0 50*d5c9a868SElliott Hugheselif [ $# = 1 ]; then 51*d5c9a868SElliott Hughes dest=$1 52*d5c9a868SElliott Hughes src=. 53*d5c9a868SElliott Hugheselse 54*d5c9a868SElliott Hughes dest=$1 55*d5c9a868SElliott Hughes shift 56*d5c9a868SElliott Hughes src="${@-}" 57*d5c9a868SElliott Hughesfi 58*d5c9a868SElliott Hughes 59*d5c9a868SElliott Hughescase $dest in 60*d5c9a868SElliott Hughes"" | . | .. | */ | */. | */.. ) 61*d5c9a868SElliott Hughes echo "Usage: $0: [destination [source...] ]" >&2 62*d5c9a868SElliott Hughes exit 1 63*d5c9a868SElliott Hughes ;; 64*d5c9a868SElliott Hughes*.t?z | *.?z | *.z | *.Z | *.tz | *.tz? ) 65*d5c9a868SElliott Hughes ;; 66*d5c9a868SElliott Hughes*) 67*d5c9a868SElliott Hughes dest=${dest}.tgz ## Add on .tgz as default suffix 68*d5c9a868SElliott Hughesesac 69*d5c9a868SElliott Hughes 70*d5c9a868SElliott Hughesif [ -h "$dest" ]; then 71*d5c9a868SElliott Hughes Error "Destination file \"$dest\" already exists as a symbolic link" 72*d5c9a868SElliott Hugheselif [ -f "$dest" ]; then 73*d5c9a868SElliott Hughes Error "Destination \"$dest\" already exists as a file" 74*d5c9a868SElliott Hugheselif [ -d "$dest" ]; then 75*d5c9a868SElliott Hughes Error "Destination \"$dest\" already exists as a directory" 76*d5c9a868SElliott Hughesfi 77*d5c9a868SElliott Hughesif [ -z "$dest" -o "X$dest" = 'X-' ]; then 78*d5c9a868SElliott Hughes echo "Writing gzipp'd tar archive to standard output." >&2 79*d5c9a868SElliott Hughes tar cvfS - -- $src | gzip -9v 80*d5c9a868SElliott Hugheselse 81*d5c9a868SElliott Hughes echo "Writing gzip'd tar archive to \"$dest\"." >&2 82*d5c9a868SElliott Hughes tar -cvS --totals --exclude "$dest" -f - -- $src | gzip -9v > "$dest" 83*d5c9a868SElliott Hughes ls -l "$dest" >&2 84*d5c9a868SElliott Hughesfi 85*d5c9a868SElliott Hughes 86*d5c9a868SElliott Hughesexit 0 87