-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmktar
executable file
·60 lines (52 loc) · 1.69 KB
/
mktar
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
#!/usr/bin/env bash
#
# /usr/local/xbin/mktar
#
#
# Description:
# A simple script to make compressed archives. It defaults
# to xz with a fallback on gz if it’s not installed.
#
# Usage:
# mktar [gz|bz2|zst|xz] [file | directory]
# mktar foobar.d # -> foobar.d.tar.xz
# mktar gz foobar.d # -> foobar.d.tar.gz
#
# OS X / macOS env's, incase they're not set already
if [[ $(uname -s) == 'Darwin' ]]; then
export COPY_EXTENDED_ATTRIBUTES_DISABLE=true
export COPYFILE_DISABLE=true
fi
# Help
[[ ${#} < 1 || ${1} == '-h' ]] && sed -n '9,14p' ${0} && exit 1;
# Vars
ERR=0;
# Check $1 for extension: xz = default | gz if not installed
[[ $(type xz 2> /dev/null) ]] && _xz='xz' || _xz='gz';
[[ ${1} =~ ^xz$|^zst$|^bz2$|^gz$ ]] && _ext=${1} && shift 1 || _ext=${_xz};
_base=$(basename ${0});
_path=$(dirname "${1}");
_dir=$(basename "${1}");
_excl=$(echo --exclude={'.DS_Store','._*'});
# Looper
if [ -e "${1}" ]; then
cd "${_path}";
case ${_ext} in
bz2) tar -cvjf "${_dir}".tar.${_ext} ${_excl} "${_dir}"; ;;
gz) tar -cvzf "${_dir}".tar.${_ext} ${_excl} "${_dir}"; ;;
lz4) tar -cvf - ${_excl} "${_dir}" \
| lz4 -v9 > "${_dir}".tar.${_ext}; ;;
xz) tar -cvf - ${_excl} "${_dir}" \
| xz -6e > "${_dir}".tar.${_ext}; ;;
zst) tar -cvf - ${_ecxl} "${_dir}" \
| zstd -T2 --ultra -22 > "${_dir}".tar.${_ext}; ;;
*)
echo -e ":: ${_base}: Could not create '${_dir}.tar.${_ext}'\n";
ERR=1;
;;
esac
else
echo -e ":: '${_dir}' is not a valid file/directory\n";
ERR=1;
fi
exit ${ERR};