• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2# Copyright 1994,2002 David C. Niemi.
3# Copyright 1996,1997,2001-2003,2010 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# 2010/10/16	AKN	Added lzip support
31#
32# Copyright (C) 1994, 2002 David C. Niemi (niemi at tuxers dot net)
33# The author requires that any copies or derived works include this
34# copyright notice; no other restrictions are placed on its use.
35#
36
37set -e
38set -u
39
40## Default unzipping command
41uzcmd='gzip -cd'
42
43case $0 in
44*uz)
45	tarparam="-pxvf"
46	zipparam=""
47	action="Extracting from "
48	;;
49*lz)
50	tarparam="-tvf"
51	zipparam="-l"
52	action="Reading directory of "
53	;;
54*)
55	echo "$0: expect to be named either \"uz\" or \"lz\"." >&2
56	exit 1
57	;;
58esac
59
60if [ $# = 0 ]; then
61	echo "$action standard input." >&2
62	$uzcmd - | tar "$tarparam" -
63	exit 0
64fi
65
66while [ $# -ge 1 ]; do
67	echo >&2
68	found=
69
70	for suffix in "" .gz .tgz .tar.gz .z .tar.z .taz .tpz .Z .tar.Z .tar.bz2 tar.lz .zip .jar .war .ear .aar .tar.xz; do
71		if [ -r "${1}$suffix" ]; then
72			found=$1$suffix
73			break
74		fi
75	done
76
77	unzip=0
78	case $found in
79		*.tar.bz2 | *.tb2)
80			uzcmd='bzip2 -cd'
81			;;
82		*.zip | *.jar | *.war | *.ear | *.aar)
83			unzip=1
84			;;
85		*.tar.lz)
86			uzcmd='lzip -cd'
87			;;
88		*.tar.xz)
89			uzcmd='xz -cd'
90			;;
91	esac
92	if [ -z "$found" ]; then
93		echo "$0: could not read \"$1\"." >&2
94	else
95		echo "$action \"$found\"." >&2
96		if [ $unzip = 1 ]; then
97			unzip $zipparam -- "$found"
98		else
99			$uzcmd -- "$found" | tar "$tarparam" -
100		fi
101	fi
102	shift
103done
104
105exit 0
106