Merge pull request #18 from irrequietus/master

Adjusting -O flag semantics, options help update.
This commit is contained in:
Con Kolivas 2013-09-01 16:50:47 -07:00
commit e32636826b

31
lrztar
View file

@ -35,7 +35,9 @@ Extras: when an lrzip tarball is used with -d, -O, it gets extracted:
-O: <path2> will decompress a -d specified lrzip tarball to <path2> path. -O: <path2> will decompress a -d specified lrzip tarball to <path2> path.
-f: will force overwrites. -f: will force overwrites.
Final : 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. - You can use the remaining options of lrzip as they were.
- lrzuntar is equivalent to lrztar [options] -d <filename>. - lrzuntar is equivalent to lrztar [options] -d <filename>.
- This script exists because of how lrzip behaves. - This script exists because of how lrzip behaves.
@ -74,7 +76,6 @@ Final :
i+="/${vopt[v_d]##*/}" i+="/${vopt[v_d]##*/}"
i="${i%.tar.*}" i="${i%.tar.*}"
((v_O)) && { ((v_O)) && {
s=""
mkdir -p "${vopt[v_O]}" &> /dev/null mkdir -p "${vopt[v_O]}" &> /dev/null
for x in ${!p[@]};do for x in ${!p[@]};do
[ "${p[x]}"x == "-O"x ] && { [ "${p[x]}"x == "-O"x ] && {
@ -90,6 +91,7 @@ Final :
"$i" "$i"
return 1 return 1
} }
((v_f)) && mkdir -p "$i" &> /dev/null
[ ! -z "$s" ] && { [ ! -z "$s" ] && {
lrzcat ${p[@]// /\\ } "$s" | tar x -C "$i" lrzcat ${p[@]// /\\ } "$s" | tar x -C "$i"
x=$? x=$?
@ -104,19 +106,26 @@ Final :
return 1 return 1
} }
else else
s="${s%/}" if ((v_O)); then
p+=( -o "${s##*/}.tar.${vopt[v_S]}"); ((v_f)) && mkdir -p "${vopt[v_O]}" &> /dev/null
! ((v_f)) && [[ -e ${s##*/}.tar.${vopt[v_S]} ]] && { for x in ${!p[@]};do
[ "${p[x]}"x == "-O"x ] && {
p[x]=
i="${p[$((x+1))]%/}"
p[$((x+1))]=
s="${!#}"
break;
}
done
fi
p+=( -o "$i/${s##*/}.tar.${vopt[v_S]}");
! ((v_f)) && [[ -e $i/${s##*/}.tar.${vopt[v_S]} ]] && {
printf "lrztar: %s exists, aborting\n" \ printf "lrztar: %s exists, aborting\n" \
"${s##*/}.tar.${vopt[v_S]}" "$i/${s##*/}.tar.${vopt[v_S]}"
return 1 return 1
} }
fi fi
[[ -d $s ]] || { ! ((v_f)) && [[ -e $i/${s##*/}.tar.${vopt[v_S]} ]] && {
printf "lrztar: directory does not exist: %s\n" "$s"
return 1
}
! ((v_f)) && [[ -e ${s##*/}.tar.${vopt[v_S]} ]] && {
printf "lrztar: file %s exists, aborting\n" "$s.tar.lrz" printf "lrztar: file %s exists, aborting\n" "$s.tar.lrz"
return 1 return 1
} }