zimfw/modules/archive/functions/archive

35 lines
1.5 KiB
Bash

# vim:et sts=2 sw=2 ft=zsh
#
# Creates archive files
#
if (( # < 2 )); then
print "usage: ${0} <archive_name.ext> <file>..." >&2
return 1
fi
# we are quitting (above) if there are less than 2 vars,
# so we don't need any argc check here.
local archive_name="${1}"
shift
# pigz and pbzip2 are aliased in the init.zsh file. This provides a significant speedup, resulting in a
# near-liner decrease in compression time based on on the number of available cores.
case "${archive_name}" in
(*.tar.gz|*.tgz) tar -cvzf "${archive_name}" "${@}" ;;
(*.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar -cvjf "${archive_name}" "${@}" ;;
(*.tar.xz|*.txz) tar -J --help &>/dev/null && tar -cvJf "${archive_name}" "${@}" ;;
(*.tar.lzma|*.tlz) tar --lzma --help &>/dev/null && tar --lzma -cvf "${archive_name}" "${@}" ;;
(*.tar) tar -cvf "${archive_name}" "${@}" ;;
(*.zip) zip -r "${archive_name}" "${@}" ;;
(*.rar) rar a "${archive_name}" "${@}" ;;
(*.7z) 7za a "${archive_name}" "${@}" ;;
(*.gz) print "${0}: .gz is only useful for single files, and does not capture permissions. Use .tar.gz" ;;
(*.bz|*.bz2) print "${0}: .bzip2 is only useful for single files, and does not capture permissions. Use .tar.bz2" ;;
(*.xz) print "${0}: .xz is only useful for single files, and does not capture permissions. Use .tar.xz" ;;
(*.lzma) print "${0}: .lzma is only useful for single files, and does not capture permissions. Use .tar.lzma" ;;
(*) print "${0}: unknown archive type: ${archive_name}" ;;
esac