-
Notifications
You must be signed in to change notification settings - Fork 78
/
lrztar
executable file
·153 lines (143 loc) · 5.28 KB
/
lrztar
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/bash
# Copyright (C) George Makrydakis 2009-2011,2013
# Copyright (C) Con Kolivas 2011-2012,2016,2018,2021
# A bash wrapper for Con Kolivas' excellent lrzip utility. For the time
# being, lrzip does not like pipes, so we had to do this. It is kind of
# self - documenting, spawned out of a test tube bash shell script.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
function lrztar_local() {
local hv="\
lrztar GNU/bash wrapper script for lrzip and tar input/output over directories.
Copyright (C) George Makrydakis 2009-2011,2013
Copyright (C) Con Kolivas 2011-2012,2016,2018,2021
Usage : lrztar [lrzip options] <directory>
Result: a lrzip tarball is produced.
Extras: when an lrzip tarball is used with -d, -O, it gets extracted:
-h: will display this message.
-d: <path1> will decompress a <path1> lrzip tarball to current directory.
-O: <path2> will decompress a -d specified lrzip tarball to <path2> path.
-f: will force overwrites.
Notice:
- The input argument is always last, all options and their arguments precede.
- The -O flag is an option flag, goes before: (-O <somedir> <input arg>).
- You can use the remaining options of lrzip as they were.
- lrzuntar is equivalent to lrztar [options] -d <filename>.
- This script exists because of how lrzip behaves.
- Beware the -f flag, it stands for what it says...
"
[[ $1 == "" ]] && {
printf "lrztar: no arguments given\n";
return 1;
}
local p=("${@:1:$(($#-1))}") s="${!#}" vopt=("lrz") \
v_w=0 v_S=0 v_D=0 v_p=0 v_q=0 v_L=0 \
v_n=0 v_l=0 v_b=0 v_g=0 v_z=0 v_U=0 \
v_T=0 v_N=0 v_v=0 v_f=0 v_d=0 v_h=0 \
v_H=0 v_c=0 v_k=0 v_o=0 v_O=0 v_m=0 x= i="$(pwd)"
tar --version &> /dev/null \
|| { printf "lrztar: no tar in your path\n"; return 1; }
lrzip --version &> /dev/null \
|| { printf "lrztar: no lrzip in your path\n"; return 1; }
lrzcat --version &> /dev/null \
|| { printf "lrztar: no lrzcat in your path\n"; return 1; }
while getopts w:O:S:DqL:nlbgzUm:TN:p:vfo:d:tVhHck x; do
[[ $x == [tV] ]] && {
printf "lrztar: invalid option for lrztar: %s\n" "$x";
return 1;
}
((v_$x=${#vopt[@]}))
vopt[${#vopt[@]}]="$OPTARG"
done
[[ $(basename "$0") == lrzuntar ]] \
&& { ((v_d=${#vopt[@]})); vopt[${#vopt[@]}]="$s"; }
{ ! (($#)) || ((v_h)); } && {
printf "%s\n" "$hv"
return
}
((v_d)) && {
[[ -e ${vopt[v_d]} ]] || {
printf "lrztar: file does not exist: %s\n" \
"${vopt[v_d]}"
return 1
}
i+="/${vopt[v_d]##*/}"
i="${i%.tar.*}"
if ((v_O)); then
for x in ${!p[@]};do
[[ ${p[x]} == "-O" ]] && {
p[x]=
p[$((x+1))]=
break;
}
done
i="${vopt[v_O]%/}"
x="${s##*/}"
if [[ -d "$i/${x%.tar.*}" ]] && ! ((v_f)); then
printf "lrztar: %s exists, use -f.\n" \
"$i/${x%.tar.*}"
return 1
fi
if ! [[ -d $i ]]; then
printf "lrztar: %s output path does not exist.\n" \
"$i"
return 1
fi
else
i="./"
fi
[ ! -z "$s" ] && {
lrzcat ${p[@]// /\\ } "$s" | tar x -C "$i"
x=$?
} || {
lrzcat ${p[@]// /\\ } | tar x -C "$i"
x=$?
}
} || {
if ((v_o)); then
! ((v_f)) && [[ -e ${vopt[$v_o]} ]] && {
printf "lrztar: %s exists, use -f to overwrite.\n" \
"${vopt[$v_o]}"
return 1
}
else
if ((v_O)); then
if ! [[ -d ${vopt[v_O]} ]]; then
printf "lrztar: %s output path does not exist.\n" \
"${vopt[v_O]}"
return 1
fi
for x in ${!p[@]};do
[[ ${p[x]} == "-O" ]] && {
p[x]=
i="${p[$((x+1))]%/}"
p[$((x+1))]=
s="${!#}"
break;
}
done
fi
s="${s%/}"
p+=(-o "$i/${s##*/}.tar.${vopt[v_S]}");
fi
if ! ((v_o)); then
! ((v_f)) && [[ -e $i/${s##*/}.tar.${vopt[v_S]} ]] && {
printf "lrztar: %s exists, use -f to overwrite\n" \
"$i/${s##*/}.tar.${vopt[v_S]}"
return 1
}
fi
tar c "$s" | lrzip "${p[@]}"
x=$?
}
return $x
}
lrztar_local "${@}"