huge longrun improvements
This commit is contained in:
@@ -35,8 +35,13 @@
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Smartly uncompress archives (zip only for now)
|
||||
# ------------------------------------------------------------------------------
|
||||
# Smartly uncompress archives
|
||||
# Usage: utaz [option] [directorie(s)|file(s)]
|
||||
# Options:
|
||||
# -h, --help Display that help screen
|
||||
# -d, --delete If decompression succeeded, delete the source file
|
||||
# -c, --create-dir Always create a host directory
|
||||
# -n, --no-dir Never create a host directory
|
||||
utaz()
|
||||
{
|
||||
_ununzip()
|
||||
@@ -136,53 +141,73 @@ utaz()
|
||||
rpm2cpio "$1" | (cd "$2/" && cpio -idmv) >/dev/null 2>&1
|
||||
}
|
||||
|
||||
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
|
||||
local PARSED=$(getopt -o hdcn --long help,delete,create-dir,no-dir -n 'utaz' -- "$@")
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
disp E "Invalid options, use \"utaz --help\" to display usage."
|
||||
return 1
|
||||
fi
|
||||
eval set -- "$PARSED"
|
||||
while true; do
|
||||
case "$1" in
|
||||
-h|--help)
|
||||
printf "utaz: uncompress all the given files and/or the ones found in the given\n"
|
||||
printf " directories creating an host directory where needed.\n\n"
|
||||
printf "Usage: utaz [option] [directorie(s)|file(s)]\n\n"
|
||||
printf "Options:\n"
|
||||
printf "\t-h, --help\t\tDisplay that help screen\n"
|
||||
printf "\t-d, --delete\t\tIf decompression succeeded, delete the source file\n"
|
||||
printf "\t-c, --create-dir\tAlways create a host directory\n"
|
||||
printf "\t-n, --no-dir\t\tNever create a host directory\n\n"
|
||||
printf "Supported archive format:\n"
|
||||
printf "\t- zip\n"
|
||||
printf "\t- tar.gz, .tgz\n"
|
||||
printf "\t- tar.bz2, .tbz2\n"
|
||||
printf "\t- tar.xz, .txz\n"
|
||||
printf "\t- tar.lz, .tlz\n"
|
||||
printf "\t- rar\n"
|
||||
printf "\t- arj\n"
|
||||
printf "\t- lha, lzh\n"
|
||||
printf "\t- ace\n"
|
||||
printf "\t- 7z, p7z\n"
|
||||
printf "\t- zst\n"
|
||||
printf "\t- cpio\n"
|
||||
printf "\t- cab\n"
|
||||
printf "\t- deb\n"
|
||||
printf "\t- rpm\n"
|
||||
return 0
|
||||
;;
|
||||
|
||||
"-d" | "--delete")
|
||||
-d|--delete)
|
||||
local willrm=1
|
||||
shift
|
||||
;;
|
||||
|
||||
"-c" | "--create-dir")
|
||||
-c|--create-dir)
|
||||
local createdir=1
|
||||
shift
|
||||
;;
|
||||
|
||||
"-n" | "--no-dir")
|
||||
-n|--no-dir)
|
||||
local nodir=1
|
||||
shift
|
||||
;;
|
||||
|
||||
"-"*)
|
||||
disp E "Invalid option, use \"utaz --help\" to display options list"
|
||||
echo
|
||||
return 1
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
|
||||
*)
|
||||
# The ${opt%/} writing is to remove trailing / if any
|
||||
local LIST="${LIST} ${opt%/}"
|
||||
disp E "Invalid option, use \"utaz --help\" to display options list"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
# The remaining arguments after -- are the files/directories to process,
|
||||
# "." is used if none is given
|
||||
local FILES=("$@")
|
||||
[[ ${#FILES[@]} -eq 0 ]] && FILES=(".")
|
||||
|
||||
[[ -n ${createdir} && -n ${nodir} ]] && \
|
||||
disp E "The --create-dir and --no-dir options are mutually exclusive."
|
||||
|
||||
[[ -z ${LIST} ]] && local LIST="."
|
||||
for zitem in ${LIST}; do
|
||||
for zitem in "${FILES[@]}"; do
|
||||
for f in "${zitem}"/*; do
|
||||
local dir="${f%.*}"
|
||||
local extractor=""
|
||||
@@ -193,13 +218,13 @@ utaz()
|
||||
*.tar.gz|*.tgz)
|
||||
extractor="_ungzip"
|
||||
;;
|
||||
*.tar.bz2)
|
||||
*.tar.bz2|*.tbz2)
|
||||
extractor="_unbzip2"
|
||||
;;
|
||||
*.tar.xz)
|
||||
*.tar.xz|*.txz)
|
||||
extractor="_unxz"
|
||||
;;
|
||||
*.tar.lz)
|
||||
*.tar.lz|*.tlz)
|
||||
extractor="_unlzop"
|
||||
;;
|
||||
*.tar)
|
||||
@@ -217,7 +242,7 @@ utaz()
|
||||
*.ace)
|
||||
extractor="_ununace"
|
||||
;;
|
||||
*.7z)
|
||||
*.7z|*.p7z)
|
||||
extractor="_un7z"
|
||||
;;
|
||||
*.zst)
|
||||
@@ -277,10 +302,14 @@ utaz()
|
||||
rm -f "${f}" && disp I "File ${zitem}/${f} deleted."
|
||||
;;
|
||||
1)
|
||||
disp W "Compression program returned a warning: deletion canceled."
|
||||
if [[ -n ${willrm} ]]; then
|
||||
disp W "Compression program returned a warning: deletion canceled."
|
||||
else
|
||||
disp W "Compression program returned a warning."
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
disp E "The zip file seems corrupted, failed."
|
||||
disp E "The compressed file ${f} seems corrupted, failed."
|
||||
rm -rf "${dir}" >/dev/null 2>&1
|
||||
continue
|
||||
;;
|
||||
@@ -310,10 +339,21 @@ utaz()
|
||||
done
|
||||
}
|
||||
export -f utaz
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Compress directories or files into one or more archive
|
||||
# ------------------------------------------------------------------------------
|
||||
# Usage: taz [option] [--parallel=<n>] [--format=<format>] [directory1 ... directoryN]
|
||||
# Options:
|
||||
# -h, --help Display that help screen
|
||||
# -d, --delete Delete source file or directory after success
|
||||
# -f, --format Chose archive format in the given list. If several format are
|
||||
# given, the smalest is kept
|
||||
# -p, --parallel Number of threads to use (if allowed by underlying utility)
|
||||
# -v, --verbose Display progress where possible
|
||||
# -q, --quiet Display less messages (only errors and warnings)
|
||||
# -1, .., -9 Compression level to use [1=fast/biggest, 9=slow/smallest]
|
||||
taz()
|
||||
{
|
||||
_doxz()
|
||||
@@ -421,78 +461,92 @@ taz()
|
||||
return $?
|
||||
}
|
||||
|
||||
for opt in $@; do
|
||||
case $opt in
|
||||
"-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
|
||||
local PARSED
|
||||
PARSED=$(getopt -o hdf:p:vq123456789 --long help,delete,format:,parallel:,verbose,quiet --name "taz" -- "$@")
|
||||
if [ $? -ne 0 ]; then
|
||||
disp E "Invalid options, use \"taz --help\" to display usage."
|
||||
return 1
|
||||
fi
|
||||
eval set -- "$PARSED"
|
||||
while true; do
|
||||
case "$1" in
|
||||
-h|--help)
|
||||
printf "taz: archive all files of a directory.\n\n"
|
||||
printf "Usage: taz [option] [--parallel=<n>] [--format=<format>] [directory1 ... directoryN]\n\n"
|
||||
printf "Options:\n"
|
||||
printf "\t-h, --help\tDisplay that help screen\n"
|
||||
printf "\t-d, --delete\tDelete source file or directory after success\n"
|
||||
printf "\t-f, --format\tChose archive format in the given list. If several format are"
|
||||
printf "\t\t\tgiven, the smalest is kept\n"
|
||||
printf "\t-p, --parallel\tNumber of threads to use (if allowed by underlying utility)\n"
|
||||
printf "\t-v, --verbose\tDisplay progress where possible\n"
|
||||
printf "\t-q, --quiet\tDisplay less messages (only errors and warnings)\n"
|
||||
printf "\t-1, .., -9\tCompression level to use [1=fast/biggest, 9=slow/smallest]\n\n"
|
||||
printf "Supported archive format:\n"
|
||||
printf "\tParam.| programs | Algo. | Description\n"
|
||||
printf "\t------+---------------+-------+----------------------------------------\n"
|
||||
printf "\t lz | plzip, lzip | lzma | Safe efficient default format\n"
|
||||
printf "\t xz | xz | lzma2 | Unsafe, not for long term\n"
|
||||
printf "\t bz2 | pbzip2, bzip2 | bzip2 | Historical but less efficient than lz\n"
|
||||
printf "\t gz | pigz, gzip | lz77 | Historical, safe, fast\n"
|
||||
printf "\t lzo | lzop | lzo | Very fast but no multithread\n"
|
||||
printf "\t tar | tar | tar | No compression\n"
|
||||
printf "\n"
|
||||
return 0
|
||||
;;
|
||||
|
||||
"-d" | "--delete")
|
||||
-d|--delete)
|
||||
local willrm=1
|
||||
shift
|
||||
;;
|
||||
|
||||
"-f"?* | "--format"?*)
|
||||
local compform=$(echo "$opt" | cut -f 2- -d '=')
|
||||
-f|--format)
|
||||
local compform=$2
|
||||
shift 2
|
||||
;;
|
||||
|
||||
"-p"?* | "--parallel"?*)
|
||||
local nproc=$(echo "$opt" | cut -f 2- -d '=')
|
||||
-p|--parallel)
|
||||
local nproc=$2
|
||||
shift 2
|
||||
;;
|
||||
|
||||
"-v" | "--verbose")
|
||||
-v|--verbose)
|
||||
local verbose=1
|
||||
shift
|
||||
;;
|
||||
|
||||
"-q" | "--quiet")
|
||||
-q|--quiet)
|
||||
local quiet=1
|
||||
shift
|
||||
;;
|
||||
|
||||
"-"*)
|
||||
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
|
||||
-[1-9])
|
||||
compression="${1#-}"
|
||||
shift
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
|
||||
*)
|
||||
local LIST="$LIST ${opt%/}"
|
||||
disp E "Invalid option, use \"taz --help\" to display options list"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# The remaining arguments after -- are the files/directories to process,
|
||||
# "." is used if none is given
|
||||
local FILES=("$@")
|
||||
[[ ${#FILES[@]} -eq 0 ]] && FILES=(".")
|
||||
|
||||
[[ ! $compform ]] && compform=lz # safe and efficient (unless data are already compressed)
|
||||
[[ ! $nproc ]] && nproc=1
|
||||
[[ ! $complevel ]] && complevel=6
|
||||
[[ $verbose -gt 1 && $quiet -gt 1 ]] &&
|
||||
disp E "The --verbose and --quiet options can't be used together."
|
||||
|
||||
for item in $LIST; do
|
||||
for item in "${FILES[@]}"; do
|
||||
local donetar=0
|
||||
disp I "Processing $item..."
|
||||
|
||||
@@ -537,6 +591,7 @@ taz()
|
||||
unset quiet
|
||||
}
|
||||
export -f taz
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
# EOF
|
||||
|
||||
Reference in New Issue
Block a user