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

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