-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract
More file actions
executable file
·53 lines (47 loc) · 1.5 KB
/
extract
File metadata and controls
executable file
·53 lines (47 loc) · 1.5 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
#!/usr/bin/env bash
#
# /usr/local/xbin/extract
#
#
# Decription:
# Script to extract misc archives
#
# Usage:
# extract <archive> ...
# extract fooBar.tar.xz
# extract fooBar.tar.xz barBaz.tar.xz
# extract ./**/*.tar.xz
#
# Help
[[ ${#} < 1 || ${1} == '-h' ]] && sed -n '8,14p' ${0} && exit 1;
# Vars
ERR=0;
# Looper
for f in "${@}"; do
_dir=$(dirname "${f}");
_file=$(basename "${f}");
_ext="${_file#*.}";
if [ -f "${f}" ]; then
case "${f}" in
*.tar.xz|*.txz) tar -Jxvf "${f}" -C "${_dir}"; ;;
*.tar.zst|*.tzst) tar --zstd -xvf "${f}" -C "${_dir}"; ;;
*.tar.bz2|*.bz2|*.tbz2) tar -jxvf "${f}" -C "${_dir}"; ;;
*.tar.gz|*.gz|*.tgz) tar -zxvf "${f}" -C "${_dir}"; ;;
*.tar|*.zip) tar -xvf "${f}" -C "${_dir}"; ;;
*.tar.lz4) (cd "${_dir}" && lz4 -d "${f}" -c | tar -xvf -); ;;
*.rar) (cd "${_dir}" && unrar x "${f}"); ;;
*.Z) (cd "${_dir}" && uncompress "${f}"); ;;
*.7z) (cd "${_dir}" && 7z x "${f}"); ;;
*)
echo "$(basename ${0}): '${_file}' cannot be extracted. '${_ext}' is not supported.";
ERR=1;
;;
esac
# Cleanup messy garbage from Mac (zip)
[ -d "${_dir}/__MACOSX" ] && rm -rf "${_dir}/__MACOSX";
else
echo "'${_file}' is not a valid file";
ERR=1;
fi
done
exit ${ERR};