support for spaced filename
This commit is contained in:
@@ -208,7 +208,22 @@ utaz()
|
|||||||
disp E "The --create-dir and --no-dir options are mutually exclusive."
|
disp E "The --create-dir and --no-dir options are mutually exclusive."
|
||||||
|
|
||||||
for zitem in "${FILES[@]}"; do
|
for zitem in "${FILES[@]}"; do
|
||||||
for f in "${zitem}"/*; do
|
# Build list of input files to process, with whitespace-safe handling.
|
||||||
|
local targets=()
|
||||||
|
if [[ -f "$zitem" ]]; then
|
||||||
|
targets=("$zitem")
|
||||||
|
elif [[ -d "$zitem" ]]; then
|
||||||
|
mapfile -d '' -t targets < <(find "$zitem" -mindepth 1 -maxdepth 1 -print0 2>/dev/null)
|
||||||
|
if [[ ${#targets[@]} -eq 0 ]]; then
|
||||||
|
disp I "Directory ${zitem} is empty, skipping."
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
disp W "Path ${zitem} is not a file or directory, skipping."
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
for f in "${targets[@]}"; do
|
||||||
local dir="${f%.*}"
|
local dir="${f%.*}"
|
||||||
local extractor=""
|
local extractor=""
|
||||||
case "$f" in
|
case "$f" in
|
||||||
@@ -269,21 +284,21 @@ utaz()
|
|||||||
# Verify binary existence
|
# Verify binary existence
|
||||||
local cmd=${extractor//_un/}
|
local cmd=${extractor//_un/}
|
||||||
if [[ $cmd == "deb" ]]; then
|
if [[ $cmd == "deb" ]]; then
|
||||||
command -v dpkg-deb >/dev/null 2>&1 || {
|
command -v -- dpkg-deb >/dev/null 2>&1 || {
|
||||||
disp E "The program 'dpkg-deb' is not installed, aborting."
|
disp E "The program 'dpkg-deb' is not installed, aborting."
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
elif [[ $cmd == "rpm" ]]; then
|
elif [[ $cmd == "rpm" ]]; then
|
||||||
command -v rpm2cpio >/dev/null 2>&1 || {
|
command -v -- rpm2cpio >/dev/null 2>&1 || {
|
||||||
disp E "The program 'rpm2cpio' is not installed, aborting."
|
disp E "The program 'rpm2cpio' is not installed, aborting."
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
command -v cpio >/dev/null 2>&1 || {
|
command -v -- cpio >/dev/null 2>&1 || {
|
||||||
disp E "The program 'cpio' is not installed, aborting."
|
disp E "The program 'cpio' is not installed, aborting."
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
command -v ${cmd} >/dev/null 2>&1 || {
|
command -v -- "${cmd}" >/dev/null 2>&1 || {
|
||||||
disp E "Binary ${cmd} necessary to extract ${f} is missing."
|
disp E "Binary ${cmd} necessary to extract ${f} is missing."
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -318,7 +333,12 @@ utaz()
|
|||||||
if [[ -n ${createdir} ]]; then
|
if [[ -n ${createdir} ]]; then
|
||||||
disp I "Archive extracted successfully in subdirectory."
|
disp I "Archive extracted successfully in subdirectory."
|
||||||
elif [[ -n ${nodir} ]]; then
|
elif [[ -n ${nodir} ]]; then
|
||||||
mv "./${dir}/"* ./ && rmdir "${dir}"
|
shopt -s nullglob
|
||||||
|
for child in "${dir}"/*; do
|
||||||
|
mv -- "$child" .
|
||||||
|
done
|
||||||
|
shopt -u nullglob
|
||||||
|
rmdir -- "${dir}"
|
||||||
disp I "Archive extracted successfully, no subdirectory needed."
|
disp I "Archive extracted successfully, no subdirectory needed."
|
||||||
else
|
else
|
||||||
# Set nullglob to ensure the array is empty if no files match
|
# Set nullglob to ensure the array is empty if no files match
|
||||||
@@ -328,7 +348,12 @@ utaz()
|
|||||||
# Check if exactly one item exists and if that item is a directory
|
# Check if exactly one item exists and if that item is a directory
|
||||||
if [[ ${#contents[@]} -eq 1 ]] && [[ -d "${contents[0]}" ]]; then
|
if [[ ${#contents[@]} -eq 1 ]] && [[ -d "${contents[0]}" ]]; then
|
||||||
# Single directory detected
|
# Single directory detected
|
||||||
mv "${contents[0]}"/* ./ && rmdir "${dir}"
|
shopt -s nullglob
|
||||||
|
for child in "${contents[0]}"/*; do
|
||||||
|
mv -- "$child" .
|
||||||
|
done
|
||||||
|
shopt -u nullglob
|
||||||
|
rmdir -- "${dir}"
|
||||||
disp I "Archive extracted successfully, no subdirectory needed."
|
disp I "Archive extracted successfully, no subdirectory needed."
|
||||||
else
|
else
|
||||||
disp I "Archive extracted successfully in subdirectory."
|
disp I "Archive extracted successfully in subdirectory."
|
||||||
@@ -356,12 +381,57 @@ export -f utaz
|
|||||||
# -1, .., -9 Compression level to use [1=fast/biggest, 9=slow/smallest]
|
# -1, .., -9 Compression level to use [1=fast/biggest, 9=slow/smallest]
|
||||||
taz()
|
taz()
|
||||||
{
|
{
|
||||||
|
_taz_compress_generic()
|
||||||
|
{
|
||||||
|
local preferred="$1" fallback="$2" thread_arg="$3" threads="$4" level="$5" verbose="$6" file="$7" message="$8"
|
||||||
|
local cmd='' procopt=()
|
||||||
|
|
||||||
|
if [[ -n "$message" ]]; then
|
||||||
|
disp W "$message"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if command -v -- "$preferred" >/dev/null 2>&1; then
|
||||||
|
cmd="$preferred"
|
||||||
|
elif [[ -n "$fallback" ]] && command -v -- "$fallback" >/dev/null 2>&1; then
|
||||||
|
cmd="$fallback"
|
||||||
|
if [[ $threads -gt 1 ]]; then
|
||||||
|
disp W "${fallback} doesn't support multithreading, falling back to 1 thread."
|
||||||
|
disp W "Consider installing ${preferred} for multithreading abilities."
|
||||||
|
threads=1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
disp E "Program '${preferred}' or '${fallback}' are not installed, aborting."
|
||||||
|
return 127
|
||||||
|
fi
|
||||||
|
|
||||||
|
# build command line options
|
||||||
|
if [[ -n "$thread_arg" ]] && [[ $threads -gt 0 ]]; then
|
||||||
|
procopt+=("$thread_arg" "$threads")
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -n "$verbose" ]]; then
|
||||||
|
procopt+=("$verbose")
|
||||||
|
fi
|
||||||
|
|
||||||
|
# special behaviour for xz and lzop:
|
||||||
|
if [[ "$cmd" == "xz" ]]; then
|
||||||
|
"$cmd" "${procopt[@]}" --compress --keep -"$level" "$file"
|
||||||
|
return $?
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$cmd" == "lzop" ]] && [[ $threads -gt 1 ]]; then
|
||||||
|
disp W "lzop doesn't support multithreading, falling back to 1 thread."
|
||||||
|
threads=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
"$cmd" "${procopt[@]}" --keep -"$level" "$file"
|
||||||
|
return $?
|
||||||
|
}
|
||||||
|
|
||||||
_doxz()
|
_doxz()
|
||||||
{
|
{
|
||||||
command -v xz >/dev/null 2>&1 || {
|
_taz_compress_generic "xz" "" "-T" "$2" "$3" "$4" "$1" "xz format is not suited for long term archiving. See https://www.nongnu.org/lzip/xz_inadequate.html for details."
|
||||||
disp E "The program 'xz' is not installed, aborting."
|
}
|
||||||
return 127
|
|
||||||
}
|
|
||||||
|
|
||||||
[[ $4 ]] && local verb='-v'
|
[[ $4 ]] && local verb='-v'
|
||||||
|
|
||||||
@@ -376,89 +446,22 @@ taz()
|
|||||||
|
|
||||||
_dolz()
|
_dolz()
|
||||||
{
|
{
|
||||||
local procopt="--threads $2"
|
_taz_compress_generic "plzip" "lzip" "--threads" "$2" "$3" "$4" "$1" ""
|
||||||
local command=plzip
|
|
||||||
|
|
||||||
command -v plzip >/dev/null 2>&1 || {
|
|
||||||
command -v lzip >/dev/null 2>&1 || {
|
|
||||||
disp E "Program 'plzip' or 'lzip' are not installed, aborting."
|
|
||||||
return 127
|
|
||||||
}
|
|
||||||
command=lzip
|
|
||||||
local procopt=""
|
|
||||||
[[ $2 -gt 1 ]] &&
|
|
||||||
disp W "lzip doesn't support multithreading, falling back to 1 thread." &&
|
|
||||||
disp W "Consider installing plzip to obtain multithreading abilities."
|
|
||||||
}
|
|
||||||
|
|
||||||
[[ $4 ]] && local verb="-vv"
|
|
||||||
|
|
||||||
# Compresse au format lzip (lzma)
|
|
||||||
$command $verb $procopt --keep -$3 $1
|
|
||||||
return $?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_dogz()
|
_dogz()
|
||||||
{
|
{
|
||||||
local procopt="--processes $2"
|
_taz_compress_generic "pigz" "gzip" "--processes" "$2" "$3" "$4" "$1" ""
|
||||||
local command=pigz
|
|
||||||
|
|
||||||
command -v pigz >/dev/null 2>&1 || {
|
|
||||||
command -v gzip >/dev/null 2>&1 || {
|
|
||||||
disp E "Programs 'pigz' or 'gzip' are not installed, aborting."
|
|
||||||
return 127
|
|
||||||
}
|
|
||||||
local command="gzip --compress"
|
|
||||||
local procopt=""
|
|
||||||
[[ $2 -gt 1 ]] &&
|
|
||||||
disp W "gzip doesn't support multithreading, falling back to 1 thread." &&
|
|
||||||
disp W "Consider installing pigz to obtain multithreading abilities."
|
|
||||||
}
|
|
||||||
|
|
||||||
[[ $4 ]] && local verb="--verbose"
|
|
||||||
|
|
||||||
# Compresse au format bz2
|
|
||||||
$command $verb $procopt --keep -$3 $1
|
|
||||||
return $?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_dobz2()
|
_dobz2()
|
||||||
{
|
{
|
||||||
local procopt="-p$2"
|
_taz_compress_generic "pbzip2" "bzip2" "-p" "$2" "$3" "$4" "$1" ""
|
||||||
local command=pbzip2
|
|
||||||
|
|
||||||
command -v pbzip2 >/dev/null 2>&1 || {
|
|
||||||
command -v bzip2 >/dev/null 2>&1 || {
|
|
||||||
disp E "The program 'pbzip2' or 'bzip2' are not installed, aborting."
|
|
||||||
return 127
|
|
||||||
}
|
|
||||||
local command=bzip2
|
|
||||||
local procopt=""
|
|
||||||
[[ $2 -gt 1 ]] &&
|
|
||||||
disp W "bzip2 doesn't support multithreading, falling back to 1 thread." &&
|
|
||||||
disp W "Consider installing pbzip2 to obtain multithreading abilities."
|
|
||||||
}
|
|
||||||
|
|
||||||
[[ $4 ]] && local verb="-v"
|
|
||||||
|
|
||||||
# Compresse au format bz2
|
|
||||||
$command $verb --compress $procopt --keep -$3 $1
|
|
||||||
return $?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_dolzo()
|
_dolzo()
|
||||||
{
|
{
|
||||||
command -v lzop >/dev/null 2>&1 || {
|
_taz_compress_generic "lzop" "" "" "$2" "$3" "$4" "$1" ""
|
||||||
disp E "The program 'lzop' is not installed, aborting."
|
|
||||||
return 127
|
|
||||||
}
|
|
||||||
|
|
||||||
[[ $4 ]] && local verb='-v'
|
|
||||||
[[ $2 -gt 1 ]] && disp W "lzop doesn't support multithreading, falling back to 1 thread."
|
|
||||||
|
|
||||||
# Compresse au format lzo
|
|
||||||
lzop --keep -$3 $1
|
|
||||||
return $?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local PARSED
|
local PARSED
|
||||||
|
|||||||
Reference in New Issue
Block a user