-
Notifications
You must be signed in to change notification settings - Fork 4
/
extract
executable file
·50 lines (42 loc) · 881 Bytes
/
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
#!/bin/bash
for args in "$@"
do
fname=$(readlink -f "$args")
bname=$(basename "$fname")
dest1st=${bname%.*}
dest2nd=${dest1st%.*}
case "$bname" in
*.tar.gz | *.tar.bz2 | *.tar.xz | *.tar.7z)
destdir=${dest2nd};;
*)
destdir=${dest1st};;
esac
mkdir "$destdir"
if [ "$?" != "0" ]
then
echo Directory creating failed.
exit 1
fi
cd "$destdir"
case "$bname" in
*.tar.bz2 | *.tarbz2 | *.tbz2)
tar xvjf "$fname";;
*.tar.gz | *.targz | *.tgz)
tar xvzf "$fname";;
*.tar.xz | *.tarxz | *.txz)
tar xvJf "$fname";;
*.tar.7z | *.tar7z | *.t7z)
7z x -so "$fname" | tar xf -;;
*.zip | *.ZIP)
LANG=C 7z x "$fname"
fenc=$(find ./ -type f |enca -L zh -i)
[ "$?" = "0" ] && [ "$fenc" != "ASCII" ] && \
eval convmv -f $fenc -t UTF-8 --notest -r *;;
*.deb)
ar x "$fname";;
*)
7z x "$fname";;
esac
cd "$OLDPWD"
done
exit 0