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