bugfix, esthetic cleanup, better comments, version bump

This commit is contained in:
Geoffray Levasseur-Brandin
2024-06-21 16:19:44 +02:00
parent 9e49e3e4d7
commit bef205ae84
18 changed files with 634 additions and 571 deletions

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env bash
# ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
# Protected by the BSD3 license. Please read bellow for details.
@@ -38,45 +39,45 @@
# ------------------------------------------------------------------------------
utaz()
{
for opt in $@ ; do
for opt in $@; do
case $opt in
"-h"|"--help")
echo "utaz: uncompress all the given files and/or the ones found in the given"
echo " directories creating an host directory where needed."
echo
echo "Usage: utaz [option] [directorie(s)|file(s)]"
echo
echo "Options:"
echo " -h, --help Display that help screen"
echo " -d, --delete If decompression succeeded, delete the source file"
echo " -c, --create-dir Always create a host directory"
echo " -n, --no-dir Never create a host directory"
echo
return 0
;;
"-h" | "--help")
echo "utaz: uncompress all the given files and/or the ones found in the given"
echo " directories creating an host directory where needed."
echo
echo "Usage: utaz [option] [directorie(s)|file(s)]"
echo
echo "Options:"
echo " -h, --help Display that help screen"
echo " -d, --delete If decompression succeeded, delete the source file"
echo " -c, --create-dir Always create a host directory"
echo " -n, --no-dir Never create a host directory"
echo
return 0
;;
"-d"|"--delete")
local willrm=1
;;
"-d" | "--delete")
local willrm=1
;;
"-c"|"--create-dir")
local createdir=1
;;
"-c" | "--create-dir")
local createdir=1
;;
"-n"|"--no-dir")
local nodir=1
;;
"-n" | "--no-dir")
local nodir=1
;;
"-"*)
disp E "Invalid option, use \"utaz --help\" to display options list"
echo
return 1
;;
"-"*)
disp E "Invalid option, use \"utaz --help\" to display options list"
echo
return 1
;;
*)
# The ${opt%/} writing is to remove trailing / if any
local LIST="$LIST ${opt%/}"
;;
*)
# The ${opt%/} writing is to remove trailing / if any
local LIST="$LIST ${opt%/}"
;;
esac
done
@@ -85,7 +86,7 @@ utaz()
[[ ! $LIST ]] && local LIST="."
for zitem in $LIST; do
[[ $(ls $zitem/*.zip 2> /dev/null | wc -l) -eq 0 ]] &&
[[ $(ls $zitem/*.zip 2>/dev/null | wc -l) -eq 0 ]] &&
disp W "$zitem contains no supported archive file, skipping." &&
continue
@@ -98,20 +99,20 @@ utaz()
disp E "The filesystem can't create directories, exit!" &&
return 1
unzip -o $f -d $dir > /dev/null 2>&1
unzip -o $f -d $dir >/dev/null 2>&1
case $? in
0)
[[ $willrm ]] && rm -f $f && disp I "File $zitem/$f deleted."
;;
0)
[[ $willrm ]] && rm -f $f && disp I "File $zitem/$f deleted."
;;
1)
disp W "Compression program returned a warning: deletion canceled."
;;
*)
disp E "The zip file seems corrupted, failed."
rm -rf $dir > /dev/null 2>&1
continue
;;
1)
disp W "Compression program returned a warning: deletion canceled."
;;
*)
disp E "The zip file seems corrupted, failed."
rm -rf $dir >/dev/null 2>&1
continue
;;
esac
if [[ $createdir ]]; then
@@ -136,7 +137,7 @@ export -f utaz
# ------------------------------------------------------------------------------
# Compress directories or files into one or more archive
# ------------------------------------------------------------------------------
taz ()
taz()
{
_doxz()
{
@@ -151,7 +152,7 @@ taz ()
disp W "xz format is not suited for long term archiving."
disp I "See https://www.nongnu.org/lzip/xz_inadequate.html for details."
# Compresse to xz (lzma2) - Deprecated
# Compresse to xz (lzma2) - Deprecated
xz $verb --compress --keep -$3 -T $2 $1
return $?
}
@@ -170,7 +171,7 @@ taz ()
local procopt=""
[[ $2 -gt 1 ]] &&
disp W "lzip doesn't support multithreading, falling back to 1 thread." &&
disp W "Consitder installing plzip to obtain multithreading abilities."
disp W "Consider installing plzip to obtain multithreading abilities."
}
[[ $4 ]] && local verb="-vv"
@@ -243,68 +244,68 @@ taz ()
return $?
}
for opt in $@ ; do
for opt in $@; do
case $opt in
"-h"|"--help")
echo "taz: archive all files of a directory."
"-h" | "--help")
echo "taz: archive all files of a directory."
echo
echo "Usage: taz [option] [--parallel=<n>] [--format=<format>] [directory1 ... directoryN]"
echo
echo "Options:"
echo " -h, --help Display that help screen"
echo " -d, --delete Delete source file or directory after success"
echo " -f, --format Chose archive format in the given list. If several format are"
echo " given, the smalest is kept"
echo " -p, --parallel Number of threads to use (if allowed by underlying utility)"
echo " -v, --verbose Display progress where possible"
echo " -q, --quiet Display less messages (only errors and warnings)"
echo " -1, .., -9 Compression level to use [1=fast/biggest, 9=slow/smallest]"
echo
echo "Supported archive format:"
echo " Param.| programs | Algo. | Description"
echo " ------+---------------+-------+----------------------------------------"
echo " lz | plzip, lzip | lzma | Safe efficient default format"
echo " xz | xz | lzma2 | Unsafe, not for long term"
echo " bz2 | pbzip2, bzip2 | bzip2 | Historical but less efficient than lz"
echo " gz | pigz, gzip | lz77 | Historical, safe, fast"
echo " lzo | lzop | lzo | Very fast but no multithread"
echo " tar | tar | tar | No compression"
echo
return 0
;;
"-d" | "--delete")
local willrm=1
;;
"-f"?* | "--format"?*)
local compform=$(echo "$opt" | cut -f 2- -d '=')
;;
"-p"?* | "--parallel"?*)
local nproc=$(echo "$opt" | cut -f 2- -d '=')
;;
"-v" | "--verbose")
local verbose=1
;;
"-q" | "--quiet")
QUIET=1
;;
"-"*)
local complevel=$(echo $opt | sed 's/-//')
if ! [[ $complevel =~ ^[1-9]+$ ]]; then
disp E "Invalid option, use taz --help to display options list"
echo
echo "Usage: taz [option] [--parallel=<n>] [--format=<format>] [directory1 ... directoryN]"
echo
echo "Options:"
echo " -h, --help Display that help screen"
echo " -d, --delete Delete source file or directory after success"
echo " -f, --format Chose archive format in the given list. If several format are"
echo " given, the smalest is kept"
echo " -p, --parallel Number of threads to use (if allowed by underlying utility)"
echo " -v, --verbose Display progress where possible"
echo " -q, --quiet Display less messages (only errors and warnings)"
echo " -1, .., -9 Compression level to use [1=fast/biggest, 9=slow/smallest]"
echo
echo "Supported archive format:"
echo " Param.| programs | Algo. | Description"
echo " ------+---------------+-------+----------------------------------------"
echo " lz | plzip, lzip | lzma | Safe efficient default format"
echo " xz | xz | lzma2 | Unsafe, not for long term"
echo " bz2 | pbzip2, bzip2 | bzip2 | Historical but less efficient than lz"
echo " gz | pigz, gzip | lz77 | Historical, safe, fast"
echo " lzo | lzop | lzo | Very fast but no multithread"
echo " tar | tar | tar | No compression"
echo
return 0
;;
return 1
fi
;;
"-d"|"--delete")
local willrm=1
;;
"-f"?*|"--format"?*)
local compform=$(echo "$opt" | cut -f 2- -d '=')
;;
"-p"?*|"--parallel"?*)
local nproc=$(echo "$opt" | cut -f 2- -d '=')
;;
"-v"|"--verbose")
local verbose=1
;;
"-q"|"--quiet")
QUIET=1
;;
"-"*)
local complevel=$(echo $opt | sed 's/-//')
if ! [[ $complevel =~ ^[1-9]+$ ]]; then
disp E "Invalid option, use taz --help to display options list"
echo
return 1
fi
;;
*)
local LIST="$LIST ${opt%/}"
;;
*)
local LIST="$LIST ${opt%/}"
;;
esac
done
@@ -312,7 +313,7 @@ taz ()
[[ ! $nproc ]] && nproc=1
[[ ! $complevel ]] && complevel=6
[[ $verbose -gt 1 && $QUIET -gt 1 ]] &&
disp E "The --verbose and --quiet options can't be used together."
disp E "The --verbose and --quiet options can't be used together."
for item in $LIST; do
local donetar=0
@@ -338,14 +339,14 @@ taz ()
disp I "\t Compressing archive..."
_do$compform $fname $nproc $complevel $verbose
[[ ! $? -eq 0 ]] && case $? in
127)
disp E "Compression program unavailable, aborting."
return 127
;;
*)
disp E "Compression program returned an error, not deleting anything if asked, skipping to next item."
continue
;;
127)
disp E "Compression program unavailable, aborting."
return 127
;;
*)
disp E "Compression program returned an error, not deleting anything if asked, skipping to next item."
continue
;;
esac
[[ $donetar -gt 0 ]] && rm $fname
@@ -359,3 +360,6 @@ taz ()
unset QUIET
}
export -f taz
# ------------------------------------------------------------------------------
# EOF