-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunpack
executable file
·48 lines (39 loc) · 1.07 KB
/
unpack
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
#!/bin/bash
set -e
filename=$(basename "$1")
filepath=$(dirname "$1")
fileinfo=$(file -i "$1")
cd "$filepath"
destination="${filename%.*}-unpacked"
# zip
if [[ $fileinfo =~ "application/zip" ]]; then
mkdir "$destination"
unzip "$filename" -d "$destination"
echo "Extracted file to $destination"
#gzip
elif [[ $fileinfo =~ "application/gzip" ]]; then
gzip -dk "$filename"
#bzip2
elif [[ $fileinfo =~ "application/x-bzip2" ]]; then
bzip2 -dk "$filename"
#bzip
elif [[ $fileinfo =~ "application/x-bzip" ]]; then
bzip -dk "$filename"
#rar
elif [[ $fileinfo =~ "application/x-rar" || $fileinfo =~ "application/vnd.rar" ]]; then
mkdir "$destination"
unrar x "$filename" "$destination"
echo "Extracted file to $destination"
#tar
elif [[ $fileinfo =~ "application/x-tar" ]]; then
mkdir "$destination"
tar -xvf "$filename" -C "$destination"
echo "Extracted file to $destination"
#7zip
elif [[ $fileinfo =~ "application/x-7z-compressed" ]]; then
mkdir "$destination"
7za e "$filename" -o"$destination"
echo "Extracted file to $destination"
else
echo "Unknown compression!"
fi