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

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