pack : add rar unpack support.

This commit is contained in:
Dmitry Voronin 2023-11-12 16:50:46 +03:00
parent a395d7aae6
commit a6dc76e1f8

View file

@ -1,4 +1,4 @@
_UNPACK_SUPPORTED=".tar$|.tgz$|.txz$|.tar.gz$|.tar.xz$|.zip$|.iso$"
_UNPACK_SUPPORTED=".tar$|.tgz$|.txz$|.tar.gz$|.tar.xz$|.zip$|.iso$|.rar$"
# Pack files into desired format.
# Usage: pack <TARGET.ext> <FILES>
@ -101,6 +101,9 @@ unpack()
"iso")
_unpack_iso "${target}"
;;
"rar")
_unpack_rar "${target}"
;;
*)
echo -e "${color_yellow}${target}: format not supported.${color_default}"
return 2
@ -124,71 +127,65 @@ unpack()
fi
}
# show error.
_pack_error()
{
echo -e "${color_bred}${1}: failed.${color_default}"
}
# Pack zip.
_pack_zip()
{
zip -9 -r "${@}"
}
# pack tgz.
_pack_tgz()
{
tar -c "${@:2}" | pv -s $(du -csb "${@:2}" | sed -n -e '$p' | awk '{print $1}') | gzip -1 > "${1}"
}
# pack txz.
_pack_txz()
{
tar -c "${@:2}" | pv -s $(du -csb "${@:2}" | sed -n -e '$p' | awk '{print $1}') | xz -9e > "${1}"
}
# pack tar.
_pack_tar()
{
tar -c "${@:2}" | pv -s $(du -csb "${@:2}" | sed -n -e '$p' | awk '{print $1}') > "${1}"
}
# unpack zip archive.
_unpack_zip()
{
unzip "${@}"
}
# unpack 7z archive.
_unpack_7z()
{
7za x "${@}"
}
# unpack tgz archive.
_unpack_tgz()
{
pv "${@}" | gzip -d | tar -xf -
}
# unpack txz archive.
_unpack_txz()
{
pv "${@}" | xz -d | tar -xf -
}
# unpack tar archive.
_unpack_tar()
{
pv "${@}" | tar -xf -
}
# unpack iso image.
_unpack_iso()
{
7za x "${@}"
}
_unpack_rar()
{
unrar x "${@}"
}
# 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 _unpack_iso
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 _unpack_rar