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

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