-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract.sh
More file actions
executable file
·77 lines (62 loc) · 1.54 KB
/
Copy pathextract.sh
File metadata and controls
executable file
·77 lines (62 loc) · 1.54 KB
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
#!/bin/zsh
function usage() {
echo "Использование: extract [/путь/к/архиву] [/путь/назначения"]
echo "Распаковывает архив в указанную папку."
echo "Аргументы:"
echo " --help Показать это сообщение и выйти"
exit 0
}
if [[ "$1" == "--help" ]]; then
usage
fi
if [[ $# -ne 2 ]] then
echo "Недостаточное количество аргументов"
fi
archive="$1"
destination="$2"
if [[ ! -f "$archive" ]] then
echo "Файла не существует"
exit 1
fi
mkdir -p "$destination"
ext=${archive##*.}
case $ext in
zip)
unzip -qq "$archive" -d "$destination"
;;
tar)
tar -xf "$archive" -C "$destination"
;;
7z)
7z x "$archive" -o "$destination"
;;
rar)
unrar x "$archive" -o "$destination"
;;
gz)
if [[ "$archive" == *.tar.gz ]]; then
tar -xzf "$archive" -C "$destination"
else
gunzip -c "$archive" > "$destination/${archive:t:r}"
fi
;;
bz2)
if [[ "$archive" == *.tar.bz2 ]]; then
tar -xjf "$archive" -C "$destination"
else
bunzip2 -c "$archive" > "$destination/${archive:t:r}"
fi
;;
xz)
if [[ "$archive" == *.tar.xz ]]; then
tar -xJf "$archive" -C "$destination"
else
unxz -c "$archive" > "$destination/${archive:t:r}"
fi
;;
*)
echo "Архив неизвестного формата"
exit 2
;;
esac
echo "Успешно! Архив распакован в $destination"