-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharchive.sh
executable file
·95 lines (86 loc) · 2.27 KB
/
archive.sh
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
archive_list () {
case $1 in
*.tar) tar tf "$1";;
*.tar.*) tar tf "$1";;
*.tgz) tar tf "$1";;
*.zip) unzip -l "$1";;
*.rar) 7z l "$1";;
*.7z) 7z l "$1";;
*)
echo "WTF is this? Lets try 7zip" >&2
7z l "$1"
;;
esac
}
archive_extract () {
FILENAME=$(basename "$1")
case $1 in
*.tar) tar xf "$1";;
*.tar.*) tar xf "$1";;
*.tgz) tar xf "$1";;
*.bz2) bzip2 -dc "$1" > "${FILENAME%.*}";;
*.gz) gzip -dc "$1" > "${FILENAME%.*}";;
*.xz) xz -dc "$1" > "${FILENAME%.*}";;
*.lz4) lz4 -d "$1" "${FILENAME%.*}";;
*.lzo) lzop -dp "$1";;
*.zst) zstd -d "$1" -o "${FILENAME%.*}";;
*.zip) unzip "$1";;
*.rar) 7z x "$1";;
*.7z) 7z x "$1";;
*)
echo "WTF is this? Lets try 7zip" >&2
7z x "$1"
;;
esac
}
archive_cat () {
TYPE=$(file -b "$1" | awk '{ print $1 }')
case $TYPE in
"gzip") zcat "$1";;
"bzip2") bzcat "$1";;
"XZ") xzcat "$1";;
"lzop") lzop -dcf "$1";;
"LZ4") lz4cat "$1";;
"LZMA") lzcat "$1";;
"Zstandard")zstdcat "$1";;
"PGP") gpg -d -o - "$1";;
"ASCII") cat "$1";;
"UTF-8") cat "$1";;
*)
echo "$1: unknown type ($TYPE)" >&2
;;
esac
}
if [[ $_ != "$0" ]]; then
# echo "Script is being sourced"
true # noop
else
# echo "Script is a subshell"
if [ ! -f "$1" ]; then
exit 1
fi
#
# Symlink commands
# List
if [ "$(basename "$0")" == "t" ]; then
for file in "$@"; do
archive_list "$file"
done
exit 0
fi
# Extract
if [ "$(basename "$0")" == "x" ]; then
for file in "$@"; do
archive_extract "$file"
done
exit 0
fi
# Print
if [ "$(basename "$0")" == "qcat" ]; then
for file in "$@"; do
archive_cat "$file"
done
exit 0
fi
fi