Skip to content

Commit ad138ab

Browse files
uniunpack: universal unpacker for Linux
In case you are too lazy to remember the names and the flags of the appropriate utilities Supports *.tar|*.tbz|*.txz|*.tgz|*.tar.bz2|*.tar.gz|*.tar.xz|*.tar.lz|*.rar|*.7z|*.bz2|*.gz|*.xz|*.zip|*.cpio
1 parent 2fe0006 commit ad138ab

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

uniunpack

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#! /bin/sh
2+
3+
# Universal Unpacker by Artem S. Tashkinov
4+
# v1.4.0 Oct 18 15:35 2014: total rewrite; proper gzip support; no command output :(
5+
# v1.4.1 Oct 26 13:20 2014: file extension normalized
6+
# v1.4.2 Nov 4 04:29 2014: use RAR by default, use -r- for RAR, BASH->SH
7+
# v1.4.3 Mar 7 22:02 2015: use UNRAR by default
8+
# v1.4.4 Tue 05 Nov 2019 01:18:27: prefer p7zip for zip archives
9+
10+
test -z "$1" && echo "Need an archive name to proceed" && exit 1
11+
test ! -e "$1" && echo "File '$1' doesn't exist" && exit 1
12+
13+
lower=$(echo "$1" | tr A-Z a-z)
14+
15+
case "$lower" in
16+
*.tar|*.tbz|*.txz|*.tgz|*.tar.bz2|*.tar.gz|*.tar.xz|*.tar.lz)
17+
tar xf "$1"
18+
;;
19+
*.rar)
20+
unrar x -r- "$1"
21+
;;
22+
*.7z)
23+
7z x "$1"
24+
;;
25+
*.bz2)
26+
bzip2 -kd "$1"
27+
;;
28+
*.gz)
29+
gunzip "$1"
30+
;;
31+
*.xz)
32+
xz -dk "$1"
33+
;;
34+
*.zip)
35+
if 7z &> /dev/null; then
36+
7z x "$1"
37+
else
38+
unzip "$1"
39+
fi
40+
;;
41+
*.cpio)
42+
cpio -i -m -d -F "$1"
43+
;;
44+
*)
45+
echo "The archive type for '$1' is unknown"
46+
echo -n "Would you like to try unpacking the archive using 7z (y/n)? "
47+
read answer
48+
test "$answer" = "Y" -o "$answer" = "y" && 7z x "$1"
49+
;;
50+
esac
51+
52+
res=$?
53+
test "$res" -ne 0 && echo "WARNING: Unpacking failed!"
54+
exit "$res"

0 commit comments

Comments
 (0)