wok-next diff xarchive/stuff/slitaz-wrap.sh @ rev 2877
remove xarchive-extras
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Mon May 04 13:35:07 2009 +0200 (2009-05-04) |
parents | 2093d8f83439 |
children | c50152520c0a |
line diff
1.1 --- a/xarchive/stuff/slitaz-wrap.sh Sun Feb 01 10:41:34 2009 +0000 1.2 +++ b/xarchive/stuff/slitaz-wrap.sh Mon May 04 13:35:07 2009 +0200 1.3 @@ -1,7 +1,7 @@ 1.4 #!/bin/sh 1.5 # slitaz-wrap.sh - sh slitaz core wrapper for xarchive frontend 1.6 # Copyright (C) 2005 Lee Bigelow <ligelowbee@yahoo.com> 1.7 -# Copyright (C) 2008 Pascal Bellard <pascal.bellard@slitaz.org> 1.8 +# Copyright (C) 2009 Pascal Bellard <pascal.bellard@slitaz.org> 1.9 # 1.10 # This program is free software; you can redistribute it and/or modify 1.11 # it under the terms of the GNU General Public License as published by 1.12 @@ -38,6 +38,8 @@ 1.13 CROMFS_EXTS="cromfs" 1.14 FS_EXTS="ext2 ext3 dos fat vfat fd fs loop" 1.15 CLOOP_EXTS="cloop" 1.16 +RAR_EXTS="rar cbr" 1.17 +LHA_EXTS="lha lzh lzs" 1.18 1.19 # Setup awk program 1.20 AWK_PROGS="mawk gawk awk" 1.21 @@ -49,6 +51,16 @@ 1.22 fi 1.23 done 1.24 1.25 +# Setup xterm program to use 1.26 +XTERM_PROGS="xterm rxvt xvt wterm aterm Eterm" 1.27 +XTERM_PROG="" 1.28 +for xtermprog in $XTERM_PROGS; do 1.29 + if [ "$(which $xtermprog)" ]; then 1.30 + XTERM_PROG="$xtermprog" 1.31 + break 1.32 + fi 1.33 +done 1.34 + 1.35 # setup variables opt and archive. 1.36 # the shifting will leave the files passed as 1.37 # all the remaining args "$@" 1.38 @@ -57,6 +69,16 @@ 1.39 archive="$1" 1.40 test -z $1 || shift 1 1.41 1.42 +tazpkg2cpio() 1.43 +{ 1.44 + tmpcpio="$(mktemp -d -t tmpcpio.XXXXXX)" 1.45 + cd $tmpcpio 1.46 + cpio -i fs.cpio.gz > /dev/null < "$1" 1.47 + zcat fs.cpio.gz 1.48 + cd - 1.49 + rm -rf $tmpcpio 1.50 +} 1.51 + 1.52 decompress_ipk() 1.53 { 1.54 tar xOzf "$1" ./data.tar.gz | gzip -dc 1.55 @@ -98,10 +120,15 @@ 1.56 fi 1.57 done 1.58 1.59 +do_decompress() 1.60 +{ 1.61 + $DECOMPRESS "$1" 1.62 +} 1.63 + 1.64 # Compression functions 1.65 decompress_func() 1.66 { 1.67 - if [ "$DECOMPRESS" ]; then 1.68 + if [ "$DECOMPRESS" != "cat" ]; then 1.69 tmpname="$(mktemp -t tartmp.XXXXXX)" 1.70 if [ -f "$archive" ]; then 1.71 $DECOMPRESS "$archive" > "$tmpname" 1.72 @@ -115,7 +142,7 @@ 1.73 1.74 compress_func() 1.75 { 1.76 - if [ "$COMPRESS" ] && [ "$oldarch" ]; then 1.77 + if [ "$COMPRESS" != "cat" ] && [ "$oldarch" ]; then 1.78 [ -f "$oldarch" ] && rm "$oldarch" 1.79 if $COMPRESS < "$archive" > "$oldarch"; then 1.80 rm "$archive" 1.81 @@ -131,6 +158,26 @@ 1.82 return 0 1.83 } 1.84 1.85 +addtar() 1.86 +{ 1.87 + tar -cf - $@ 1.88 +} 1.89 + 1.90 +extracttar() 1.91 +{ 1.92 + tar -xf - 1.93 +} 1.94 + 1.95 +addcpio() 1.96 +{ 1.97 + find $@ | cpio -o -H newc 1.98 +} 1.99 + 1.100 +extractcpio() 1.101 +{ 1.102 + cpio -id > /dev/null 1.103 +} 1.104 + 1.105 add_file() 1.106 { 1.107 ( cd $2 ; tar -cf - $1 ) | tar -xf - 1.108 @@ -146,42 +193,50 @@ 1.109 action=$1 1.110 shift 1.111 tardir="$(dirname "$archive")" 1.112 - [ $(expr "$lc_archive" : ".*\."$BZIP2_EXTS"$") -gt 0 ] && ! which bzip2 && return 1.113 - for ext in $TAR_EXTS $GZIP_EXTS $BZIP2_EXTS $COMPRESS_EXTS $LZMA_EXTS; do 1.114 - if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.115 - if [ "$action" = "new_archive" ]; then 1.116 - decompress_func 1.117 - cd "$tardir" 1.118 - tar -cf "$archive" "${1#$tardir/}" 1.119 - status=$? 1.120 - compress_func 1.121 - exit $status 1.122 - fi 1.123 - if not_busybox tar; then 1.124 + if [ $(expr "$lc_archive" : ".*\."$BZIP2_EXTS"$") -gt 0 ]; then 1.125 + [ "$(which bzip2)" ] || return 1.126 + fi 1.127 + if not_busybox tar && [ "$action" != "new_archive" ]; then 1.128 + for ext in $TAR_EXTS $GZIP_EXTS $BZIP2_EXTS $COMPRESS_EXTS $LZMA_EXTS; do 1.129 + if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.130 decompress_func 1.131 case "$action" in 1.132 remove_file) 1.133 tar --delete -f "$archive" "$@";; 1.134 add_file) 1.135 cd "$tardir" 1.136 - tar -rf "$archive" "${1#$tardir/}";; 1.137 - *) false;; 1.138 + while [ -n "$1" ]; do 1.139 + tar -rf "$archive" "${1#$tardir/}" 1.140 + done;; 1.141 esac 1.142 status=$? 1.143 compress_func 1.144 exit $status 1.145 + fi 1.146 + done 1.147 + fi 1.148 + while read add extract exts; do 1.149 + for ext in $exts; do 1.150 + if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.151 + if [ "$action" = "new_archive" ]; then 1.152 + decompress_func 1.153 + cd "$tardir" 1.154 + $add "${1#$tardir/}" > "$archive" 1.155 + status=$? 1.156 + compress_func 1.157 + exit $status 1.158 fi 1.159 tmptar="$(mktemp -d -t tartmp.XXXXXX)" 1.160 here="$(pwd)" 1.161 cd $tmptar 1.162 - $DECOMPRESS < "$archive" | tar -xf - 1.163 + $DECOMPRESS "$archive" | $extract 1.164 status=$? 1.165 if [ $status -eq 0 -a -n "$1" ]; then 1.166 - while [ "$1" ]; do 1.167 + while [ "$1" ]; do 1.168 $action "${1#$tardir/}" $here 1.169 shift 1.170 - done 1.171 - tar -cf - $(ls -a | grep -v ^\.$ | grep -v ^\.\.$) | \ 1.172 + done 1.173 + $add $(ls -a | grep -v ^\.$ | grep -v ^\.\.$) | \ 1.174 $COMPRESS > "$archive" 1.175 status=$? 1.176 fi 1.177 @@ -189,57 +244,35 @@ 1.178 rm -rf $tmptar 1.179 exit $status 1.180 fi 1.181 - done 1.182 - for ext in $CPIO_EXTS $CPIOGZ_EXTS; do 1.183 - if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.184 - if [ "$action" = "new_archive" ]; then 1.185 - decompress_func 1.186 - cd "$tardir" 1.187 - echo "${1#$tardir/}" | cpio -o -H newc > "$archive" 1.188 - status=$? 1.189 - compress_func 1.190 - exit $status 1.191 - fi 1.192 - tmpcpio="$(mktemp -d -t cpiotmp.XXXXXX)" 1.193 - here="$(pwd)" 1.194 - cd $tmpcpio 1.195 - $DECOMPRESS "$archive" | cpio -id > /dev/null 1.196 - status=$? 1.197 - if [ $status -eq 0 -a -n "$1" ]; then 1.198 - while [ "$1" ]; do 1.199 - $action "${1#$tardir/}" $here 1.200 - shift 1.201 - done 1.202 - find . | cpio -o -H newc | $COMPRESS > "$archive" 1.203 - status=$? 1.204 - fi 1.205 - cd $here 1.206 - rm -rf $tmpcpio 1.207 - exit $status 1.208 - fi 1.209 - done 1.210 + done 1.211 + done <<EOT 1.212 +addtar extracttar $TAR_EXTS $GZIP_EXTS $BZIP2_EXTS $COMPRESS_EXTS $LZMA_EXTS 1.213 +addcpio extractcpio $CPIO_EXTS $CPIOGZ_EXTS 1.214 +EOT 1.215 } 1.216 1.217 loop_fs() 1.218 { 1.219 tmpfs="$(mktemp -d -t fstmp.XXXXXX)" 1.220 umnt="umount -d" 1.221 + ext=${lc_archive##*.} 1.222 + case " $CROMFS_EXTS " in 1.223 + *\ $ext\ *) umnt="fusermount -u" 1.224 + cromfs-driver "$archive" $tmpfs;; 1.225 + esac 1.226 case " $CLOOP_EXTS " in 1.227 - \ $1\ ) mount -o loop=/dev/cloop,ro "$archive" $tmpfs;; 1.228 + *\ $ext\ *) mount -o loop=/dev/cloop,ro "$archive" $tmpfs;; 1.229 esac 1.230 case " $FS_EXTS " in 1.231 - \ $1\ ) mount -o loop,rw "$archive" $tmpfs;; 1.232 + *\ $ext\ *) mount -o loop,rw "$archive" $tmpfs;; 1.233 esac 1.234 - case " $ISO_EXTS " in 1.235 - \ $1\ ) mount -o loop,ro -t iso9660 "$archive" $tmpfs;; 1.236 + case " $ISO_EXTS $SQUASHFS_EXTS " in 1.237 + *\ $ext\ *) mount -o loop,ro "$archive" $tmpfs;; 1.238 esac 1.239 - case " $SQUASHFS_EXTS " in 1.240 - \ $1\ ) mount -o loop,ro -t squashfs "$archive" $tmpfs;; 1.241 - esac 1.242 - case " $CROMFS_EXTS " in 1.243 - \ $1\ ) cromfs-driver "$archive" $tmpfs; umnt="fusermount -u";; 1.244 - esac 1.245 - case "$2" in 1.246 + rmdir $tmpfs 2> /dev/null && exit $E_UNSUPPORTED 1.247 + cmd=$1 1.248 + shift 1.249 + case "$cmd" in 1.250 stat) find $tmpfs | while read f; do 1.251 [ "$f" = "$tmpfs" ] && continue 1.252 link="-" 1.253 @@ -248,21 +281,22 @@ 1.254 '{ printf "%s;%s\n",$1,substr($2,0,8)}') 1.255 echo "${f#$tmpfs/};$(stat -c "%s;%A;%U;%G" $f);$date;$link" 1.256 done;; 1.257 - copy) if [ -z "$3" ]; then 1.258 + copy) if [ -z "$1" ]; then 1.259 ( cd $tmpfs ; tar cf - . ) | tar xf - 1.260 else 1.261 - while [ -n "$3" ]; do 1.262 - ( cd $tmpfs ; tar cf - "$3" ) | tar xf - 1.263 + while [ -n "$1" ]; do 1.264 + ( cd $tmpfs ; tar cf - "$1" ) | tar xf - 1.265 shift; 1.266 done 1.267 fi;; 1.268 add) tar cf - "$@" | ( cd $tmpfs ; tar xf - );; 1.269 - remove) while [ -n "$3" ]; do 1.270 - rm -rf $tmpfs/$3 1.271 + remove) while [ -n "$1" ]; do 1.272 + rm -rf $tmpfs/$1 1.273 done;; 1.274 esac 1.275 $umnt $tmpfs 1.276 rmdir $tmpfs 1.277 + exit 0 1.278 } 1.279 1.280 # the option switches 1.281 @@ -276,63 +310,41 @@ 1.282 echo warning: zip not found, extract only >/dev/stderr 1.283 fi 1.284 done 1.285 - [ -d /lib/modules/$(uname -r)/kernel/fs/squashfs/squashfs.ko ] && \ 1.286 - for ext in $SQUASHFS_EXTS; do 1.287 - printf "%s;" $ext 1.288 - done 1.289 - [ -x /bin/cromfs-driver ] && for ext in $CROMFS_EXTS; do 1.290 - printf "%s;" $ext 1.291 - done 1.292 - [ -d /lib/modules/$(uname -r)/kernel/drivers/block/cloop.ko ] && \ 1.293 - for ext in $CLOOP_EXTS; do 1.294 - printf "%s;" $ext 1.295 - done 1.296 + while read mod exts; do 1.297 + [ -f /lib/modules/$(uname -r)/kernel/$mod ] || continue 1.298 + for ext in $exts; do 1.299 + printf "%s;" $ext 1.300 + done 1.301 + done <<EOT 1.302 +fs/squashfs/squashfs.ko $SQUASHFS_EXTS 1.303 +drivers/block/cloop.ko $CLOOP_EXTS 1.304 +EOT 1.305 + while read exe exts; do 1.306 + [ "$(which $exe)" ] || continue 1.307 + for ext in $exts; do 1.308 + printf "%s;" $ext 1.309 + done 1.310 + done <<EOT 1.311 +cromfs-driver $CROMFS_EXTS 1.312 +rar $RAR_EXTS 1.313 +unace ace 1.314 +arj arj 1.315 +7za 7z 1.316 +lha $LHA_EXTS 1.317 +EOT 1.318 printf "\n" 1.319 exit 1.320 ;; 1.321 1.322 -o) # open: mangle output of tar cmd for xarchive 1.323 - for ext in $TAR_EXTS $GZIP_EXTS $BZIP2_EXTS $COMPRESS_EXTS $LZMA_EXTS \ 1.324 - $IPK_EXTS; do 1.325 - # format of tar output: 1.326 -# lrwxrwxrwx USR/GRP 0 2005-05-12 00:32:03 file -> /path/to/link 1.327 -# -rw-r--r-- USR/GRP 6622 2005-04-22 12:29:14 file 1.328 -# 1 2 3 4 5 6 1.329 - if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.330 - $DECOMPRESS "$archive" | tar -tvf - | $AWK_PROG ' 1.331 - { 1.332 - attr=$1 1.333 - split($2,ids,"/") #split up the 2nd field to get uid/gid 1.334 - uid=ids[1] 1.335 - gid=ids[2] 1.336 - size=$3 1.337 - date=$4 1.338 - time=$5 1.339 - 1.340 - #this method works with filenames that start with a space (evil!) 1.341 - #split line a time and a space 1.342 - split($0,linesplit, $5 " ") 1.343 - #then split the second item (name&link) at the space arrow space 1.344 - split(linesplit[2], nlsplit, " -> ") 1.345 - 1.346 - name=nlsplit[1] 1.347 - link=nlsplit[2] 1.348 - 1.349 - if (! link) {link="-"} #if there was no link set it to a dash 1.350 - 1.351 - printf "%s;%s;%s;%s;%s;%s;%s;%s\n",name,size,attr,uid,gid,date,time,link 1.352 - }' 1.353 - exit 1.354 - fi 1.355 - done 1.356 - 1.357 - for ext in $CPIO_EXTS $CPIOGZ_EXTS; do 1.358 + while read cmd filter exts; do 1.359 + for ext in $exts; do 1.360 # format of cpio output: 1.361 # lrwxrwxrwx USR/GRP 0 2005-05-12 00:32:03 file -> /path/to/link 1.362 # -rw-r--r-- USR/GRP 6622 2005-04-22 12:29:14 file 1.363 # 1 2 3 4 5 6 1.364 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.365 - $DECOMPRESS "$archive" | cpio -tv | $AWK_PROG ' 1.366 + $cmd "$archive" | $filter | $AWK_PROG ' 1.367 { 1.368 attr=$1 1.369 split($2,ids,"/") #split up the 2nd field to get uid/gid 1.370 @@ -355,13 +367,18 @@ 1.371 1.372 if (name != "" && uid != "blocks") printf "%s;%s;%s;%s;%s;%s;%s;%s\n",name,size,attr,uid,gid,date,time,link 1.373 }' 1.374 - exit 1.375 + exit 0 1.376 fi 1.377 done 1.378 - 1.379 + done <<EOT 1.380 +do_decompress cpio\ -tv $CPIO_EXTS $CPIOGZ_EXTS 1.381 +do_decompress tar\ -tvf\ - $TAR_EXTS $GZIP_EXTS $BZIP2_EXTS $COMPRESS_EXTS $LZMA_EXTS $IPK_EXTS 1.382 +rpm2cpio cpio\ -tv $RPM_EXTS 1.383 +tazpkg2cpio cpio\ -tv $TAZPKG_EXTS 1.384 +EOT 1.385 for ext in $ZIP_EXTS; do 1.386 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.387 - if which zipinfo; then 1.388 + if [ "$(which zipinfo)" ]; then 1.389 # format of zipinfo -T -s-h- output: 1.390 # -rw-r--r-- 2.3 unx 11512 tx defN YYYYMMDD.HHMMSS file 1.391 # 1 2 3 4 5 6 7 8 1.392 @@ -385,7 +402,7 @@ 1.393 name=linesplit[2] 1.394 printf "%s;%s;%s;%s;%s;%s;%s;%s\n",name,size,attr,uid,gid,date,time,link 1.395 }' 1.396 - exit 1.397 + exit 0 1.398 else 1.399 # format of unzip -l output: 1.400 # 6622 2005-04-22 12:29:14 file 1.401 @@ -413,114 +430,198 @@ 1.402 1.403 if (name != "" && n > 3) printf "%s;%s;%s;%s;%s;%s;%s;%s\n",name,size,attr,uid,gid,date,time,link 1.404 }' 1.405 - exit 1.406 + exit 0 1.407 fi 1.408 fi 1.409 done 1.410 1.411 - for ext in $RPM_EXTS; do 1.412 - if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.413 - rpm2cpio "$archive" | cpio -tv | $AWK_PROG ' 1.414 - { 1.415 - attr=$1 1.416 - split($2,ids,"/") #split up the 2nd field to get uid/gid 1.417 - uid=ids[1] 1.418 - gid=ids[2] 1.419 - size=$3 1.420 - date=$4 1.421 - time=$5 1.422 - 1.423 - #this method works with filenames that start with a space (evil!) 1.424 - #split line a time and a space 1.425 - split($0,linesplit, $5 " ") 1.426 - #then split the second item (name&link) at the space arrow space 1.427 - split(linesplit[2], nlsplit, " -> ") 1.428 - 1.429 - name=substr(nlsplit[1],2) 1.430 - link=nlsplit[2] 1.431 - 1.432 - if (! link) {link="-"} #if there was no link set it to a dash 1.433 - 1.434 - if (name != "" && uid != "blocks") printf "%s;%s;%s;%s;%s;%s;%s;%s\n",name,size,attr,uid,gid,date,time,link 1.435 - }' 1.436 - exit 1.437 - fi 1.438 - done 1.439 - 1.440 - for ext in $DEB_EXTS; do 1.441 - if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.442 - dpkg-deb -c "$archive" | $AWK_PROG ' 1.443 - { 1.444 - attr=$1 1.445 - split($2,ids,"/") #split up the 2nd field to get uid/gid 1.446 - uid=ids[1] 1.447 - gid=ids[2] 1.448 - size=$3 1.449 - date=$4 1.450 - time=$5 1.451 - 1.452 - #this method works with filenames that start with a space (evil!) 1.453 - #split line a time and a space 1.454 - split($0,linesplit, $5 " ") 1.455 - #then split the second item (name&link) at the space arrow space 1.456 - split(linesplit[2], nlsplit, " -> ") 1.457 - 1.458 - name=substr(nlsplit[1],2) 1.459 - link=nlsplit[2] 1.460 - 1.461 - if (! link) {link="-"} #if there was no link set it to a dash 1.462 - 1.463 - printf "%s;%s;%s;%s;%s;%s;%s;%s\n",name,size,attr,uid,gid,date,time,link 1.464 - }' 1.465 - exit 1.466 - fi 1.467 - done 1.468 - 1.469 - for ext in $TAZPKG_EXTS; do 1.470 - # format of cpio output: 1.471 -# lrwxrwxrwx USR/GRP 0 2005-05-12 00:32:03 file -> /path/to/link 1.472 -# -rw-r--r-- USR/GRP 6622 2005-04-22 12:29:14 file 1.473 -# 1 2 3 4 5 6 1.474 - if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.475 - tmpcpio="$(mktemp -d -t cpiotmp.XXXXXX)" 1.476 - here="$(pwd)" 1.477 - cd $tmpcpio 1.478 - cpio -i fs.cpio.gz > /dev/null < "$archive" 1.479 - zcat fs.cpio.gz | cpio -tv | $AWK_PROG ' 1.480 - { 1.481 - attr=$1 1.482 - split($2,ids,"/") #split up the 2nd field to get uid/gid 1.483 - uid=ids[1] 1.484 - gid=ids[2] 1.485 - size=$3 1.486 - date=$4 1.487 - time=$5 1.488 - 1.489 - #this method works with filenames that start with a space (evil!) 1.490 - #split line a time and a space 1.491 - split($0,linesplit, $5 " ") 1.492 - #then split the second item (name&link) at the space arrow space 1.493 - split(linesplit[2], nlsplit, " -> ") 1.494 - 1.495 - name=substr(nlsplit[1],3) 1.496 - link=nlsplit[2] 1.497 - 1.498 - if (! link) {link="-"} #if there was no link set it to a dash 1.499 - 1.500 - if (name != "" && uid != "blocks") printf "%s;%s;%s;%s;%s;%s;%s;%s\n",name,size,attr,uid,gid,date,time,link 1.501 - }' 1.502 - cd $here 1.503 - rm -rf $tmpcpio 1.504 - exit 1.505 - fi 1.506 - done 1.507 - 1.508 for ext in $ISO_EXTS $SQUASHFS_EXTS $CROMFS_EXTS $CLOOP_EXTS $FS_EXTS; do 1.509 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.510 - loop_fs $ext stat 1.511 - exit 1.512 + loop_fs stat 1.513 fi 1.514 done 1.515 + for ext in $RAR_EXTS; do 1.516 + if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.517 + # format of rar output: 1.518 +#------------------------------------- 1.519 +# bookmarks/mozilla_bookmarks.html 1.520 +# 11512 5231 45% 28-02-05 16:19 -rw-r--r-- F3F3477F m3b 2.9 1.521 +# (or 11512 5231 45% 28-02-05 16:19 .D.... 00000000 m3b 2.9) 1.522 +# (or 11512 5231 45% 28-02-05 16:19 .....S F3F3477F m3b 2.9) 1.523 +# 1 2 3 4 5 6 7 8 9 1.524 +#------------------------------------- 1.525 + 1.526 + rar v -c- "$archive" | $AWK_PROG -v uuid=$(id -u -n) ' 1.527 + # The body of info we wish to process starts with a dashed line 1.528 + # so set a flag to signal when to start and stop processing. 1.529 + # The name is on one line with the info on the next so toggle 1.530 + # a line flag letting us know what kinda info to get. 1.531 + BEGIN { flag=0; line=0 } 1.532 + /^------/ { flag++; if (flag > 1) exit 0; next} #line starts with dashs 1.533 + { 1.534 + if (flag == 0) next #not in the body yet so grab the next line 1.535 + if (line == 0) #this line contains the name 1.536 + { 1.537 + name=substr($0,2) #strip the single space from start of name 1.538 + line++ #next line will contain the info so increase the flag 1.539 + next 1.540 + } 1.541 + else #we got here so this line contains the info 1.542 + { 1.543 + size=$1 1.544 + date=$4 1.545 + time=$5 1.546 + 1.547 + #modify attributes to read more unix like if they are not 1.548 + if (index($6, "D") != 0) {attr="drwxr-xr-x"} 1.549 + else if (index($6, ".") != 0) {attr="-rw-r--r--"} 1.550 + else {attr=$6} 1.551 + 1.552 + uid=uuid 1.553 + gid=uuid 1.554 + link="-" 1.555 + 1.556 + printf "%s;%s;%s;%s;%s;%s;%s;%s\n",name,size,attr,uid,gid,date,time,link 1.557 + line=0 #next line will be a name so reset the flag 1.558 + } 1.559 + }' 1.560 + exit 0 1.561 + fi 1.562 + done 1.563 + for ext in ace; do 1.564 + if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.565 + # format of ace output: 1.566 + # Date ³Time ³Packed ³Size ³Ratio³File 1.567 + # 17.09.02³00:32³ 394116³ 414817³ 95%³ OggDS0993.exe 1.568 + # 1 2 3 4 5 1.569 + unace v -c- "$archive" | $AWK_PROG -v uuid=$(id -u -n) ' 1.570 + #only process lines starting with two numbers and a dot 1.571 + /^[0-9][0-9]\./ { 1.572 + date=substr($1,1,8) 1.573 + time=substr($1,10,5) 1.574 + #need to strip the funky little 3 off the end of size 1.575 + size=substr($3,1,(length($3)-1)) 1.576 + 1.577 + #split line at ratio and a space, second item is our name 1.578 + split($0, linesplit, ($4 " ")) 1.579 + name=linesplit[2] 1.580 + 1.581 + uid=uuid; gid=uuid; link="-"; attr="-" 1.582 + printf "%s;%s;%s;%s;%s;%s;%s;%s\n",name,size,attr,uid,gid,date,time,link 1.583 + }' 1.584 + exit 0 1.585 + fi 1.586 + done 1.587 + for ext in arj; do 1.588 + if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.589 + # format of arj output: 1.590 + # 001) ANKETA.FRG 1.591 + # 3 MS-DOS 356 121 0.340 92-04-12 11:39:46 1 1.592 + 1.593 + arj v "$archive" | $AWK_PROG -v uuid=$(id -u -n) '{ 1.594 + if (($0 ~ /^[0-9]+\) .*/)||($0 ~ /^------------ ---------- ---------- -----/)){ 1.595 + if (filestr ~ /^[0-9]+\) .*/) { 1.596 + 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 1.597 + perm="" 1.598 + file="" 1.599 + symfile="" 1.600 + filestr="" 1.601 + } 1.602 + } 1.603 + 1.604 + if ($0 ~ /^[0-9]+\) .*/) { 1.605 + filestr=$0 1.606 + sub(/^[0-9]*\) /, "") 1.607 + file=$0 1.608 + uid=uuid 1.609 + gid=0 1.610 + } 1.611 + 1.612 + 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].*/) { 1.613 + size=$3 1.614 + split($6, date, "-") 1.615 + split($7, time, ":") 1.616 + if ($8 ~ /^[rwx-]/) {perm=$8;} else {perm="-rw-r--r--"} 1.617 + } 1.618 + 1.619 + if ($0 ~ /^[\t ]+SymLink -> .*/) { 1.620 + symfile = $3 1.621 + perm="l"substr(perm, 2) 1.622 + } else {symfile="-"} 1.623 + 1.624 + if ($0 ~ /^[\t ]+Owner: UID [0-9]+\, GID [0-9]+/) { 1.625 + uid=$3 1.626 + gid=$5 1.627 + owner=1 1.628 + } 1.629 + }' 1.630 + exit 0 1.631 + fi 1.632 + done 1.633 + for ext in 7z; do 1.634 + if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.635 + # format of 7za output: 1.636 + # ------------------- ----- ------------ ------------ ------------ 1.637 + # 1992-04-12 11:39:46 ....A 356 ANKETA.FRG 1.638 + 1.639 + 7za l "$archive" | $AWK_PROG -v uuid=$(id -u -n) ' 1.640 + BEGIN { flag=0; } 1.641 + /^-------/ { flag++; if (flag > 1) exit 0; next } 1.642 + { 1.643 + if (flag == 0) next 1.644 + 1.645 + year=substr($1, 1, 4) 1.646 + month=substr($1, 6, 2) 1.647 + day=substr($1, 9, 2) 1.648 + time=substr($2, 1, 5) 1.649 + 1.650 + if (index($3, "D") != 0) {attr="drwxr-xr-x"} 1.651 + else if (index($3, ".") != 0) {attr="-rw-r--r--"} 1.652 + 1.653 + size=$4 1.654 + 1.655 + $0=substr($0, 54) 1.656 + if (NF > 1) {name=$0} 1.657 + else {name=$1} 1.658 + gsub(/\\/, "/", name) 1.659 + 1.660 + printf "%s;%d;%s;%d;%d;%d-%02d-%02d;%s;-\n", name, size, attr, uid, 0, year, month, day, time 1.661 + }' 1.662 + exit 0 1.663 + fi 1.664 + done 1.665 + for ext in $LHA_EXTS; do 1.666 + if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.667 + # format of lha output: 1.668 + # Desktop/up -> .. 1.669 + # lrwxrwxrwx 0/0 0 0 ****** -lhd- 0000 2009-05-03 16:59:03 [2] 1.670 + 1.671 + lha v -q -v "$archive" | $AWK_PROG ' 1.672 + { 1.673 + if ($4 == "") { 1.674 + split($0, nlsplit, " -> ") 1.675 + name=nlsplit[1] 1.676 + link=nlsplit[2] 1.677 + if (! link) {link="-"} 1.678 + next 1.679 + } 1.680 + attr=$1 1.681 + ids=$2 1.682 + split($2,ids,"/") #split up the 2nd field to get uid/gid 1.683 + uid=ids[1] 1.684 + gid=ids[2] 1.685 + size=$4 1.686 + 1.687 + year=substr($8, 1, 4) 1.688 + month=substr($8, 6, 2) 1.689 + day=substr($8, 9, 2) 1.690 + time=substr($9, 1, 5) 1.691 + 1.692 + printf "%s;%d;%s;%d;%d;%d-%02d-%02d;%s;-\n", name, size, attr, uid, gid, year, month, day, time 1.693 + }' 1.694 + exit 0 1.695 + fi 1.696 + done 1.697 exit $E_UNSUPPORTED 1.698 ;; 1.699 1.700 @@ -528,51 +629,84 @@ 1.701 update_tar_cpio add_file "$@" 1.702 for ext in $FS_EXTS; do 1.703 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.704 - loop_fs $ext add "$@" 1.705 - exit 0 1.706 + loop_fs add "$@" 1.707 fi 1.708 done 1.709 - which zip >/dev/null && for ext in $ZIP_EXTS; do 1.710 + while read exe args exts; do 1.711 + [ "$(which $exe)" ] || continue 1.712 + for ext in $exts; do 1.713 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.714 # we only want to add the file's basename, not 1.715 # the full path so... 1.716 while [ "$1" ]; do 1.717 cd "$(dirname "$1")" 1.718 - zip -g -r "$archive" "$(basename "$1")" 1.719 + $exe $args "$archive" "$(basename "$1")" 1.720 wrapper_status=$? 1.721 shift 1 1.722 done 1.723 exit $wrapper_status 1.724 fi 1.725 - done 1.726 + done 1.727 + done <<EOT 1.728 +zip -g\ -r $ZIP_EXTS 1.729 +rar a $RAR_EXTS 1.730 +arj a arj 1.731 +7za a\ -ms=off 7z 1.732 +lha a $LHA_EXTS 1.733 +EOT 1.734 exit $E_UNSUPPORTED 1.735 ;; 1.736 1.737 -n) # new: create new archive with passed files 1.738 update_tar_cpio new_archive "$@" 1.739 - which zip >/dev/null && for ext in $ZIP_EXTS; do 1.740 + while read exe args exts; do 1.741 + [ "$(which $exe)" ] || continue 1.742 + for ext in $exts; do 1.743 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.744 # create will only be passed the first file, the 1.745 # rest will be "added" to the new archive 1.746 cd "$(dirname "$1")" 1.747 - zip -r "$archive" "$(basename "$1")" 1.748 + $exe $args "$archive" "$(basename "$1")" 1.749 fi 1.750 - done 1.751 + done 1.752 + done <<EOT 1.753 +zip -r $ZIP_EXTS 1.754 +rar a $RAR_EXTS 1.755 +arj a arj 1.756 +7za a\ -ms=off 7z 1.757 +lha a $LHA_EXTS 1.758 +EOT 1.759 exit $E_UNSUPPORTED 1.760 ;; 1.761 1.762 -r) # remove: from archive passed files 1.763 update_tar_cpio remove_file "$@" 1.764 - for ext in $FS_EXTS; do 1.765 + while read exe args exts; do 1.766 + [ "$(which $exe)" ] || continue 1.767 + for ext in $exts; do 1.768 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.769 - loop_fs $ext remove "$@" 1.770 - exit 0 1.771 + $exe $args "$archive" "$@" 1.772 + exit $? 1.773 fi 1.774 - done 1.775 - which zip >/dev/null && for ext in $ZIP_EXTS; do 1.776 - if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.777 - zip -d "$archive" "$@" 1.778 - fi 1.779 + done 1.780 + done <<EOT 1.781 +loop_fs remove $FS_EXTS 1.782 +zip -d $ZIP_EXTS 1.783 +rar d $RAR_EXTS 1.784 +arj d arj 1.785 +lha d $LHA_EXTS 1.786 +EOT 1.787 + wrapper_status=0 1.788 + [ "$(which 7za)" ] && [ $(expr "$lc_archive" : ".*\.7z$") -gt 0 ] && 1.789 + while [ "$1" ]; do 1.790 + 7za l "$archive" 2>/dev/null | grep -q "[.][/]" >&/dev/null \ 1.791 + && EXFNAME=*./"$1" || EXFNAME="$1" 1.792 + 7za d "$archive" "$EXFNAME" 2>&1 \ 1.793 + | grep -q E_NOTIMPL &> /dev/null && { 1.794 + echo -e "Function not implemented: 7z cannot delete files from solid archive." >&2 1.795 + wrapper_status=$E_UNSUPPORTED 1.796 + } 1.797 + shift 1; 1.798 done 1.799 exit $E_UNSUPPORTED 1.800 ;; 1.801 @@ -587,75 +721,61 @@ 1.802 exit $? 1.803 fi 1.804 done 1.805 - for ext in $CPIO_EXTS $CPIOGZ_EXTS; do 1.806 + 1.807 + while read exe exts; do 1.808 + [ "$(which $exe)" ] || continue 1.809 + for ext in $exts; do 1.810 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.811 if [ -n "$1" ]; then 1.812 while [ "$1" ]; do 1.813 - $DECOMPRESS "$archive" | cpio -idv "$1" 1.814 + $exe "$archive" | cpio -idv "$1" 1.815 shift 1 1.816 done 1.817 else 1.818 - $DECOMPRESS "$archive" | cpio -idv 1.819 + $exe "$archive" | cpio -idv 1.820 fi 1.821 exit $? 1.822 fi 1.823 - done 1.824 - for ext in $ZIP_EXTS; do 1.825 + done 1.826 + done <<EOT 1.827 +rpm2cpio $RPM_EXTS 1.828 +do_decompress $CPIO_EXTS $CPIOGZ_EXTS 1.829 +tazpkg2cpio $TAZPKG_EXTS 1.830 +EOT 1.831 + 1.832 + while read exe args exts; do 1.833 + [ "$(which $exe)" ] || continue 1.834 + for ext in $exts; do 1.835 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.836 - # xarchive will put is the right extract dir 1.837 - # so we just have to extract. 1.838 - unzip -n "$archive" "$@" 1.839 + $exe $args "$archive" "$@" 1.840 exit $? 1.841 fi 1.842 done 1.843 - for ext in $RPM_EXTS; do 1.844 + done <<EOT 1.845 +loop_fs copy $ISO_EXTS $SQUASHFS_EXTS $CROMFS_EXTS $CLOOP_EXTS $FS_EXTS 1.846 +unzip -n $ZIP_EXTS 1.847 +dpkg-deb -X $DEB_EXTS 1.848 +lha x $LHA_EXTS 1.849 +EOT 1.850 + while read exe args argpass exts; do 1.851 + [ "$(which $exe)" ] || continue 1.852 + for ext in $exts; do 1.853 if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.854 - if [ -n "$1" ]; then 1.855 - while [ "$1" ]; do 1.856 - rpm2cpio "$archive" | cpio -idv "$1" 1.857 - shift 1 1.858 - done 1.859 - else 1.860 - rpm2cpio "$archive" | cpio -idv 1.861 - fi 1.862 - exit $? 1.863 + [ $exe != unace ] && $exe $args "$archive" "$@" 1.864 + if [ "$?" -ne "0" ] && [ "$XTERM_PROG" ]; then 1.865 + echo Probably password protected, 1.866 + echo Opening an x-terminal... 1.867 + $XTERM_PROG -e $exe $argpass "$archive" "$@" 1.868 + fi 1.869 + exit 0 1.870 fi 1.871 - done 1.872 - 1.873 - for ext in $DEB_EXTS; do 1.874 - if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.875 - dpkg-deb -X "$archive" "$@" 1.876 - exit $? 1.877 - fi 1.878 - done 1.879 - for ext in $TAZPKG_EXTS; do 1.880 - if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.881 - tmpcpio="$(mktemp -d -t cpiotmp.XXXXXX)" 1.882 - here="$(pwd)" 1.883 - cd $tmpcpio 1.884 - cpio -i < "$archive" > /dev/null 1.885 - zcat fs.cpio.gz | cpio -id > /dev/null 1.886 - status=$? 1.887 - if [ -n "$1" ]; then 1.888 - while [ "$1" ]; do 1.889 - dir=$(dirname "$here/$1") 1.890 - mkdir -p "$dir" 2> /dev/null 1.891 - mv "fs/$1" "$dir" 2> /dev/null 1.892 - done 1.893 - else 1.894 - mv fs/* fs/.* $here 2> /dev/null 1.895 - fi 1.896 - cd $here 1.897 - rm -rf $tmpcpio 1.898 - exit $status 1.899 - fi 1.900 - done 1.901 - for ext in $ISO_EXTS $SQUASHFS_EXTS $CROMFS_EXTS $CLOOP_EXTS $FS_EXTS; do 1.902 - if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.903 - loop_fs $ext copy "$@" 1.904 - exit 0 1.905 - fi 1.906 - done 1.907 + done 1.908 + done <<EOT 1.909 +rar x\ -o-\ -p- x\ -o- $RAR_EXTS 1.910 +arj x\ -y x\ -y\ -g? arj 1.911 +7za x\ -y\ -p- x\ -y 7z 1.912 +unace -UNUSED- x\ -o\ -y ace 1.913 +EOT 1.914 exit $E_UNSUPPORTED 1.915 ;; 1.916