-
Notifications
You must be signed in to change notification settings - Fork 1
/
dtrx
executable file
·60 lines (58 loc) · 1.35 KB
/
dtrx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/sh
#
# NAME
#
# dtrx - extract archives
#
# SYNOPSIS
#
# dtrx <file>...
#
# DESCRIPTION
#
# Extract archives of different formats. Named after the similar,
# more featureful, Python script called "Do The Right Extraction". 7z
# (from the Debian package p7zip-full) can also extract archives of
# different formats. But 7z is not always available, ergo this
# script.
#
# DEPENDENCIES
#
# GNU tar(1), unzip(1), 7z(1), ar(1), unrar(1)
#
# SEE ALSO
#
# dtrx (https://brettcsmith.org/2007/dtrx/)
#
[ "$*" ] || {
echo >&2 "usage: ${0##*/} <file>..."
exit 1
}
for arg
do
if [ -f "$arg" ]
then
# 7z can extract almost all kinds of files, but use 7z as a last
# resort since it is not always installed.
case "$arg" in
*.ar|*.deb)
ar xv "$arg" ;;
*.rar)
unrar x "$arg" ;;
*.zip)
unzip "$arg" ;;
*)
# If it is not an extension we do not recognize, try
# extracting it using GNU tar, or if that fails, use 7z.
if tar atvf "$arg" >/dev/null 2>&1
then
tar axvf "$arg"
else
7z x "$arg"
fi
;;
esac
else
echo >&2 "${0##*/}: '$arg' is not a valid file!"
fi
done