1
0
Fork 0
mirror of synced 2024-05-26 20:11:12 -04:00

archive: fix styling

This commit is contained in:
Enno Nagel 2018-11-05 21:28:30 -03:00
parent 40f1701530
commit b39e9610a1

View file

@ -2,47 +2,56 @@
# Creates archive files # Creates archive files
# #
archive() { # compress a file or folder archive() {
local name="${1%.[^.]*}" local name="${1%.[^.]*}"
local type="${1##*.}" local type="${1##*.}"
local input="$2" shift
local files="${@}"
if [ "$#" -eq 1 ]; then if [ -z "${#}" ]; then
echo "archive(): archive a file or directory." echo "archive(): archive a file or directory."
echo "Usage: archive <archive> <files>" echo "Usage: archive <archive> <files>"
echo "Error: Please give a valid file or directory name!" echo "Error: Please give a valid file or directory name!"
return 1 return 1
fi fi
# we are quitting (above) if there is only 1 var
if [ -f "${name}.${type}" ]; then if [ -f "${name}.${type}" ]; then
echo "archive(): file ${name}.${type} already exists." echo "archive(): file ${name}.${type} already exists."
name=$(mktemp --dry-run "./${name}_XXX.${type}") name=$(mktemp --dry-run "./${name}_XXX.${type}")
echo "archive(): using ${name}.${type} instead." echo "archive(): using ${name}.${type} instead."
fi fi
case "$type" in # ensure xz uses all available CPU cores by additional options
tar) shift; tar cvf "${name}.tar" "${@%%}" ;;
tbz|tar.bz) shift; tar cvjf "${name}.tar.bz2" "${@%}" ;; case "${type}" in
tbz2|tar.bz2) shift; tar cvjf "${name}.tar.bz2" "${@%%}" ;; tar) shift; tar cvf "${name}.tar" ${files} ;;
txz|tar.xz) shift; env XZ_OPT=-T0 tar cvJf "${name}.tar.xz" "${@%%}" ;; tbz|tar.bz) shift; tar cvjf "${name}.tar.bz2" ${files} ;;
tgz|tar.gz) shift; tar cvzf "${name}.tar.gz" "${@%%}" ;; tbz2|tar.bz2) shift; tar cvjf "${name}.tar.bz2" ${files} ;;
tZ|tar.Z) shift; tar cvZf "${name}.tar.Z" "${@%%}" ;; txz|tar.xz) shift; env XZ_OPT=-T0 tar cvJf "${name}.tar.xz" ${files} ;;
gz|gzip) shift; gzip -vcf "${@%%}" > "${name}.gz" ;; tgz|tar.gz) shift; tar cvzf "${name}.tar.gz" ${files} ;;
bz|bzip) shift; bzip2 -vcf "${@%%}" > "${name}.bz" ;; tZ|tar.Z) shift; tar cvZf "${name}.tar.Z" ${files} ;;
bz2|bzip2) shift; bzip2 -vcf "${@%%}" > "${name}.bz2" ;; gz|gzip) shift; gzip -vcf ${files} > "${name}.gz" ;;
Z|compress) shift; compress -vcf "${@%%}" > "${name}.Z" ;; bz|bzip) shift; bzip2 -vcf ${files} > "${name}.bz" ;;
zip) shift; zip -rull "${name}.zip" "${@%%}" ;; bz2|bzip2) shift; bzip2 -vcf ${files} > "${name}.bz2" ;;
7z|7zip) shift; 7z u "${name}.7z" "${@%%}" ;; Z|compress) shift; compress -vcf "${files}" > "${name}.Z" ;;
rar) shift; rar a "${name}.rar" "${@%%}" ;; zip) shift; zip -rull "${name}.zip" ${files} ;;
lzo) shift; lzop -vc "${@%%}" > "${name}.lzo" ;; 7z|7zip) shift; 7z u "${name}.7z" ${files} ;;
xz) shift; xz -vc -T0 "${@%%}" > "${name}.xz" ;; rar) shift; rar a "${name}.rar" ${files} ;;
lzma) shift; lzma -vc "${@%%}" > "${name}.lzma" ;; lzo) shift; lzop -vc ${files} > "${name}.lzo" ;;
xz) shift; xz -vc -T0 ${files} > "${name}.xz" ;;
lzma) shift; lzma -vc ${files} > "${name}.lzma" ;;
*) echo "archive(): archive a file or directory." *) echo "archive(): archive a file or directory."
echo "Usage: archive <archive> <files>" echo "Usage: archive <archive> <files>"
echo "Example: archive file.tbz2 file.txt file.png" echo "Example: archive file.tbz2 file.txt file.png"
echo "Please specify archive and files." echo "Please specify archive and files."
echo "Valid archive file extensions are:" echo "Valid archive file extensions are:"
echo "tar, tbz2, txz, tgz, tZ, gz, bz2, Z," echo "tar, tbz2, txz, tgz, tZ, gz, bz2, Z,"
echo "zip, 7z, rar, lzo, xz, and lzma." ;; echo "zip, 7z, rar, lzo, xz, and lzma."
echo "Note: .gz, .bzip2, .xz and .lzma only"
echo "accept a single file and no directories!"
echo "Use tar instead for multiple files and "
echo "other compression algorithms for directories." ;;
esac esac
} }