wok-4.x annotate xarchive/stuff/slitaz-wrap.sh @ rev 4355

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