1#!/bin/sh 2# Copyright 1994,2002 David C. Niemi. 3# Copyright 1996,1997,2001-2003 Alain Knaff. 4# This file is part of mtools. 5# 6# Mtools is free software: you can redistribute it and/or modify 7# it under the terms of the GNU General Public License as published by 8# the Free Software Foundation, either version 3 of the License, or 9# (at your option) any later version. 10# 11# Mtools is distributed in the hope that it will be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU General Public License for more details. 15# 16# You should have received a copy of the GNU General Public License 17# along with Mtools. If not, see <http://www.gnu.org/licenses/>. 18# uz [file...] 19# lz [file...] 20# 21# If called "uz", gunzips and extracts a gzip'd tar'd archive. 22# If called "lz", gunzips and shows a listing of a gzip'd tar'd archive. 23# 24# Requires: gzip and tar in the user's path. Should work with most tars. 25# "-" is now used for backwards compatibility with antique tars, e.g. SCO. 26# 27# 1994/02/19 DCN Created (as a trivial, but useful script) 28# 1994/12/01 DCN Combined uz and lz, added suffix handling 29# 2002/09/11 DCN Added bzip2 support 30# 31# Copyright (C) 1994, 2002 David C. Niemi (niemi at tuxers dot net) 32# The author requires that any copies or derived works include this 33# copyright notice; no other restrictions are placed on its use. 34# 35 36set -e 37set -u 38 39## Default unzipping command 40uzcmd='gzip -cd' 41 42case $0 in 43*uz) 44 tarparam="-pxvf" 45 action="Extracting from " 46 ;; 47*lz) 48 tarparam="-tvf" 49 action="Reading directory of " 50 ;; 51*) 52 echo "$0: expect to be named either \"uz\" or \"lz\"." >&2 53 exit 1 54 ;; 55esac 56 57if [ $# = 0 ]; then 58 echo "$action standard input." >&2 59 $uzcmd - | tar "$tarparam" - 60 exit 0 61fi 62 63while [ $# -ge 1 ]; do 64 echo >&2 65 found= 66 67 for suffix in "" .gz .tgz .tar.gz .z .tar.z .taz .tpz .Z .tar.Z .tar.bz2; do 68 if [ -r "${1}$suffix" ]; then 69 found=$1$suffix 70 break 71 fi 72 done 73 74 case $found in 75 *.tar.bz2 | *.tb2) 76 uzcmd='bzip2 -cd' 77 ;; 78 esac 79 if [ -z "$found" ]; then 80 echo "$0: could not read \"$1\"." >&2 81 else 82 echo "$action \"$found\"." >&2 83 $uzcmd -- "$found" | tar "$tarparam" - 84 fi 85 shift 86done 87 88exit 0 89