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

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