2010-03-29 01:07:08 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
2011-04-21 17:58:31 +02:00
|
|
|
# Copyright (C) George Makrydakis 2009, 2010, 2011
|
2011-02-20 14:20:41 +01:00
|
|
|
# Copyright (C) Con Kolivas 2011
|
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() {
|
2011-04-21 17:58:31 +02:00
|
|
|
local hv="lrztar wrapper for compressing/decompressing \
|
|
|
|
|
whole directories with lrzip.
|
|
|
|
|
lrztar [lrzip options] <directory> will compress directory \
|
|
|
|
|
to directory.tar.lrz
|
|
|
|
|
lrztar -d [lrzip options] <directory.tar.lrz> will extract directory \
|
|
|
|
|
from directory.tar.lrz
|
|
|
|
|
lrzuntar [lrzip options] <directory.tar.lrz> will extract directory \
|
|
|
|
|
from directory.tar.lrz
|
|
|
|
|
lrz[un]tar -h will display this help message
|
|
|
|
|
lrzip -h will display lrzip options"
|
|
|
|
|
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 \
|
2011-02-22 10:38:39 +01:00
|
|
|
v_n=0 v_l=0 v_b=0 v_g=0 v_z=0 v_U=0 \
|
2011-02-20 14:20:41 +01:00
|
|
|
v_T=0 v_N=0 v_v=0 v_f=0 v_d=0 v_h=0 \
|
2011-04-21 17:58:31 +02:00
|
|
|
v_H=0 v_c=0 v_k=0 v_o=0 x= i=
|
|
|
|
|
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; }
|
|
|
|
|
while getopts w:OS:DqL:nlbgzUTN:p:vfo:dtVhHck x; do
|
|
|
|
|
[[ $x == [OtV] ]] && {
|
|
|
|
|
printf "lrztar: invalid option for lrztar: %s\n" "$x";
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
((v_$x=${#vopt[@]}))
|
|
|
|
|
[ $x == S ] && vopt[${#vopt[@]}]="$OPTARG"
|
2010-03-29 01:07:08 +02:00
|
|
|
done
|
2010-04-03 11:21:31 +02:00
|
|
|
[[ $(basename "$0") == lrzuntar ]] \
|
|
|
|
|
&& { v_d=1; p="-d $p"; }
|
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
|
|
|
|
|
}
|
2011-04-21 17:58:31 +02:00
|
|
|
[[ ${s%/*} != $s ]] && i="${s%/*}/" || i="./"
|
2010-03-29 01:07:08 +02:00
|
|
|
((v_d)) && {
|
2011-04-21 17:58:31 +02:00
|
|
|
i+="$(basename "$s")"
|
|
|
|
|
[[ -e $i ]] || {
|
|
|
|
|
printf "lrztar: file does not exist: %s\n" "$i"
|
2010-03-29 01:07:08 +02:00
|
|
|
return 1
|
|
|
|
|
}
|
2011-05-14 04:49:03 +02:00
|
|
|
lrzcat $p "$i" | tar x
|
2010-03-29 01:07:08 +02:00
|
|
|
x=$?
|
|
|
|
|
} || {
|
2011-04-21 17:58:31 +02:00
|
|
|
((v_o)) || p="$p -o $(basename "$s").tar.${vopt[v_S]}"
|
|
|
|
|
[[ -d $s ]] || {
|
|
|
|
|
printf "lrztar: directory does not exist: %s\n" "$s"
|
2010-04-02 15:17:42 +02:00
|
|
|
return 1
|
|
|
|
|
}
|
2011-04-21 17:58:31 +02:00
|
|
|
tar c "$s" | lrzip $p
|
2010-03-29 01:07:08 +02:00
|
|
|
x=$?
|
|
|
|
|
}
|
|
|
|
|
! ((x)) && ((v_D)) && rm -rf "$s" &> /dev/null
|
|
|
|
|
return $x
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lrztar_local "${@}"
|