-
Notifications
You must be signed in to change notification settings - Fork 2
/
uniunpack
58 lines (53 loc) · 1.25 KB
/
uniunpack
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
#! /bin/sh
# Universal Unpacker by Artem S. Tashkinov
# v1.4.0 Oct 18 15:35 2014: total rewrite; proper gzip support; no command output :(
# v1.4.1 Oct 26 13:20 2014: file extension normalized
# v1.4.2 Nov 4 04:29 2014: use RAR by default, use -r- for RAR, BASH->SH
# v1.4.3 Mar 7 22:02 2015: use UNRAR by default
# v1.4.4 Tue 04 Nov 2019 01:18:27: prefer p7zip for zip archives
# v1.4.5 Fri Oct 22 2021 15:38:59: zst
test -z "$1" && echo "Need an archive name to proceed" && exit 1
test ! -e "$1" && echo "File '$1' doesn't exist" && exit 1
lower=$(echo "$1" | tr A-Z a-z)
case "$lower" in
*.tar|*.tbz|*.txz|*.tgz|*.tar.bz2|*.tar.gz|*.tar.xz|*.tar.lz|*.tar.zst)
tar xf "$1"
;;
*.rar)
unrar x -r- "$1"
;;
*.7z)
7z x "$1"
;;
*.bz2)
bzip2 -kd "$1"
;;
*.gz)
gunzip -k "$1"
;;
*.xz)
xz -dk "$1"
;;
*.zip)
if 7z &> /dev/null; then
7z x "$1"
else
unzip "$1"
fi
;;
*.cpio)
cpio -i -m -d -F "$1"
;;
*.zst)
zstd -d "$1" # --keep/-k is default
;;
*)
echo "The archive type for '$1' is unknown"
echo -n "Would you like to try unpacking the archive using 7z (y/n)? "
read answer
test "$answer" = "Y" -o "$answer" = "y" && 7z x "$1"
;;
esac
res=$?
test "$res" -ne 0 && echo "WARNING: Unpacking failed!"
exit "$res"