bash : pack : add support for iso unpacking.

This commit is contained in:
Dmitry Voronin 2023-11-03 21:28:11 +03:00
parent 992b570071
commit ea4a7bba3e

View file

@ -1,4 +1,4 @@
_PACK_SUPPORTED=".tar$|.zip$" _UNPACK_SUPPORTED=".tar$|.tgz$|.txz$|.zip$|.iso$"
# Pack files into desired format. # Pack files into desired format.
# Usage: pack <TARGET.ext> <FILES> # Usage: pack <TARGET.ext> <FILES>
@ -63,7 +63,7 @@ unpack()
# show error if no target specified. # show error if no target specified.
if [[ "${targets}" = "" ]]; then if [[ "${targets}" = "" ]]; then
targets=($(ls | grep -E ${_PACK_SUPPORTED})) targets=($(ls | grep -E ${_UNPACK_SUPPORTED}))
total=${#targets[@]} total=${#targets[@]}
fi fi
@ -98,6 +98,9 @@ unpack()
"tar") "tar")
_unpack_tar "${target}" _unpack_tar "${target}"
;; ;;
"iso")
_unpack_iso "${target}"
;;
*) *)
echo "${target}: format not supported." echo "${target}: format not supported."
return 2 return 2
@ -154,32 +157,38 @@ _pack_tar()
# unpack zip archive. # unpack zip archive.
_unpack_zip() _unpack_zip()
{ {
unzip "${1}" unzip "${@}"
} }
# unpack 7z archive. # unpack 7z archive.
_unpack_7z() _unpack_7z()
{ {
7z x "${1}" 7z x "${@}"
} }
# unpack tgz archive. # unpack tgz archive.
_unpack_tgz() _unpack_tgz()
{ {
pv "${1}" | gzip -d | tar -xf - pv "${@}" | gzip -d | tar -xf -
} }
# unpack txz archive. # unpack txz archive.
_unpack_txz() _unpack_txz()
{ {
pv "${1}" | xz -d | tar -xf - pv "${@}" | xz -d | tar -xf -
} }
# unpack tar archive. # unpack tar archive.
_unpack_tar() _unpack_tar()
{ {
pv "${1}" | tar -xf - pv "${@}" | tar -xf -
}
# unpack iso image.
_unpack_iso()
{
7z x "${@}"
} }
# export functions. # export functions.
export -f pack unpack _pack_tgz _pack_txz _pack_tar _pack_zip _unpack_zip _unpack_7z _unpack_tgz _unpack_txz _unpack_tar _pack_error export -f pack unpack _pack_tgz _pack_txz _pack_tar _pack_zip _unpack_zip _unpack_7z _unpack_tgz _unpack_txz _unpack_tar _pack_error _unpack_iso