-
Notifications
You must be signed in to change notification settings - Fork 4
/
xzz
executable file
·92 lines (73 loc) · 1.28 KB
/
xzz
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
#!/bin/bash
# `xzz <file-or-directory>`
# 0=true
# 1=false
_chkHelp() {
case "${1}" in
-[hH] | --[hH] | -[hH][eE][lL][pP] | --[hH][eE][lL][pP])
_help;
;;
*)
return
;;
esac;
}
_help() {
local -a Usage=(
"Usage:"
" xzz <file/directory>..."
);
local m;
for m in "${Usage[@]}"; do
echo "${m}";
done;
exit;
}
_tar() {
_bakTar "${1}";
echo "tar -cf ${1}.tar ${1}";
tar -cf "${1}.tar" "${1}";
}
_bakTar() {
local t="${1}.tar";
if ! [ -e "${t}" ]; then
return;
fi;
BAK="${t}.bak";
cp "${t}" "${BAK}";
}
_yN() {
case "${1}" in
[yY] | [yY][eE][sS] )
echo 1;
;;
*)
echo 0;
;;
esac;
}
_xz() {
local cmd="xz -zv -T 0 -e9 \"${1}\"";
echo "${cmd}";
if ! eval "${cmd}"; then
exit 1;
fi;
if ! xz -t "${1}.xz"; then
rm "${1}.xz";
_xz "${1}";
fi;
}
_chkHelp "${1}";
declare BAK;
for file; do
BAK="";
if [[ "${file}" == "${file%\.tar*}" ]]; then
_tar "${file}" ;
file="${file}.tar";
fi;
_xz "${file}";
if ! [ "${BAK}" ]; then
continue;
fi;
mv "${BAK}" "${file}";
done;