82 lines
1.9 KiB
Bash
Executable File
82 lines
1.9 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# lz, Copyright © 2010 Matteo Cypriani
|
|
#
|
|
# This program is free software. It comes without any warranty, to
|
|
# the extent permitted by applicable law. You can redistribute it
|
|
# and/or modify it under the terms of the Do What The Fuck You Want
|
|
# To Public License, Version 2, as published by Sam Hocevar. See
|
|
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
|
#
|
|
# This script emulates and extends the lz and uz commands of the mtools.
|
|
# It handles: .tar, .tar.gz, .tar.bz2, .tar.xz, .tar.lzma and .tar.Z,
|
|
# through the standards options of GNU tar.
|
|
# If the script name is "lz", the archive content is displayed. If the
|
|
# name is "uz", it is extracted.
|
|
# Note that you need GNU Tar, at least version 1.22 to support XZ files.
|
|
|
|
|
|
## Verify program name ##
|
|
|
|
PROGRAM=`basename $0`
|
|
|
|
if [ "$PROGRAM" = "lz" ] ; then
|
|
ACTION="t"
|
|
elif [ "$PROGRAM" = "uz" ] ; then
|
|
ACTION="x"
|
|
else
|
|
echo '$0 = "'"$0"' (not "lz" nor "uz")!' >&2
|
|
exit 1
|
|
fi
|
|
|
|
|
|
## Verify number of arguments ##
|
|
|
|
if [ $# -lt 1 ] ; then
|
|
echo "$PROGRAM requires at least one argument!" >&2
|
|
exit 2
|
|
fi
|
|
|
|
|
|
## Process files ##
|
|
|
|
for F in "$@" ; do
|
|
# Simple Tar archive
|
|
if [ `basename "$F" .tar` != "$F" ] ; then
|
|
FORMAT=""
|
|
|
|
# GZipped Tar
|
|
elif [ `basename "$F" .tar.gz` != "$F" \
|
|
-o `basename "$F" .tgz` != "$F" ] ; then
|
|
FORMAT="--gzip"
|
|
|
|
# BZipped Tar
|
|
elif [ `basename "$F" .tar.bz2` != "$F" \
|
|
-o `basename "$F" .tbz` != "$F" \
|
|
-o `basename "$F" .tb2` != "$F" ] ; then
|
|
FORMAT="--bzip"
|
|
|
|
# XZipped Tar
|
|
elif [ `basename "$F" .tar.xz` != "$F" \
|
|
-o `basename "$F" .txz` != "$F" ] ; then
|
|
FORMAT="--xz"
|
|
|
|
# Compressed Tar
|
|
elif [ `basename "$F" .tar.Z` != "$F" \
|
|
-o `basename "$F" .taz` != "$F" ] ; then
|
|
FORMAT="--compress"
|
|
|
|
# LZMA compressed Tar
|
|
elif [ `basename "$F" .tar.lzma` != "$F" \
|
|
-o `basename "$F" .tlz` != "$F" ] ; then
|
|
FORMAT="--lzma"
|
|
|
|
# Unknown extension
|
|
else
|
|
echo "Extension of file « $F » unknown! (skipping)" >&2
|
|
continue
|
|
fi
|
|
|
|
tar "$FORMAT" -"$ACTION"f "$F"
|
|
done
|