2010-03-29 01:07:08 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
2013-09-01 22:07:15 +02:00
|
|
|
# Copyright (C) George Makrydakis 2009-2011,2013
|
2012-03-08 04:11:04 +01:00
|
|
|
# Copyright (C) Con Kolivas 2011-2012
|
2010-03-29 01:07:08 +02:00
|
|
|
|
2010-04-03 11:34:16 +02:00
|
|
|
# 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/>.
|
2010-03-29 01:07:08 +02:00
|
|
|
|
|
|
|
|
function lrztar_local() {
|
2013-09-01 22:07:15 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
Final :
|
|
|
|
|
- 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...
|
|
|
|
|
"
|
|
|
|
|
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 x= i="$(pwd)"
|
2011-04-21 17:58:31 +02:00
|
|
|
which tar &> /dev/null \
|
|
|
|
|
|| { printf "lrztar: no tar in your path\n"; return 1; }
|
|
|
|
|
which lrzip &> /dev/null \
|
|
|
|
|
|| { printf "lrztar: no lrzip in your path\n"; return 1; }
|
2012-03-10 11:40:12 +01:00
|
|
|
which lrzcat &> /dev/null \
|
|
|
|
|
|| { printf "lrztar: no lrzcat in your path\n"; return 1; }
|
2013-09-01 22:07:15 +02:00
|
|
|
while getopts w:O:S:DqL:nlbgzUTN:p:vfo:d:tVhHck x; do
|
|
|
|
|
[[ $x == [tV] ]] && {
|
2011-04-21 17:58:31 +02:00
|
|
|
printf "lrztar: invalid option for lrztar: %s\n" "$x";
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
((v_$x=${#vopt[@]}))
|
2013-09-01 22:07:15 +02:00
|
|
|
vopt[${#vopt[@]}]="$OPTARG"
|
2010-03-29 01:07:08 +02:00
|
|
|
done
|
2010-04-03 11:21:31 +02:00
|
|
|
[[ $(basename "$0") == lrzuntar ]] \
|
2013-09-01 22:07:15 +02:00
|
|
|
&& { ((v_d=${#vopt[@]})); vopt[${#vopt[@]}]="$s"; }
|
2010-03-29 01:07:08 +02:00
|
|
|
{ ! (($#)) || ((v_h)); } && {
|
2011-04-21 17:58:31 +02:00
|
|
|
printf "%s\n" "$hv"
|
2010-03-29 01:07:08 +02:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
((v_d)) && {
|
2013-09-01 22:07:15 +02:00
|
|
|
[[ -e ${vopt[v_d]} ]] || {
|
|
|
|
|
printf "lrztar: file does not exist: %s\n" "${vopt[v_d]}"
|
2010-03-29 01:07:08 +02:00
|
|
|
return 1
|
|
|
|
|
}
|
2013-09-01 22:07:15 +02:00
|
|
|
i+="/${vopt[v_d]##*/}"
|
|
|
|
|
i="${i%.tar.*}"
|
|
|
|
|
((v_O)) && {
|
|
|
|
|
s=""
|
|
|
|
|
mkdir -p "${vopt[v_O]}" &> /dev/null
|
|
|
|
|
for x in ${!p[@]};do
|
|
|
|
|
[ "${p[x]}"x == "-O"x ] && {
|
|
|
|
|
p[x]=
|
|
|
|
|
p[$((x+1))]=
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
done
|
|
|
|
|
i="${vopt[v_O]}"
|
|
|
|
|
}
|
|
|
|
|
! ((v_f)) && [[ -d $i ]] && {
|
|
|
|
|
printf "lrztar: %s directory found, overwriting only with -f\n"\
|
|
|
|
|
"$i"
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
[ ! -z "$s" ] && {
|
|
|
|
|
lrzcat ${p[@]// /\\ } "$s" | tar x -C "$i"
|
|
|
|
|
x=$?
|
|
|
|
|
} || {
|
|
|
|
|
lrzcat ${p[@]// /\\ } | tar x -C "$i"
|
|
|
|
|
x=$?
|
|
|
|
|
}
|
2010-03-29 01:07:08 +02:00
|
|
|
} || {
|
2013-09-01 22:07:15 +02:00
|
|
|
if ((v_o)); then
|
|
|
|
|
! ((v_f)) && [[ -e ${vopt[$v_o]} ]] && {
|
|
|
|
|
printf "lrztar: %s exists, aborting\n" "${vopt[$v_o]}"
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
s="${s%/}"
|
|
|
|
|
p+=( -o "${s##*/}.tar.${vopt[v_S]}");
|
|
|
|
|
! ((v_f)) && [[ -e ${s##*/}.tar.${vopt[v_S]} ]] && {
|
|
|
|
|
printf "lrztar: %s exists, aborting\n" \
|
|
|
|
|
"${s##*/}.tar.${vopt[v_S]}"
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
fi
|
2011-04-21 17:58:31 +02:00
|
|
|
[[ -d $s ]] || {
|
|
|
|
|
printf "lrztar: directory does not exist: %s\n" "$s"
|
2010-04-02 15:17:42 +02:00
|
|
|
return 1
|
|
|
|
|
}
|
2013-09-01 22:07:15 +02:00
|
|
|
! ((v_f)) && [[ -e ${s##*/}.tar.${vopt[v_S]} ]] && {
|
|
|
|
|
printf "lrztar: file %s exists, aborting\n" "$s.tar.lrz"
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
tar c "$s" | lrzip ${p[@]// /\\ }
|
2010-03-29 01:07:08 +02:00
|
|
|
x=$?
|
|
|
|
|
}
|
|
|
|
|
return $x
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lrztar_local "${@}"
|