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

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