wok view xarchive/stuff/slitaz-wrap.sh @ rev 4355

xarchive: add xz support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Oct 04 15:34:46 2009 +0200 (2009-10-04)
parents 0109c31e8835
children 21cf50e9eaa7
line source
1 #!/bin/sh
2 # slitaz-wrap.sh - sh slitaz core wrapper for xarchive frontend
3 # Copyright (C) 2005 Lee Bigelow <ligelowbee@yahoo.com>
4 # Copyright (C) 2009 Pascal Bellard <pascal.bellard@slitaz.org>
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 # set up exit status variables
21 E_UNSUPPORTED=65
23 # Supported file extentions for tar
24 TAR_EXTS="tar"
25 GZIP_EXTS="tar.gz tgz"
26 LZMA_EXTS="tar.lz tar.lzma tlz"
27 BZIP2_EXTS="tar.bz tbz tar.bz2 tbz2"
28 XZ_EXTS="tar.xz txz"
29 COMPRESS_EXTS="tar.z tar.Z"
30 IPK_EXTS="ipk"
31 CPIO_EXTS="cpio"
32 CPIOGZ_EXTS="cpio.gz"
33 CPIOXZ_EXTS="cpio.xz"
34 ZIP_EXTS="zip cbz jar"
35 RPM_EXTS="rpm"
36 DEB_EXTS="deb"
37 TAZPKG_EXTS="tazpkg spkg"
38 ISO_EXTS="iso"
39 SQUASHFS_EXTS="sqfs squashfs"
40 CROMFS_EXTS="cromfs"
41 FS_EXTS="ext2 ext3 dos fat vfat xfs fd fs loop"
42 CLOOP_EXTS="cloop"
43 RAR_EXTS="rar cbr"
44 LHA_EXTS="lha lzh lzs"
45 LZO_EXTS="lzo"
47 # Setup awk program
48 AWK_PROGS="mawk gawk awk"
49 AWK_PROG=""
50 for awkprog in $AWK_PROGS; do
51 if [ "$(which $awkprog)" ]; then
52 AWK_PROG="$awkprog"
53 break
54 fi
55 done
57 # Setup xterm program to use
58 XTERM_PROGS="xterm rxvt xvt wterm aterm Eterm"
59 XTERM_PROG=""
60 for xtermprog in $XTERM_PROGS; do
61 if [ "$(which $xtermprog)" ]; then
62 XTERM_PROG="$xtermprog"
63 break
64 fi
65 done
67 # setup variables opt and archive.
68 # the shifting will leave the files passed as
69 # all the remaining args "$@"
70 opt="$1"
71 test -z $1 || shift 1
72 archive="$1"
73 test -z $1 || shift 1
75 tazpkg2cpio()
76 {
77 tmpcpio="$(mktemp -d -t tmpcpio.XXXXXX)"
78 cd $tmpcpio
79 cpio -i fs.cpio.gz > /dev/null < "$1"
80 zcat fs.cpio.gz
81 cd -
82 rm -rf $tmpcpio
83 }
85 decompress_ipk()
86 {
87 tar xOzf "$1" ./data.tar.gz | gzip -dc
88 }
90 # set up compression variables for our compression functions.
91 # translate archive name to lower case for pattern matching.
92 # use compressor -c option to output to stdout and direct it where we want
93 lc_archive="$(echo $archive|tr [:upper:] [:lower:])"
94 DECOMPRESS="cat"
95 COMPRESS="cat"
96 for ext in $IPK_EXTS; do
97 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
98 DECOMPRESS="decompress_ipk"
99 fi
100 done
101 for ext in $GZIP_EXTS $CPIOGZ_EXTS; do
102 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
103 DECOMPRESS="gzip -dc"
104 COMPRESS="gzip -c"
105 fi
106 done
107 for ext in $BZIP2_EXTS; do
108 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
109 DECOMPRESS="bunzip2 -c"
110 COMPRESS="bzip2 -c"
111 fi
112 done
113 for ext in $LZMA_EXTS; do
114 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
115 DECOMPRESS="unlzma -c"
116 COMPRESS="lzma e -si -so"
117 fi
118 done
119 for ext in $XZ_EXTS $CPIOXZ_EXTS; do
120 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
121 [ -x /usr/bin/rx ] || exit $E_UNSUPPORTED
122 DECOMPRESS="xz -dc"
123 COMPRESS="xz -c"
124 fi
125 done
126 for ext in $COMPRESS_EXTS; do
127 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
128 DECOMPRESS="uncompress -dc"
129 COMPRESS="compress -c"
130 fi
131 done
133 do_decompress()
134 {
135 $DECOMPRESS "$1"
136 }
138 # Compression functions
139 decompress_func()
140 {
141 if [ "$DECOMPRESS" != "cat" ]; then
142 tmpname="$(mktemp -t tartmp.XXXXXX)"
143 if [ -f "$archive" ]; then
144 $DECOMPRESS "$archive" > "$tmpname"
145 fi
146 # store old name for when we recompress
147 oldarch="$archive"
148 # change working file to decompressed tmp
149 archive="$tmpname"
150 fi
151 }
153 compress_func()
154 {
155 if [ "$COMPRESS" != "cat" ] && [ "$oldarch" ]; then
156 [ -f "$oldarch" ] && rm "$oldarch"
157 if $COMPRESS < "$archive" > "$oldarch"; then
158 rm "$archive"
159 fi
160 fi
161 }
163 not_busybox()
164 {
165 case "$(readlink $(which $1))" in
166 *busybox*) return 1;;
167 esac
168 return 0
169 }
171 addtar()
172 {
173 tar -cf - $@
174 }
176 extracttar()
177 {
178 tar -xf -
179 }
181 addcpio()
182 {
183 find $@ | cpio -o -H newc
184 }
186 extractcpio()
187 {
188 cpio -id > /dev/null
189 }
191 add_file()
192 {
193 ( cd $2 ; tar -cf - $1 ) | tar -xf -
194 }
196 remove_file()
197 {
198 rm -rf ./$1
199 }
201 update_tar_cpio()
202 {
203 action=$1
204 shift
205 tardir="$(dirname "$archive")"
206 if [ $(expr "$lc_archive" : ".*\."$BZIP2_EXTS"$") -gt 0 ]; then
207 [ "$(which bzip2)" ] || return
208 fi
209 if not_busybox tar && [ "$action" != "new_archive" ]; then
210 for ext in $TAR_EXTS $GZIP_EXTS $BZIP2_EXTS $XZ_EXTS \
211 $COMPRESS_EXTS $LZMA_EXTS; do
212 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
213 decompress_func
214 case "$action" in
215 remove_file)
216 tar --delete -f "$archive" "$@";;
217 add_file)
218 cd "$tardir"
219 while [ -n "$1" ]; do
220 tar -rf "$archive" "${1#$tardir/}"
221 done;;
222 esac
223 status=$?
224 compress_func
225 exit $status
226 fi
227 done
228 fi
229 while read add extract exts; do
230 for ext in $exts; do
231 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
232 if [ "$action" = "new_archive" ]; then
233 decompress_func
234 cd "$tardir"
235 $add "${1#$tardir/}" > "$archive"
236 status=$?
237 compress_func
238 exit $status
239 fi
240 tmptar="$(mktemp -d -t tartmp.XXXXXX)"
241 here="$(pwd)"
242 cd $tmptar
243 $DECOMPRESS "$archive" | $extract
244 status=$?
245 if [ $status -eq 0 -a -n "$1" ]; then
246 while [ "$1" ]; do
247 $action "${1#$tardir/}" $here
248 shift
249 done
250 $add $(ls -a | grep -v ^\.$ | grep -v ^\.\.$) | \
251 $COMPRESS > "$archive"
252 status=$?
253 fi
254 cd $here
255 rm -rf $tmptar
256 exit $status
257 fi
258 done
259 done <<EOT
260 addtar extracttar $TAR_EXTS $GZIP_EXTS $BZIP2_EXTS $XZ_EXTS $COMPRESS_EXTS $LZMA_EXTS
261 addcpio extractcpio $CPIO_EXTS $CPIOGZ_EXTS $CPIOXZ_EXTS
262 EOT
263 }
265 loop_fs()
266 {
267 tmpfs="$(mktemp -d -t fstmp.XXXXXX)"
268 umnt="umount -d"
269 ext=${lc_archive##*.}
270 case " $CROMFS_EXTS " in
271 *\ $ext\ *) umnt="fusermount -u"
272 cromfs-driver "$archive" $tmpfs;;
273 esac
274 case " $CLOOP_EXTS " in
275 *\ $ext\ *) mount -o loop=/dev/cloop,ro "$archive" $tmpfs;;
276 esac
277 case " $FS_EXTS " in
278 *\ $ext\ *) mount -o loop,rw "$archive" $tmpfs;;
279 esac
280 case " $ISO_EXTS $SQUASHFS_EXTS " in
281 *\ $ext\ *) mount -o loop,ro "$archive" $tmpfs;;
282 esac
283 rmdir $tmpfs 2> /dev/null && exit $E_UNSUPPORTED
284 cmd=$1
285 shift
286 case "$cmd" in
287 stat) find $tmpfs | while read f; do
288 [ "$f" = "$tmpfs" ] && continue
289 link="-"
290 [ -L "$f" ] && link=$(readlink "$f")
291 date=$(stat -c "%y" $f | awk \
292 '{ printf "%s;%s\n",$1,substr($2,0,8)}')
293 echo "${f#$tmpfs/};$(stat -c "%s;%A;%U;%G" $f);$date;$link"
294 done;;
295 copy) if [ -z "$1" ]; then
296 ( cd $tmpfs ; tar cf - . ) | tar xf -
297 else
298 while [ -n "$1" ]; do
299 ( cd $tmpfs ; tar cf - "$1" ) | tar xf -
300 shift;
301 done
302 fi;;
303 add) tar cf - "$@" | ( cd $tmpfs ; tar xf - );;
304 remove) while [ -n "$1" ]; do
305 rm -rf $tmpfs/$1
306 done;;
307 esac
308 $umnt $tmpfs
309 rmdir $tmpfs
310 exit 0
311 }
313 # the option switches
314 case "$opt" in
315 -i) # info: output supported extentions for progs that exist
316 for ext in $TAR_EXTS $GZIP_EXTS $BZIP2_EXTS $COMPRESS_EXTS $LZMA_EXTS \
317 $CPIO_EXTS $CPIOGZ_EXTS $ZIP_EXTS $DEB_EXTS $RPM_EXTS \
318 $TAZPKG_EXTS $ISO_EXTS $FS_EXTS $IPK_EXTS; do
319 printf "%s;" $ext
320 if [ "$ext" = "zip" -a ! "$(which zip)" ]; then
321 echo warning: zip not found, extract only >/dev/stderr
322 fi
323 done
324 [ -x /usr/bin/xz ] && for ext in $XZ_EXTS $CPIOXZ_EXTS; do
325 printf "%s;" $ext
326 done
327 while read mod exts; do
328 [ -f /lib/modules/$(uname -r)/kernel/$mod ] || continue
329 for ext in $exts; do
330 printf "%s;" $ext
331 done
332 done <<EOT
333 fs/squashfs/squashfs.ko $SQUASHFS_EXTS
334 drivers/block/cloop.ko $CLOOP_EXTS
335 EOT
336 while read exe exts; do
337 [ "$(which $exe)" ] || continue
338 for ext in $exts; do
339 printf "%s;" $ext
340 done
341 done <<EOT
342 cromfs-driver $CROMFS_EXTS
343 rar $RAR_EXTS
344 unace ace
345 arj arj
346 7za 7z
347 lha $LHA_EXTS
348 lzop $LZO_EXTS
349 EOT
350 printf "\n"
351 exit
352 ;;
354 -o) # open: mangle output of tar cmd for xarchive
355 while read cmd filter exts; do
356 for ext in $exts; do
357 # format of cpio output:
358 # lrwxrwxrwx USR/GRP 0 2005-05-12 00:32:03 file -> /path/to/link
359 # -rw-r--r-- USR/GRP 6622 2005-04-22 12:29:14 file
360 # 1 2 3 4 5 6
361 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
362 $cmd "$archive" | $filter | $AWK_PROG '
363 {
364 attr=$1
365 split($2,ids,"/") #split up the 2nd field to get uid/gid
366 uid=ids[1]
367 gid=ids[2]
368 size=$3
369 date=$4
370 time=$5
372 #this method works with filenames that start with a space (evil!)
373 #split line a time and a space
374 split($0,linesplit, $5 " ")
375 #then split the second item (name&link) at the space arrow space
376 split(linesplit[2], nlsplit, " -> ")
378 name=nlsplit[1]
379 link=nlsplit[2]
381 if (! link) {link="-"} #if there was no link set it to a dash
383 if (name != "" && uid != "blocks") printf "%s;%s;%s;%s;%s;%s;%s;%s\n",name,size,attr,uid,gid,date,time,link
384 }'
385 exit 0
386 fi
387 done
388 done <<EOT
389 do_decompress cpio\ -tv $CPIO_EXTS $CPIOGZ_EXTS $CPIOXZ_EXTS
390 do_decompress tar\ -tvf\ - $TAR_EXTS $GZIP_EXTS $BZIP2_EXTS $XZ_EXTS $COMPRESS_EXTS $LZMA_EXTS $IPK_EXTS
391 rpm2cpio cpio\ -tv $RPM_EXTS
392 tazpkg2cpio cpio\ -tv $TAZPKG_EXTS
393 EOT
394 for ext in $ZIP_EXTS; do
395 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
396 if [ "$(which zipinfo)" ]; then
397 # format of zipinfo -T -s-h- output:
398 # -rw-r--r-- 2.3 unx 11512 tx defN YYYYMMDD.HHMMSS file
399 # 1 2 3 4 5 6 7 8
400 zipinfo -T -s-h-t "$archive" | $AWK_PROG -v uuid=$(id -u -n) '
401 {
402 attr=$1; size=$4
404 year=substr($7,1,4)
405 month=substr($7,5,2)
406 day=substr($7,7,2)
407 date=year "-" month "-" day
409 hours=substr($7,10,2)
410 mins=substr($7,12,2)
411 secs=substr($7,14,2)
412 time=hours ":" mins ":" secs
414 uid=uuid; gid=uuid; link="-"
415 #split line at the time and a space, second item is our name
416 split($0, linesplit, ($7 " "))
417 name=linesplit[2]
418 printf "%s;%s;%s;%s;%s;%s;%s;%s\n",name,size,attr,uid,gid,date,time,link
419 }'
420 exit 0
421 else
422 # format of unzip -l output:
423 # 6622 2005-04-22 12:29:14 file
424 # 1 2 3 4
425 unzip -l "$archive" | $AWK_PROG -v uuid=$(id -u -n) '
426 BEGIN { n = 0}
427 {
428 n=n+1
429 attr=""
430 uid=uuid; gid=uuid
431 size=$1
432 date=$2
433 time=$3
435 #this method works with filenames that start with a space (evil!)
436 #split line a time and a space
437 split($0,linesplit, $3 " ")
438 #then split the second item (name&link) at the space arrow space
439 split(linesplit[2], nlsplit, " -> ")
441 name=nlsplit[1]
442 link=nlsplit[2]
444 if (! link) {link="-"} #if there was no link set it to a dash
446 if (name != "" && n > 3) printf "%s;%s;%s;%s;%s;%s;%s;%s\n",name,size,attr,uid,gid,date,time,link
447 }'
448 exit 0
449 fi
450 fi
451 done
453 for ext in $ISO_EXTS $SQUASHFS_EXTS $CROMFS_EXTS $CLOOP_EXTS $FS_EXTS; do
454 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
455 loop_fs stat
456 fi
457 done
458 for ext in $RAR_EXTS; do
459 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
460 # format of rar output:
461 #-------------------------------------
462 # bookmarks/mozilla_bookmarks.html
463 # 11512 5231 45% 28-02-05 16:19 -rw-r--r-- F3F3477F m3b 2.9
464 # (or 11512 5231 45% 28-02-05 16:19 .D.... 00000000 m3b 2.9)
465 # (or 11512 5231 45% 28-02-05 16:19 .....S F3F3477F m3b 2.9)
466 # 1 2 3 4 5 6 7 8 9
467 #-------------------------------------
469 rar v -c- "$archive" | $AWK_PROG -v uuid=$(id -u -n) '
470 # The body of info we wish to process starts with a dashed line
471 # so set a flag to signal when to start and stop processing.
472 # The name is on one line with the info on the next so toggle
473 # a line flag letting us know what kinda info to get.
474 BEGIN { flag=0; line=0 }
475 /^------/ { flag++; if (flag > 1) exit 0; next} #line starts with dashs
476 {
477 if (flag == 0) next #not in the body yet so grab the next line
478 if (line == 0) #this line contains the name
479 {
480 name=substr($0,2) #strip the single space from start of name
481 line++ #next line will contain the info so increase the flag
482 next
483 }
484 else #we got here so this line contains the info
485 {
486 size=$1
487 date=$4
488 time=$5
490 #modify attributes to read more unix like if they are not
491 if (index($6, "D") != 0) {attr="drwxr-xr-x"}
492 else if (index($6, ".") != 0) {attr="-rw-r--r--"}
493 else {attr=$6}
495 uid=uuid
496 gid=uuid
497 link="-"
499 printf "%s;%s;%s;%s;%s;%s;%s;%s\n",name,size,attr,uid,gid,date,time,link
500 line=0 #next line will be a name so reset the flag
501 }
502 }'
503 exit 0
504 fi
505 done
506 for ext in ace; do
507 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
508 # format of ace output:
509 # Date ³Time ³Packed ³Size ³Ratio³File
510 # 17.09.02³00:32³ 394116³ 414817³ 95%³ OggDS0993.exe
511 # 1 2 3 4 5
512 unace v -c- "$archive" | $AWK_PROG -v uuid=$(id -u -n) '
513 #only process lines starting with two numbers and a dot
514 /^[0-9][0-9]\./ {
515 date=substr($1,1,8)
516 time=substr($1,10,5)
517 #need to strip the funky little 3 off the end of size
518 size=substr($3,1,(length($3)-1))
520 #split line at ratio and a space, second item is our name
521 split($0, linesplit, ($4 " "))
522 name=linesplit[2]
524 uid=uuid; gid=uuid; link="-"; attr="-"
525 printf "%s;%s;%s;%s;%s;%s;%s;%s\n",name,size,attr,uid,gid,date,time,link
526 }'
527 exit 0
528 fi
529 done
530 for ext in arj; do
531 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
532 # format of arj output:
533 # 001) ANKETA.FRG
534 # 3 MS-DOS 356 121 0.340 92-04-12 11:39:46 1
536 arj v "$archive" | $AWK_PROG -v uuid=$(id -u -n) '{
537 if (($0 ~ /^[0-9]+\) .*/)||($0 ~ /^------------ ---------- ---------- -----/)){
538 if (filestr ~ /^[0-9]+\) .*/) {
539 printf "%s;%d;%s;%d;%d;%02d-%02d-%02d;%02d:%02d;%s\n", file, size, perm, uid, gid, date[1], date[3], date[2], time[1], time[2], symfile
540 perm=""
541 file=""
542 symfile=""
543 filestr=""
544 }
545 }
547 if ($0 ~ /^[0-9]+\) .*/) {
548 filestr=$0
549 sub(/^[0-9]*\) /, "")
550 file=$0
551 uid=uuid
552 gid=0
553 }
555 if ($0 ~ /^.* [0-9]+[\t ]+[0-9]+ [0-9]\.[0-9][0-9][0-9] [0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9].*/) {
556 size=$3
557 split($6, date, "-")
558 split($7, time, ":")
559 if ($8 ~ /^[rwx-]/) {perm=$8;} else {perm="-rw-r--r--"}
560 }
562 if ($0 ~ /^[\t ]+SymLink -> .*/) {
563 symfile = $3
564 perm="l"substr(perm, 2)
565 } else {symfile="-"}
567 if ($0 ~ /^[\t ]+Owner: UID [0-9]+\, GID [0-9]+/) {
568 uid=$3
569 gid=$5
570 owner=1
571 }
572 }'
573 exit 0
574 fi
575 done
576 for ext in 7z; do
577 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
578 # format of 7za output:
579 # ------------------- ----- ------------ ------------ ------------
580 # 1992-04-12 11:39:46 ....A 356 ANKETA.FRG
582 7za l "$archive" | $AWK_PROG -v uuid=$(id -u -n) '
583 BEGIN { flag=0; }
584 /^-------/ { flag++; if (flag > 1) exit 0; next }
585 {
586 if (flag == 0) next
588 year=substr($1, 1, 4)
589 month=substr($1, 6, 2)
590 day=substr($1, 9, 2)
591 time=substr($2, 1, 5)
593 if (index($3, "D") != 0) {attr="drwxr-xr-x"}
594 else if (index($3, ".") != 0) {attr="-rw-r--r--"}
596 size=$4
598 $0=substr($0, 54)
599 if (NF > 1) {name=$0}
600 else {name=$1}
601 gsub(/\\/, "/", name)
603 printf "%s;%d;%s;%d;%d;%d-%02d-%02d;%s;-\n", name, size, attr, uid, 0, year, month, day, time
604 }'
605 exit 0
606 fi
607 done
608 for ext in $LHA_EXTS; do
609 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
610 # format of lha output:
611 # Desktop/up -> ..
612 # lrwxrwxrwx 0/0 0 0 ****** -lhd- 0000 2009-05-03 16:59:03 [2]
614 lha v -q -v "$archive" | $AWK_PROG '
615 {
616 if ($4 == "") {
617 split($0, nlsplit, " -> ")
618 name=nlsplit[1]
619 link=nlsplit[2]
620 if (! link) {link="-"}
621 next
622 }
623 attr=$1
624 ids=$2
625 split($2,ids,"/") #split up the 2nd field to get uid/gid
626 uid=ids[1]
627 gid=ids[2]
628 size=$4
630 year=substr($8, 1, 4)
631 month=substr($8, 6, 2)
632 day=substr($8, 9, 2)
633 time=substr($9, 1, 5)
635 printf "%s;%d;%s;%d;%d;%d-%02d-%02d;%s;-\n", name, size, attr, uid, gid, year, month, day, time
636 }'
637 exit 0
638 fi
639 done
640 for ext in $LZO_EXTS; do
641 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
642 # format of lzo output:
643 # Method Length Packed Ratio Date Time Name
644 # ------ ------ ------ ----- ---- ---- ----
645 # LZO1X-1 626 526 84.0% 2009-05-27 09:52 file
646 # LZO1X-1 10057 5675 56.4% 2005-07-25 16:26 path/file
647 # ------- ------- ----- ----
648 # 1 2 3 4 5 6 7
649 lzop -Plv "$archive" | $AWK_PROG -v uuid=$(id -u -n) '
650 BEGIN { show = 0}
651 {
652 if ($5 == "----" || $4 == "----") {
653 show = 1 - show
654 next
655 }
656 attr="-rw-r--r--"
657 uid=uuid; gid=uuid
658 size=$2
659 date=$5
660 time=$6
662 #this method works with filenames that start with a space (evil!)
663 #split line a time and a space
664 split($0,linesplit, $6 " ")
666 name=linesplit[2]
667 link="-" # links are not supported
669 if (show == 1) printf "%s;%s;%s;%s;%s;%s;%s;%s\n",name,size,attr,uid,gid,date,time,link
670 }'
671 exit 0
672 fi
673 done
674 exit $E_UNSUPPORTED
675 ;;
677 -a) # add to archive passed files
678 update_tar_cpio add_file "$@"
679 for ext in $FS_EXTS; do
680 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
681 loop_fs add "$@"
682 fi
683 done
684 while read exe args exts; do
685 [ "$(which $exe)" ] || continue
686 for ext in $exts; do
687 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
688 # we only want to add the file's basename, not
689 # the full path so...
690 while [ "$1" ]; do
691 cd "$(dirname "$1")"
692 $exe $args "$archive" "$(basename "$1")"
693 wrapper_status=$?
694 shift 1
695 done
696 exit $wrapper_status
697 fi
698 done
699 done <<EOT
700 zip -g\ -r $ZIP_EXTS
701 rar a $RAR_EXTS
702 arj a arj
703 7za a\ -ms=off 7z
704 lha a $LHA_EXTS
705 EOT
706 exit $E_UNSUPPORTED
707 ;;
709 -n) # new: create new archive with passed files
710 update_tar_cpio new_archive "$@"
711 while read exe args exts; do
712 [ "$(which $exe)" ] || continue
713 for ext in $exts; do
714 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
715 # create will only be passed the first file, the
716 # rest will be "added" to the new archive
717 cd "$(dirname "$1")"
718 $exe $args "$archive" "$(basename "$1")"
719 fi
720 done
721 done <<EOT
722 zip -r $ZIP_EXTS
723 rar a $RAR_EXTS
724 arj a arj
725 7za a\ -ms=off 7z
726 lha a $LHA_EXTS
727 EOT
728 exit $E_UNSUPPORTED
729 ;;
731 -r) # remove: from archive passed files
732 update_tar_cpio remove_file "$@"
733 while read exe args exts; do
734 [ "$(which $exe)" ] || continue
735 for ext in $exts; do
736 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
737 $exe $args "$archive" "$@"
738 exit $?
739 fi
740 done
741 done <<EOT
742 loop_fs remove $FS_EXTS
743 zip -d $ZIP_EXTS
744 rar d $RAR_EXTS
745 arj d arj
746 lha d $LHA_EXTS
747 EOT
748 wrapper_status=0
749 [ "$(which 7za)" ] && [ $(expr "$lc_archive" : ".*\.7z$") -gt 0 ] &&
750 while [ "$1" ]; do
751 7za l "$archive" 2>/dev/null | grep -q "[.][/]" >&/dev/null \
752 && EXFNAME=*./"$1" || EXFNAME="$1"
753 7za d "$archive" "$EXFNAME" 2>&1 \
754 | grep -q E_NOTIMPL &> /dev/null && {
755 echo -e "Function not implemented: 7z cannot delete files from solid archive." >&2
756 wrapper_status=$E_UNSUPPORTED
757 }
758 shift 1;
759 done
760 exit $E_UNSUPPORTED
761 ;;
763 -e) # extract: from archive passed files
764 for ext in $TAR_EXTS $GZIP_EXTS $BZIP2_EXTS $COMPRESS_EXTS $LZMA_EXTS \
765 $IPK_EXTS $XZ_EXTS; do
766 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
767 # xarchive will put is the right extract dir
768 # so we just have to extract.
769 $DECOMPRESS "$archive" | tar -xf - "$@"
770 exit $?
771 fi
772 done
774 while read exe exts; do
775 [ "$(which $exe)" ] || continue
776 for ext in $exts; do
777 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
778 if [ -n "$1" ]; then
779 while [ "$1" ]; do
780 $exe "$archive" | cpio -idv "$1"
781 shift 1
782 done
783 else
784 $exe "$archive" | cpio -idv
785 fi
786 exit $?
787 fi
788 done
789 done <<EOT
790 rpm2cpio $RPM_EXTS
791 do_decompress $CPIO_EXTS $CPIOGZ_EXTS $CPIOXZ_EXTS
792 tazpkg2cpio $TAZPKG_EXTS
793 EOT
795 while read exe args exts; do
796 [ "$(which $exe)" ] || continue
797 for ext in $exts; do
798 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
799 $exe $args "$archive" "$@"
800 exit $?
801 fi
802 done
803 done <<EOT
804 loop_fs copy $ISO_EXTS $SQUASHFS_EXTS $CROMFS_EXTS $CLOOP_EXTS $FS_EXTS
805 unzip -n $ZIP_EXTS
806 dpkg-deb -X $DEB_EXTS
807 lha x $LHA_EXTS
808 lzop -x $LZO_EXTS
809 EOT
810 while read exe args argpass exts; do
811 [ "$(which $exe)" ] || continue
812 for ext in $exts; do
813 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
814 [ $exe != unace ] && $exe $args "$archive" "$@"
815 if [ "$?" -ne "0" ] && [ "$XTERM_PROG" ]; then
816 echo Probably password protected,
817 echo Opening an x-terminal...
818 $XTERM_PROG -e $exe $argpass "$archive" "$@"
819 fi
820 exit 0
821 fi
822 done
823 done <<EOT
824 rar x\ -o-\ -p- x\ -o- $RAR_EXTS
825 arj x\ -y x\ -y\ -g? arj
826 7za x\ -y\ -p- x\ -y 7z
827 unace -UNUSED- x\ -o\ -y ace
828 EOT
829 exit $E_UNSUPPORTED
830 ;;
832 *) echo "error, option $opt not supported"
833 echo "use one of these:"
834 echo "-i #info"
835 echo "-o archive #open"
836 echo "-a archive files #add"
837 echo "-n archive file #new"
838 echo "-r archive files #remove"
839 echo "-e archive files #extract"
840 exit
841 esac