wok-next annotate xarchive/stuff/slitaz-wrap.sh @ rev 4954

xarchive: add lrzip support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Feb 17 16:44:15 2010 +0100 (2010-02-17)
parents f16dac640ecf
children a93b9fa277ad
rev   line source
pascal@688 1 #!/bin/sh
pascal@4909 2 #
pascal@4909 3 # slitaz-wrap.sh - slitaz core wrapper for xarchive frontend
pascal@4909 4 # Copyright (C) 2005 Lee Bigelow <ligelowbee@yahoo.com>
pascal@4909 5 # Copyright (C) 2010 Pascal Bellard <pascal.bellard@slitaz.org>
pascal@4909 6 #
pascal@688 7 # This program is free software; you can redistribute it and/or modify
pascal@688 8 # it under the terms of the GNU General Public License as published by
pascal@688 9 # the Free Software Foundation; either version 2 of the License, or
pascal@688 10 # (at your option) any later version.
pascal@4909 11 #
pascal@688 12 # This program is distributed in the hope that it will be useful,
pascal@688 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
pascal@688 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
pascal@688 15 # GNU General Public License for more details.
pascal@4909 16 #
pascal@688 17 # You should have received a copy of the GNU General Public License
pascal@688 18 # along with this program; if not, write to the Free Software
pascal@688 19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
pascal@688 20
pascal@4909 21 UNSUPPORTED=65
pascal@688 22
pascal@4909 23 GZIP_EXTS="tar.gz tgz cpio.gz"
pascal@688 24 LZMA_EXTS="tar.lz tar.lzma tlz"
pascal@688 25 BZIP2_EXTS="tar.bz tbz tar.bz2 tbz2"
pascal@4909 26 COMPRESS_EXTS="tar.z tar.Z"
pascal@4909 27 TAR_EXTS="tar tar.gz tgz $LZMA_EXTS $BZIP2_EXTS $COMPRESS_EXTS"
pascal@4355 28 XZ_EXTS="tar.xz txz"
pascal@4954 29 LRZIP_EXTS="tar.lzr tlzr"
pascal@2080 30 IPK_EXTS="ipk"
pascal@4909 31 CPIO_EXTS="cpio cpio.gz"
pascal@4355 32 CPIOXZ_EXTS="cpio.xz"
pascal@4954 33 CPIOLRZIP_EXTS="cpio.lzr"
pascal@688 34 ZIP_EXTS="zip cbz jar"
pascal@688 35 RPM_EXTS="rpm"
pascal@4909 36 DEB_EXTS="deb udeb"
pascal@3530 37 TAZPKG_EXTS="tazpkg spkg"
pascal@942 38 ISO_EXTS="iso"
pascal@4909 39 SQUASHFS_EXTS="sfs sqfs squashfs"
pascal@4909 40 CROMFS_EXTS="cfs cromfs"
pascal@4355 41 FS_EXTS="ext2 ext3 dos fat vfat xfs fd fs loop"
pascal@943 42 CLOOP_EXTS="cloop"
pascal@2877 43 RAR_EXTS="rar cbr"
pascal@2877 44 LHA_EXTS="lha lzh lzs"
pascal@3194 45 LZO_EXTS="lzo"
pascal@4909 46 ARJ_EXTS="arj pak arc j uc2 zoo"
pascal@4909 47 _7Z_EXTS="7z bcj bcj2"
pascal@688 48
pascal@4909 49 while read var progs; do
pascal@4909 50 eval $var=""
pascal@4909 51 for i in $progs; do
pascal@4909 52 [ "$(which $i)" ] || continue
pascal@4909 53 eval $var="$i"
pascal@4909 54 break
pascal@4909 55 done
pascal@4909 56 done <<EOT
pascal@4909 57 AWK_PROG mawk gawk awk
pascal@4909 58 XTERM_PROG xterm rxvt xvt wterm aterm Eterm false
pascal@4909 59 EOT
pascal@688 60
pascal@4909 61 # the shifting will leave the files passed as all the remaining args "$@"
pascal@688 62 opt="$1"
pascal@4909 63 archive="$2"
pascal@4909 64 lc_ext="$(echo ${2##*.} |tr [:upper:] [:lower:])"
pascal@4909 65 shift 2
pascal@688 66
pascal@2877 67 tazpkg2cpio()
pascal@2877 68 {
pascal@4909 69 tmp="$(mktemp -d -t tmpcpio.XXXXXX)"
pascal@4909 70 case "$(cd $tmp; cpio -iv < "$1")" in
pascal@4909 71 *lzma) unlzma -c $tmp/fs.cpio.lzma;;
pascal@4909 72 *gz) zcat $tmp/fs.cpio.gz
pascal@4909 73 esac
pascal@4909 74 rm -rf $tmp
pascal@2877 75 }
pascal@2877 76
pascal@2080 77 decompress_ipk()
pascal@2080 78 {
pascal@4909 79 tar xOzf "$1" ./data.tar.gz | gzip -dc
pascal@2080 80 }
pascal@2080 81
pascal@4909 82 # variables for our compression functions.
pascal@688 83 DECOMPRESS="cat"
pascal@688 84 COMPRESS="cat"
pascal@4909 85 while read d c exts; do
pascal@4909 86 case " $exts " in *\ $lc_ext\ *)
pascal@4909 87 [ "$d" == "${d% *}" -o "$(which ${d% *})" ] || exit $UNSUPPORTED
pascal@4909 88 DECOMPRESS="$d"
pascal@4909 89 COMPRESS="$c"
pascal@4909 90 [ "$(which ${c% *})" ] || COMPRESS="false"
pascal@4909 91 break
pascal@4909 92 esac
pascal@4909 93 done <<EOT
pascal@4909 94 unlzma\ -c lzma\ e\ -si\ -so $LZMA_EXTS
pascal@4909 95 bunzip2\ -c bzip2\ -c $BZIP2_EXTS
pascal@4909 96 gzip\ -dc gzip\ -c $GZIP_EXTS
pascal@4909 97 xz\ -dc xz\ -c $XZ_EXTS $CPIOXZ_EXTS
pascal@4954 98 lrzip\ -d lrzip $LRZIP_EXTS $CPIOLRZIP_EXTS
pascal@4909 99 uncompress\ -dc compress\ -c $COMPRESS_EXTS
pascal@4909 100 rpm2cpio false $RPM_EXTS
pascal@4909 101 tazpkg2cpio false $TAZPKG_EXTS
pascal@4909 102 decompress_ipk false $IPK_EXTS
pascal@4909 103 EOT
pascal@688 104
pascal@688 105 decompress_func()
pascal@688 106 {
pascal@4909 107 [ "$DECOMPRESS" = "cat" ] && return
pascal@4909 108 tmp="$(mktemp -t tartmp.XXXXXX)"
pascal@4909 109 [ -f "$archive" ] && $DECOMPRESS "$archive" > "$tmp"
pascal@4909 110 # store old name for compress_func
pascal@4909 111 oldarch="$archive"
pascal@4909 112 # change working file
pascal@4909 113 archive="$tmp"
pascal@688 114 }
pascal@688 115
pascal@688 116 compress_func()
pascal@688 117 {
pascal@4909 118 status=$?
pascal@4909 119 if [ "$COMPRESS" != "cat" -a -n "$oldarch" ]; then
pascal@4909 120 [ -f "$oldarch" ] && rm "$oldarch"
pascal@4909 121 $COMPRESS < "$archive" > "$oldarch" && rm "$archive"
pascal@4909 122 fi
pascal@4909 123 exit $status
pascal@688 124 }
pascal@688 125
pascal@688 126 not_busybox()
pascal@688 127 {
pascal@4909 128 [ "$(basename $(readlink $(which $1)))" != "busybox" ]
pascal@2877 129 }
pascal@2877 130
pascal@2877 131 addcpio()
pascal@2877 132 {
pascal@4909 133 find $@ | cpio -o -H newc
pascal@2877 134 }
pascal@2877 135
pascal@4909 136 a_file()
pascal@2877 137 {
pascal@4909 138 ( cd $2 ; tar -cf - $1 ) | tar -xf -
pascal@2877 139 }
pascal@2877 140
pascal@4909 141 r_file()
pascal@941 142 {
pascal@4909 143 rm -rf ./$1
pascal@941 144 }
pascal@941 145
pascal@4909 146 dpkg_c()
pascal@941 147 {
pascal@4909 148 dpkg-deb -c "$archive"
pascal@941 149 }
pascal@941 150
pascal@942 151 loop_fs()
pascal@942 152 {
pascal@4909 153 [ "$1" = "-n" ] && retrun
pascal@4909 154 cmd=$1
pascal@4909 155 shift
pascal@4909 156 tmp="$(mktemp -d -t fstmp.XXXXXX)"
pascal@4914 157 while read command umnt exts; do
pascal@4909 158 case " $exts " in *\ $lc_ext\ *)
pascal@4909 159 $command "$archive" $tmp
pascal@4909 160 break
pascal@4909 161 esac
pascal@4909 162 done <<EOT
pascal@4909 163 cromfs-driver fusermount\ -u $CROMFS_EXTS
pascal@4909 164 mount\ -o\ loop=/dev/cloop,ro umount\ -d $CLOOP_EXTS
pascal@4909 165 mount\ -o\ loop,rw umount\ -d $FS_EXTS
pascal@4909 166 mount\ -o\ loop,ro umount\ -d $ISO_EXTS $SQUASHFS_EXTS
pascal@4909 167 EOT
pascal@4909 168 rmdir $tmp 2> /dev/null && return
pascal@4909 169 case "$cmd" in
pascal@4909 170 -o) find $tmp | while read f; do
pascal@4909 171 [ "$f" = "$tmp" ] && continue
pascal@4909 172 link="-"
pascal@4909 173 [ -L "$f" ] && link=$(readlink "$f")
pascal@4909 174 date=$(stat -c "%y" $f | $AWK_PROG \
pascal@4909 175 '{ printf "%s;%s\n",$1,substr($2,0,8)}')
pascal@4909 176 echo "${f#$tmp/};$(stat -c "%s;%A;%U;%G" $f);$date;$link"
pascal@4909 177 done;;
pascal@4909 178 -e) ( cd $tmp ; tar cf - "$@" ) | tar xf - ;;
pascal@4909 179 -a) tar cf - "$@" | ( cd $tmp ; tar xf - );;
pascal@4909 180 -r) ( cd $tmp ; rm -rf "$@" )
pascal@4909 181 esac
pascal@4909 182 $umnt $tmp
pascal@4909 183 rmdir $tmp
pascal@4909 184 exit
pascal@942 185 }
pascal@942 186
pascal@4909 187 update()
pascal@4909 188 {
pascal@4909 189 loop_fs "$@"
pascal@4909 190 [ "$COMPRESS" = "false" ] && return
pascal@4909 191 action=$1
pascal@4909 192 shift
pascal@4909 193 tardir="$(dirname "$archive")"
pascal@4909 194 if not_busybox tar && [ "$action" != "-n" ]; then
pascal@4954 195 case " $TAR_EXTS $XZ_EXTS $LRZIP_EXTS " in *\ $lc_ext\ *)
pascal@4909 196 decompress_func
pascal@4909 197 case "$action" in
pascal@4909 198 -r) tar --delete -f "$archive" "$@";;
pascal@4909 199 -a) cd "$tardir"
pascal@4909 200 while [ -n "$1" ]; do
pascal@4909 201 tar -rf "$archive" "${1#$tardir/}"
pascal@4909 202 done
pascal@4909 203 esac
pascal@4909 204 compress_func
pascal@4909 205 esac
pascal@4909 206 fi
pascal@4909 207 while read add extract exts; do
pascal@4909 208 case " $exts " in *\ $lc_ext\ *)
pascal@4909 209 if [ "$action" = "-n" ]; then
pascal@4909 210 decompress_func
pascal@4909 211 cd "$tardir"
pascal@4909 212 $add "${1#$tardir/}" > "$archive"
pascal@4909 213 compress_func
pascal@4909 214 fi
pascal@4909 215 tmp="$(mktemp -d -t tartmp.XXXXXX)"
pascal@4909 216 cd $tmp
pascal@4909 217 $DECOMPRESS "$archive" | $extract
pascal@4909 218 status=$?
pascal@4909 219 if [ $status -eq 0 -a -n "$1" ]; then
pascal@4909 220 while [ "$1" ]; do
pascal@4909 221 ${action#-}_file "${1#$tardir/}" $here
pascal@4909 222 shift
pascal@4909 223 done
pascal@4909 224 $add $(ls -a | grep -v ^\.$ | grep -v ^\.\.$) | \
pascal@4909 225 $COMPRESS > "$archive"
pascal@4909 226 status=$?
pascal@4909 227 fi
pascal@4909 228 cd - >/dev/null
pascal@4909 229 rm -rf $tmp
pascal@4909 230 exit $status
pascal@4909 231 esac
pascal@4909 232 done <<EOT
pascal@4954 233 tar\ -cf\ - tar\ -xf\ - $TAR_EXTS $XZ_EXTS $LRZIP_EXTS
pascal@4954 234 addcpio cpio\ -id\ >\ /dev/null $CPIO_EXTS $CPIOXZ_EXTS $CPIOLRZIP_EXTS
pascal@4909 235 EOT
pascal@4909 236 }
pascal@4909 237
pascal@4909 238 # main: option switches
pascal@688 239 case "$opt" in
pascal@688 240 -i) # info: output supported extentions for progs that exist
pascal@4909 241 while read exe exts; do
pascal@4909 242 [ "$(which $exe)" -o -f /lib/modules/$(uname -r)/kernel/$exe.ko ] &&
pascal@4909 243 echo -n "$exts " | sed 's/ /;/g'
pascal@2877 244 done <<EOT
pascal@4909 245 tar $TAR_EXTS $IPK_EXTS
pascal@4909 246 cpio $CPIO_EXTS $TAZPKG_EXTS
pascal@4909 247 unzip $ZIP_EXTS
pascal@4909 248 dpkg-deb $DEB_EXTS
pascal@4909 249 rpm2cpio $RPM_EXTS
pascal@4909 250 mount $ISO_EXTS $FS_EXTS
pascal@4909 251 xz $XZ_EXTS $CPIOXZ_EXTS
pascal@4954 252 lrzip $LRZIP_EXTS $CPIOLRZIP_EXTS
pascal@2877 253 rar $RAR_EXTS
pascal@2877 254 unace ace
pascal@4909 255 arj $ARJ_EXTS
pascal@4909 256 7zr $_7Z_EXTS
pascal@2877 257 lha $LHA_EXTS
pascal@3194 258 lzop $LZO_EXTS
pascal@4909 259 cabextract cab
pascal@4909 260 cromfs-driver $CROMFS_EXTS
pascal@4909 261 fs/squashfs/squashfs $SQUASHFS_EXTS
pascal@4909 262 drivers/block/cloop $CLOOP_EXTS
pascal@2877 263 EOT
pascal@4909 264 echo ""
pascal@4909 265 exit
pascal@4909 266 ;;
pascal@4909 267 -o) # open: mangle output for xarchive
pascal@4909 268 AWK_MISC='
pascal@4909 269 BEGIN {
pascal@4909 270 attr="-"
pascal@4909 271 link="-"
pascal@4909 272 uid=uuid
pascal@4909 273 gid=uuid
pascal@4909 274 }
pascal@4909 275 function getlink(arg)
pascal@4909 276 {
pascal@4909 277 split(arg, x, " -> ")
pascal@4909 278 name=x[1]
pascal@4909 279 link=x[2]
pascal@4909 280 if (!link) link="-"
pascal@4909 281 }
pascal@688 282
pascal@4909 283 function getname(arg)
pascal@4909 284 {
pascal@4909 285 # works with filenames that start with a space (evil!)
pascal@4909 286 split($0,x, arg)
pascal@4909 287 getlink(x[2])
pascal@4909 288 }
pascal@4909 289
pascal@4909 290 function getid(arg)
pascal@4909 291 {
pascal@4909 292 if (uuid != "") return
pascal@4909 293 split(arg,x,"/")
pascal@4909 294 uid=x[1]
pascal@4909 295 gid=x[2]
pascal@4909 296 }
pascal@4909 297
pascal@4909 298 function getattr(arg)
pascal@4909 299 {
pascal@4909 300 attr=arg
pascal@4909 301 if (index(attr, "D") != 0) attr="drwxr-xr-x"
pascal@4909 302 else if (index(attr, ".") != 0 || attr !~ /^[rwx-]/) attr="-rw-r--r--"
pascal@4909 303 }
pascal@4909 304
pascal@4909 305 function display()
pascal@4909 306 {
pascal@4909 307 if (name != "") printf "%s;%s;%s;%s;%s;%s;%s;%s\n",name,size,attr,uid,gid,date,time,link
pascal@4909 308 }
pascal@4909 309
pascal@4909 310 function show(arg)
pascal@4909 311 {
pascal@4909 312 getid($2)
pascal@4909 313 getname(arg)
pascal@4909 314 if (uid != "blocks") display()
pascal@4909 315 }'
pascal@4909 316 AWKU="$AWK_PROG -v uuid=$(id -u -n) $AWK_MISC"
pascal@4909 317 AWK="$AWK_PROG $AWK_MISC"
pascal@4909 318 while read filter exts; do
pascal@688 319 # lrwxrwxrwx USR/GRP 0 2005-05-12 00:32:03 file -> /path/to/link
pascal@4909 320 case " $exts " in *\ $lc_ext\ *)
pascal@4909 321 $DECOMPRESS "$archive" | $filter | $AWK'
pascal@4909 322 {
pascal@4909 323 attr=$1
pascal@4909 324 size=$3
pascal@4909 325 date=$4
pascal@4909 326 time=$5
pascal@4909 327 show($5 " ")
pascal@4909 328 }'
pascal@4909 329 esac
pascal@4909 330 done <<EOT
pascal@4954 331 cpio\ -tv $CPIO_EXTS $CPIOXZ_EXTS $CPIOLRZIP_EXTS $RPM_EXTS $TAZPKG_EXTS
pascal@4954 332 tar\ -tvf\ - $TAR_EXTS $XZ_EXTS $LRZIP_EXTS $IPK_EXTS
pascal@4909 333 dpkg_c $DEB_EXTS
pascal@2877 334 EOT
pascal@4909 335 loop_fs $opt
pascal@4909 336 case " $ZIP_EXTS " in *\ $lc_ext\ *)
pascal@2877 337 if [ "$(which zipinfo)" ]; then
pascal@4909 338 # -rw-r--r-- 2.3 unx 11512 tx defN YYYYMMDD.HHMMSS file
pascal@4909 339 zipinfo -T -s-h-t "$archive" | $AWKU'
pascal@4909 340 {
pascal@4909 341 attr=$1
pascal@4909 342 size=$4
pascal@4909 343 date=substr($7,1,4) "-" substr($7,5,2) "-" substr($7,7,2)
pascal@4909 344 time=substr($7,10,2) ":" substr($7,12,2) ":" substr($7,14,2)
pascal@4909 345 show($7 " ")
pascal@4909 346 }'
pascal@688 347 else
pascal@4909 348 # 6622 2005-04-22 12:29:14 file
pascal@4909 349 unzip -l "$archive" | $AWKU'
pascal@4909 350 /-[0-9]+-/ {
pascal@4909 351 size=$1
pascal@4909 352 date=$2
pascal@4909 353 time=$3
pascal@4909 354 show($3 " ")
pascal@4909 355 }'
pascal@688 356 fi
pascal@4909 357 esac
pascal@4909 358 # -----------+---------------------+-------
pascal@4909 359 # 6622 | 22.04.2005 12:29:14 | file
pascal@4909 360 [ "$lc_ext" == "cab" ] && cabextract -q -l "$archive" | $AWKU'
pascal@4909 361 /[0-9]+ |/ {
pascal@4909 362 size=$1
pascal@4909 363 date=$3
pascal@4909 364 time=$4
pascal@4909 365 show($4 " | ")
pascal@4909 366 }'
pascal@4909 367 case " $RAR_EXTS " in *\ $lc_ext\ *)
pascal@2877 368 #-------------------------------------
pascal@2877 369 # bookmarks/mozilla_bookmarks.html
pascal@2877 370 # 11512 5231 45% 28-02-05 16:19 -rw-r--r-- F3F3477F m3b 2.9
pascal@2877 371 # (or 11512 5231 45% 28-02-05 16:19 .D.... 00000000 m3b 2.9)
pascal@4909 372 rar v -c- "$archive" | $AWKU'
pascal@4909 373 /-[0-9]+-/ {
pascal@4909 374 getattr($6)
pascal@4909 375 size=$1
pascal@4909 376 date=$4
pascal@4909 377 time=$5
pascal@4909 378 display()
pascal@4909 379 }
pascal@4909 380 {
pascal@4909 381 name=substr($0,2)
pascal@4909 382 }'
pascal@4909 383 esac
pascal@4909 384 case "$lc_ext" in
pascal@4909 385 ace)
pascal@4909 386 # Date ³Time ³Packed ³Size ³Ratio³File
pascal@4909 387 # 17.09.02³00:32³ 394116³ 414817³ 95%³ OggDS0993.exe
pascal@4909 388 unace v -c- "$archive" | $AWKU'
pascal@4909 389 /^[0-9][0-9]\./ {
pascal@4909 390 # strip the funky little 3 off the end of size
pascal@4909 391 size=substr($3,1,(length($3)-1))
pascal@4909 392 date=substr($1,1,8)
pascal@4909 393 time=substr($1,10,5)
pascal@4909 394 show($4 " ")
pascal@4909 395 }'
pascal@4909 396 ;;
pascal@4909 397 7z|bcj|bcj2)
pascal@4909 398 # ------------------- ----- ------------ ------------ ------------
pascal@4909 399 # 1992-04-12 11:39:46 ....A 356 ANKETA.FRG
pascal@4909 400 7zr l "$archive" | $AWKU'
pascal@4909 401 /^[0-9]+-/ {
pascal@4909 402 date=$1
pascal@4909 403 time=$2
pascal@4909 404 getattr($3)
pascal@4909 405 size=$4
pascal@4909 406 $0=substr($0, 54)
pascal@4909 407 name=$1
pascal@4909 408 if (NF > 1) name=$0
pascal@4909 409 gsub(/\\/, "/", name)
pascal@4909 410 display()
pascal@4909 411 }'
pascal@4909 412 esac
pascal@4909 413 case " $ARJ_EXTS " in *\ $lc_ext\ *)
pascal@4909 414 # 001) ANKETA.FRG
pascal@4909 415 # 3 MS-DOS 356 121 0.340 92-04-12 11:39:46 1
pascal@4909 416 arj v "$archive" | $AWKU'
pascal@4909 417 BEGIN { name="" }
pascal@4909 418 /^[0-9]+\) / {
pascal@4909 419 display()
pascal@4909 420 getname($1 " ")
pascal@4909 421 }
pascal@4909 422 /^[\t ]+[0-9]+/ {
pascal@4909 423 size=$3
pascal@4909 424 date=$6
pascal@4909 425 time=$7
pascal@4909 426 getattr($8)
pascal@4909 427 }
pascal@4909 428 /^[\t ]+Owner: UID [0-9]+\, GID [0-9]+/ { uid=$3; gid=$5 }
pascal@4909 429 /^[\t ]+SymLink -> / { link=$3; attr="l"substr(attr, 2) }
pascal@4909 430 /^---/ { display() }
pascal@4909 431 '
pascal@4909 432 esac
pascal@4909 433 case " $LHA_EXTS " in *\ $lc_ext\ *)
pascal@4909 434 # Desktop/up -> ..
pascal@4909 435 # lrwxrwxrwx 0/0 0 0 ****** -lhd- 0000 2009-05-03 16:59:03 [2]
pascal@4909 436 lha v -q -v "$archive" | $AWK'
pascal@4909 437 {
pascal@4909 438 if ($4 == "") { getlink($0); next }
pascal@4909 439 attr=$1
pascal@4909 440 getid($2)
pascal@4909 441 size=$4
pascal@4909 442 date=$8
pascal@4909 443 time=$9
pascal@4909 444 display()
pascal@4909 445 }'
pascal@4909 446 esac
pascal@4909 447 case " $LZO_EXTS " in *\ $lc_ext\ *)
pascal@3194 448 # ------ ------ ------ ----- ---- ---- ----
pascal@3194 449 # LZO1X-1 10057 5675 56.4% 2005-07-25 16:26 path/file
pascal@4909 450 lzop -Plv "$archive" | $AWKU'
pascal@4909 451 /-[0-9]+-/ {
pascal@4909 452 size=$2
pascal@4909 453 date=$5
pascal@4909 454 time=$6
pascal@4909 455 show($6 " ")
pascal@4909 456 }'
pascal@4909 457 esac
pascal@4909 458 exit 0
pascal@4909 459 ;;
pascal@4909 460 -a|-n) # add to archive / new: create new archive
pascal@4909 461 update $opt "$@"
pascal@2877 462 while read exe args exts; do
pascal@4909 463 [ "$(which $exe)" ] || continue
pascal@4909 464 [ "$opt$exe" = "-nzip" ] && args="-r"
pascal@4909 465 case " $exts " in *\ $lc_ext\ *)
pascal@4909 466 # only add the file's basename, not the full path
pascal@4909 467 while [ "$1" ]; do
pascal@4909 468 cd "$(dirname "$1")"
pascal@4909 469 $exe $args "$archive" "$(basename "$1")"
pascal@4909 470 status=$?
pascal@4909 471 shift
pascal@4909 472 done
pascal@4909 473 exit $status
pascal@4909 474 esac
pascal@2877 475 done <<EOT
pascal@2877 476 zip -g\ -r $ZIP_EXTS
pascal@2877 477 rar a $RAR_EXTS
pascal@4909 478 arj a $ARJ_EXTS
pascal@4909 479 7zr a\ -ms=off $_7Z_EXTS
pascal@2877 480 lha a $LHA_EXTS
pascal@2877 481 EOT
pascal@4909 482 ;;
pascal@4909 483 -r) # remove from archive passed files
pascal@4909 484 update $opt "$@"
pascal@2877 485 while read exe args exts; do
pascal@4909 486 [ "$(which $exe)" ] || continue
pascal@4909 487 case " $exts " in *\ $lc_ext\ *)
pascal@4909 488 $exe $args "$archive" "$@" | grep -q E_NOTIMPL && {
pascal@4909 489 echo -e "7z cannot delete files from solid archive." >&2
pascal@4909 490 exit $UNSUPPORTED
pascal@4909 491 }
pascal@4909 492 exit 0
pascal@4909 493 esac
pascal@2877 494 done <<EOT
pascal@2877 495 zip -d $ZIP_EXTS
pascal@2877 496 rar d $RAR_EXTS
pascal@4909 497 arj d $ARJ_EXTS
pascal@2877 498 lha d $LHA_EXTS
pascal@4909 499 7zr d $_7Z_EXTS
pascal@2877 500 EOT
pascal@4909 501 ;;
pascal@4909 502 -e) # extract from archive passed files
pascal@4909 503 while read arch exts; do
pascal@4909 504 case " $exts " in *\ $lc_ext\ *)
pascal@4909 505 $DECOMPRESS "$archive" | $arch "$@"
pascal@4909 506 exit $?
pascal@4909 507 esac
pascal@2877 508 done <<EOT
pascal@4954 509 tar\ -xf\ - $TAR_EXTS $IPK_EXTS $XZ_EXTS $LRZIP_EXTS
pascal@4954 510 cpio\ -idm $CPIO_EXTS $CPIOXZ_EXTS $CPIOLRZIP_EXTS $RPM_EXTS $TAZPKG_EXTS
pascal@2877 511 EOT
pascal@4909 512 while read exe x p exts; do
pascal@4909 513 [ "$(which $exe)" ] || continue
pascal@4909 514 case " $exts " in *\ $lc_ext\ *)
pascal@4909 515 [ "$x" != "N/A" ] && $exe $x "$archive" "$@"
pascal@4909 516 status=$?
pascal@4909 517 if [ "$p" != "N/A" -a $status -ne 0 ]; then
pascal@4909 518 echo Password protected, opening an x-term...
pascal@4909 519 $XTERM_PROG -e $exe $p "$archive" "$@"
pascal@4909 520 exit $?
pascal@4909 521 fi
pascal@4909 522 exit $status
pascal@4909 523 esac
pascal@2877 524 done <<EOT
pascal@4909 525 unzip -n N/A $ZIP_EXTS
pascal@4909 526 dpkg-deb -X N/A $DEB_EXTS
pascal@4909 527 lha x N/A $LHA_EXTS
pascal@4909 528 lzop -x N/A $LZO_EXTS
pascal@4909 529 rar x\ -o-\ -p- x\ -o- $RAR_EXTS
pascal@4909 530 arj x\ -y x\ -y\ -g? $ARJ_EXTS
pascal@4909 531 7zr x\ -y\ -p- x\ -y $_7Z_EXTS
pascal@4909 532 unace N/A x\ -o\ -y ace
pascal@4909 533 cabextract -q N/A cab
pascal@2877 534 EOT
pascal@4909 535 loop_fs $opt "$@"
pascal@4909 536 ;;
pascal@4909 537 *) cat <<EOT
pascal@4909 538 error, option $opt not supported
pascal@4909 539 use one of these:
pascal@4909 540 -i #info
pascal@4909 541 -o archive #open
pascal@4909 542 -a archive files #add
pascal@4909 543 -n archive file #new
pascal@4909 544 -r archive files #remove
pascal@4909 545 -e archive files #extract
pascal@2877 546 EOT
pascal@688 547 esac
pascal@4909 548 exit $UNSUPPORTED