-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextract
executable file
·80 lines (70 loc) · 1.87 KB
/
extract
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
#
# Extract from an archive (optionally compressed) with full path
#
# May 2014, yaswant.pradhan
# -----------------------------------------------------------------------------
usage() {
cat <<EOF
usage:
${0##*/} filename
Supported file types auto-detected by file extension:
.bz2, .tar.bz2, .tbz2, .tbz:
bzip2 compressed file or archive -> b[un]zip2 or tar.
.gz, .tar.gz, .tgz:
GNU zip (gzip) compressed file or archive -> parallel gzip (pigz)
or tar.
.pax: portable archive exchange (POSIX) archive -> tar or pax.
.rar: Roshal Archive (aproprietary archive file format) using unrar.
.tar: tape archive (tar) -> tar.
.xz, .lzma:
general-purpose data compression with a high compression ratio.
.zip: ZIP archive (MS-DOS) -> [un]xz.
.Z: adaptive Lempel-Ziv coding compress file -> [un]compress.
.7z: general-purpose data compression supports many compression methods
(LZMA[2], PPDM, BCJ[2], BZip2, Deflate) used by other compression
tools to compress data.
EOF
}
[ $# -lt 1 ] && usage && exit
command -v unrar &>/dev/null || export PATH=$PATH:~fra6/pkg/rar
# Extract file/archive:
if [ -f "$1" ]; then
case $1 in
*.tar.bz2 | *.tbz2 | *.tbz)
tar xvjf "$1"
;;
*.tar.gz | *.tgz)
tar xvf "$1" -I /usr/bin/pigz --totals
;;
*.tar | *.pax | *.tar.xz)
tar xvf "$1"
;;
*.bz2)
bunzip2 "$1"
;;
*.gz)
pigz -dk "$1"
;;
*.xz | *.lzma)
xz -dk "$1"
;;
*.zip)
unzip "$1"
;;
*.Z)
uncompress "$1"
;;
*.rar)
unrar x "$1"
;;
*.7z)
~fra6/pkg/7zip/bin/7z x "$1"
;;
*)
printf "%s: '%s' cant be restored.\n" "${0##*/}" "$1" && exit 2
;;
esac
else
printf "%s: Error: %s is not a valid file.\n" "${0##*/}" "$1" && exit 1
fi