wok-current rev 942

xarchive: add iso, sqfs, cromfs support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Jun 24 15:43:13 2008 +0000 (2008-06-24)
parents cee7a7cd19eb
children 52f4a751924a
files xarchive/stuff/slitaz-wrap.sh
line diff
     1.1 --- a/xarchive/stuff/slitaz-wrap.sh	Tue Jun 24 13:47:32 2008 +0000
     1.2 +++ b/xarchive/stuff/slitaz-wrap.sh	Tue Jun 24 15:43:13 2008 +0000
     1.3 @@ -32,6 +32,9 @@
     1.4  RPM_EXTS="rpm"
     1.5  DEB_EXTS="deb"
     1.6  TAZPKG_EXTS="tazpkg"
     1.7 +ISO_EXTS="iso"
     1.8 +SQUASHFS_EXTS="sqfs squashfs"
     1.9 +CROMFS_EXTS="cromfs"
    1.10  
    1.11  # Setup awk program
    1.12  AWK_PROGS="mawk gawk awk"
    1.13 @@ -57,33 +60,28 @@
    1.14  lc_archive="$(echo $archive|tr [:upper:] [:lower:])"
    1.15  DECOMPRESS="cat"
    1.16  COMPRESS="cat"
    1.17 -TAR_COMPRESS_OPT=""
    1.18  for ext in $GZIP_EXTS $CPIOGZ_EXTS; do
    1.19      if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
    1.20          DECOMPRESS="gzip -dc"
    1.21          COMPRESS="gzip -c"
    1.22 -        TAR_COMPRESS_OPT="z"
    1.23      fi
    1.24  done
    1.25  for ext in $BZIP2_EXTS; do
    1.26      if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
    1.27          DECOMPRESS="bzip2 -dc" 
    1.28          COMPRESS="bzip2 -c"
    1.29 -        TAR_COMPRESS_OPT="j"
    1.30      fi
    1.31  done
    1.32  for ext in $LZMA_EXTS; do
    1.33      if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
    1.34          DECOMPRESS="unlzma -c" 
    1.35          COMPRESS="lzma e -si -so"
    1.36 -        TAR_COMPRESS_OPT="a"
    1.37      fi
    1.38  done
    1.39  for ext in $COMPRESS_EXTS; do
    1.40      if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
    1.41          DECOMPRESS="uncompress -dc" 
    1.42          COMPRESS="compress -c"
    1.43 -        TAR_COMPRESS_OPT="--use-compress-prog=compress"
    1.44      fi
    1.45  done
    1.46  
    1.47 @@ -208,17 +206,59 @@
    1.48      done
    1.49  }
    1.50  
    1.51 +loop_fs()
    1.52 +{
    1.53 +    tmpfs="$(mktemp -d -t fstmp.XXXXXX)"
    1.54 +    umnt="umount -d"
    1.55 +    case " $ISO_EXTS " in 
    1.56 +    \ $1\ ) mount -o loop,ro -t iso9660 "$archive" $tmpfs;;
    1.57 +    esac
    1.58 +    case " $SQUASHFS_EXTS " in 
    1.59 +    \ $1\ ) mount -o loop,ro -t squashfs "$archive" $tmpfs;;
    1.60 +    esac
    1.61 +    case " $CROMFS_EXTS " in 
    1.62 +    \ $1\ ) cromfs-driver "$archive" $tmpfs; umnt="fusermount -u";;
    1.63 +    esac
    1.64 +    case "$2" in
    1.65 +    stat)	find $tmpfs | while read f; do
    1.66 +    		    [ "$f" = "$tmpfs" ] && continue
    1.67 +		    link="-"
    1.68 +		    [ -L "$f" ] && link=$(readlink "$f")
    1.69 +		    date=$(stat -c "%y" $f | awk \
    1.70 +		    	'{ printf "%s;%s\n",$1,substr($2,0,8)}')
    1.71 +		    echo "${f#$tmpfs/};$(stat -c "%s;%A;%U;%G" $f);$date;$link"
    1.72 +    		done;;
    1.73 +    copy)	if [ -z "$3" ]; then
    1.74 +    		    ( cd $tmpfs ; tar cf - . ) | tar xf -
    1.75 +    		else
    1.76 +		    while [ -n "$3" ]; do
    1.77 +    			( cd $tmpfs ; tar cf - "$3" ) | tar xf -
    1.78 +			shift;
    1.79 +		    done
    1.80 +		fi;;
    1.81 +    esac
    1.82 +    $umnt $tmpfs
    1.83 +    rmdir $tmpfs
    1.84 +}
    1.85 +
    1.86  # the option switches
    1.87  case "$opt" in
    1.88      -i) # info: output supported extentions for progs that exist
    1.89          for ext in $TAR_EXTS $GZIP_EXTS $BZIP2_EXTS $COMPRESS_EXTS $LZMA_EXTS \
    1.90                     $CPIO_EXTS $CPIOGZ_EXTS $ZIP_EXTS $DEB_EXTS $RPM_EXTS \
    1.91 -                   $TAZPKG_EXTS ; do
    1.92 +                   $TAZPKG_EXTS $ISO_EXTS; do
    1.93              printf "%s;" $ext
    1.94              if [ "$ext" = "zip" -a ! "$(which zip)" ]; then
    1.95                  echo warning: zip not found, extract only >/dev/stderr
    1.96              fi
    1.97          done
    1.98 +	[ -d /lib/modules/$(uname -r)/kernel/fs/squashfs/squashfs.ko ] && \
    1.99 +	for ext in $SQUASHFS_EXTS; do
   1.100 +            printf "%s;" $ext
   1.101 +	done
   1.102 +	[ -x /bin/cromfs-driver ] && for ext in $CROMFS_EXTS; do
   1.103 +            printf "%s;" $ext
   1.104 +	done
   1.105          printf "\n"
   1.106          exit
   1.107          ;;
   1.108 @@ -230,7 +270,7 @@
   1.109  # -rw-r--r-- USR/GRP    6622 2005-04-22 12:29:14 file 
   1.110  # 1          2          3    4          5        6
   1.111              if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
   1.112 -                tar -tv${TAR_COMPRESS_OPT}f "$archive" | $AWK_PROG '
   1.113 +		$DECOMPRESS "$archive" | tar -tvf - | $AWK_PROG '
   1.114          {
   1.115            attr=$1
   1.116            split($2,ids,"/") #split up the 2nd field to get uid/gid
   1.117 @@ -443,6 +483,13 @@
   1.118  		cd $here
   1.119  		rm -rf $tmpcpio
   1.120                  exit
   1.121 +	    fi
   1.122 +        done
   1.123 +
   1.124 +        for ext in $ISO_EXTS $SQUASHFS_EXTS $CROMFS_EXTS; do
   1.125 +            if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
   1.126 +	    	loop_fs $ext stat
   1.127 +                exit
   1.128              fi
   1.129  	done
   1.130          exit $E_UNSUPPORTED
   1.131 @@ -494,7 +541,7 @@
   1.132              if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
   1.133                  # xarchive will put is the right extract dir
   1.134                  # so we just have to extract.
   1.135 -		$DECOMPRESS < "$archive" | tar -xf - "$@"
   1.136 +		$DECOMPRESS "$archive" | tar -xf - "$@"
   1.137                  exit $?
   1.138  	    fi
   1.139  	done
   1.140 @@ -561,6 +608,12 @@
   1.141  		exit $status
   1.142  	    fi
   1.143  	done
   1.144 +        for ext in $ISO_EXTS $SQUASHFS_EXTS $CROMFS_EXTS; do
   1.145 +            if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then
   1.146 +	    	loop_fs $ext copy "$@"
   1.147 +                exit 0
   1.148 +            fi
   1.149 +	done
   1.150          exit $E_UNSUPPORTED
   1.151          ;;
   1.152