[archivers] xzize: reindent

master
Matteo Cypriani 3 years ago
parent 3fb819f430
commit 718768755c
  1. 230
      archivers/xzize.sh

@ -28,136 +28,138 @@ COMPRESSION_LEVEL=
test_extension()
{
FILE="$1"
EXTENSION="$2"
NEWEXTENSION=xz
if [ $# -eq 3 ] ; then
NEWEXTENSION="$3"
fi
BASE="$(basename "$FILE" ."$EXTENSION")"
if [ "$BASE" != "$FILE" ] ; then
DEST="$BASE".$NEWEXTENSION
return 0
fi
DEST="$FILE"
return 1
FILE="$1"
EXTENSION="$2"
NEWEXTENSION=xz
if [ $# -eq 3 ] ; then
NEWEXTENSION="$3"
fi
BASE="$(basename "$FILE" ."$EXTENSION")"
if [ "$BASE" != "$FILE" ] ; then
DEST="$BASE".$NEWEXTENSION
return 0
fi
DEST="$FILE"
return 1
}
do_recompress()
{
if [ -e "$DEST" ] ; then
echo "Skipping source file « $SOURCE »: destination file « $DEST » already exists!" >&2
return 0
fi
echo "Recompressing « $SOURCE » to « $DEST »…"
$ACTION -c "$SOURCE" | xz $COMPRESSION_LEVEL >"$DEST"
return $?
if [ -e "$DEST" ] ; then
echo "Skipping source file « $SOURCE »: destination file « $DEST » already exists!" >&2
return 0
fi
echo "Recompressing « $SOURCE » to « $DEST »…"
$ACTION -c "$SOURCE" | xz $COMPRESSION_LEVEL >"$DEST"
return $?
}
## Verify number of arguments ##
if [ $# -lt 1 ] ; then
echo "$0 requires at least one argument!" >&2
exit 2
echo "$0 requires at least one argument!" >&2
exit 2
fi
## Process files ##
for SOURCE in "$@" ; do
# Does source file exist?
if [ ! -e "$SOURCE" ] ; then
echo "Skipping source file « $SOURCE »: does not exist!" >&2
continue
fi
# Does source file is regular?
if [ ! -f "$SOURCE" ] ; then
echo "Skipping source file « $SOURCE »: is not a regular file!" >&2
continue
fi
# GZip
if test_extension "$SOURCE" gz ; then
ACTION="gunzip"
do_recompress
continue
fi
# GZipped Tar (.tgz)
if test_extension "$SOURCE" tgz $TAR_XZ_EXT ; then
ACTION="gunzip"
do_recompress
continue
fi
# BZip2
if test_extension "$SOURCE" bz2 ; then
ACTION="bunzip2"
do_recompress
continue
fi
# BZipped Tar (.tbz)
if test_extension "$SOURCE" tbz $TAR_XZ_EXT ; then
ACTION="bunzip2"
do_recompress
continue
fi
# BZipped Tar (.tb2)
if test_extension "$SOURCE" tb2 $TAR_XZ_EXT ; then
ACTION="bunzip2"
do_recompress
continue
fi
# LZMA
if test_extension "$SOURCE" lzma ; then
ACTION="unlzma"
do_recompress
continue
fi
# LZMA compressed Tar (.tlz)
if test_extension "$SOURCE" tlz $TAR_XZ_EXT ; then
ACTION="unlzma"
do_recompress
continue
fi
# Compress
if test_extension "$SOURCE" Z ; then
ACTION="uncompress"
do_recompress
continue
fi
# Compressed Tar (.taz)
if test_extension "$SOURCE" taz $TAR_XZ_EXT ; then
ACTION="uncompress"
do_recompress
continue
fi
# XZ
if test_extension "$SOURCE" xz ; then
echo "Skipping source file « $DEST »: has already .xz suffix!" >&2
continue
fi
# XZipped Tar (.txz)
if test_extension "$SOURCE" txz $TAR_XZ_EXT ; then
echo "Skipping source file « $DEST »: seems to be a XZipped Tar archive (.txz suffix)!" >&2
continue
fi
# Uncompressed file: fall back to simple compression
echo "Compressing « $SOURCE » to xz…"
xz $COMPRESSION_LEVEL "$SOURCE"
# Does source file exist?
if [ ! -e "$SOURCE" ] ; then
echo "Skipping source file « $SOURCE »: does not exist!" >&2
continue
fi
# Is source file regular?
if [ ! -f "$SOURCE" ] ; then
echo "Skipping source file « $SOURCE »: is not a regular file!" >&2
continue
fi
# GZip
if test_extension "$SOURCE" gz ; then
ACTION="gunzip"
do_recompress
continue
fi
# GZipped Tar (.tgz)
if test_extension "$SOURCE" tgz $TAR_XZ_EXT ; then
ACTION="gunzip"
do_recompress
continue
fi
# BZip2
if test_extension "$SOURCE" bz2 ; then
ACTION="bunzip2"
do_recompress
continue
fi
# BZipped Tar (.tbz)
if test_extension "$SOURCE" tbz $TAR_XZ_EXT ; then
ACTION="bunzip2"
do_recompress
continue
fi
# BZipped Tar (.tb2)
if test_extension "$SOURCE" tb2 $TAR_XZ_EXT ; then
ACTION="bunzip2"
do_recompress
continue
fi
# LZMA
if test_extension "$SOURCE" lzma ; then
ACTION="unlzma"
do_recompress
continue
fi
# LZMA compressed Tar (.tlz)
if test_extension "$SOURCE" tlz $TAR_XZ_EXT ; then
ACTION="unlzma"
do_recompress
continue
fi
# Compress
if test_extension "$SOURCE" Z ; then
ACTION="uncompress"
do_recompress
continue
fi
# Compressed Tar (.taz)
if test_extension "$SOURCE" taz $TAR_XZ_EXT ; then
ACTION="uncompress"
do_recompress
continue
fi
# XZ
if test_extension "$SOURCE" xz ; then
echo "Skipping source file « $DEST »: has already .xz suffix!" >&2
continue
fi
# XZipped Tar (.txz)
if test_extension "$SOURCE" txz $TAR_XZ_EXT ; then
echo "Skipping source file « $DEST »: seems to be a XZipped Tar archive (.txz suffix)!" >&2
continue
fi
# Uncompressed file: fall back to simple compression
echo "Compressing « $SOURCE » to xz…"
xz $COMPRESSION_LEVEL "$SOURCE"
done
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

Loading…
Cancel
Save