3
# Copyright (C) 2013, 2023 Etersoft
4
# Copyright (C) 2013, 2023 Vitaly Lipatov <lav@etersoft.ru>
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU Affero General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU Affero General Public License for more details.
16
# You should have received a copy of the GNU Affero General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
23
[ -n "$use_7z" ] && return 1
24
[ -n "$use_patool" ] || is_command patool
31
[ "$ERC_BACKEND" = "patool" ] && use_patool=1
32
[ "$ERC_BACKEND" = "7z" ] && use_7z=1
34
[ -n "$use_patool" ] && [ -n "$use_7z" ] && fatal "Don't use --use-7z and --use-patool simulateously."
36
if [ -n "$use_7z" ] || ! have_patool ; then
37
# TODO: try install patool and p7zip
38
is_command 7za && HAVE_7Z='7za'
39
if ! is_command $HAVE_7Z ; then
41
is_command 7zz && HAVE_7Z='7zz'
43
if ! is_command $HAVE_7Z ; then
45
is_command 7zr && HAVE_7Z='7zr'
47
is_command $HAVE_7Z || fatal "Could not find any patool or 7-zip backend. Please install p7zip package and retry."
49
[ -z "$force" ] || HAVE_7Z="$HAVE_7Z -y"
56
for i in gz bz2 xz bzip2 lz4 lzma zst zstd ; do
60
for i in gz bz2 xz lz4 ; do
80
# it is extension list really
81
# list all supported formats: tar rar and so on
86
a='' patool formats | grep ".* files:" | sed "s/ .*//g"
88
echo "tar zip 7z tar.7z"
91
# TODO: do not use patool formats in such case?
92
# See ArchiveCompressions in patool
96
# returns true if arg is XXX: from list_formats
99
[ "${1/:/}" = "$1" ] && return 1
100
local arc="$(echo "$1" | sed -e 's|:.*||g')"
101
list_formats | grep -q "^$arc$" && return 0
105
# TODO: detect by name, without comparing with existing?
110
for i in $(list_formats) ; do
111
[ -z "${1/*.$i/}" ] && echo "$i" && return
120
ext=$(get_archive_ext "$1")
121
if [ -n "$ext" ] ; then
122
echo $(dirname "$1")/$(basename "$1" .$ext)
132
file --mime-type "$1" | grep -q "text/" && echo "plain" && return
133
file "$1" | grep -q "empty" && echo "plain" && return
139
# TODO: detect by extension as default
143
if [ -r "$1" ] ; then
144
# TODO: rewrite with mime
145
file "$1" | grep -q "Zip archive data" && echo "zip" && return
146
file "$1" | grep -q "RAR archive data" && echo "rar" && return
147
# used for unexists files too
149
# warning "Couldn't read $1, skipping mime checking"
152
if aext=$(get_archive_ext "$1") ; then