wok-next diff xarchive/stuff/slitaz-wrap.sh @ rev 7062
Up: gogglesmm to 0.11.3.
author | Christopher Rogers <slaxemulator@gmail.com> |
---|---|
date | Mon Nov 01 21:06:38 2010 +0000 (2010-11-01) |
parents | ea802196d3e8 |
children | 4a1a5d881605 |
line diff
1.1 --- a/xarchive/stuff/slitaz-wrap.sh Fri Mar 26 22:01:29 2010 +0100 1.2 +++ b/xarchive/stuff/slitaz-wrap.sh Mon Nov 01 21:06:38 2010 +0000 1.3 @@ -61,9 +61,16 @@ 1.4 # the shifting will leave the files passed as all the remaining args "$@" 1.5 opt="$1" 1.6 archive="$2" 1.7 -lc_ext="$(echo ${2##*.} |tr [:upper:] [:lower:])" 1.8 +lc="$(echo $2|tr [:upper:] [:lower:])" 1.9 shift 2 1.10 1.11 +in_exts() 1.12 +{ 1.13 +for i in $@; do 1.14 + [ $(expr "$lc" : ".*\."$i"$") -gt 0 ] && break 1.15 +done 1.16 +} 1.17 + 1.18 tazpkg2cpio() 1.19 { 1.20 tmp="$(mktemp -d -t tmpcpio.XXXXXX)" 1.21 @@ -83,13 +90,12 @@ 1.22 DECOMPRESS="cat" 1.23 COMPRESS="cat" 1.24 while read d c exts; do 1.25 - case " $exts " in *\ $lc_ext\ *) 1.26 - [ "$d" == "${d% *}" -o "$(which ${d% *})" ] || exit $UNSUPPORTED 1.27 - DECOMPRESS="$d" 1.28 - COMPRESS="$c" 1.29 - [ "$(which ${c% *})" ] || COMPRESS="false" 1.30 - break 1.31 - esac 1.32 + in_exts $exts || continue 1.33 + [ "$d" == "${d% *}" -o "$(which ${d% *})" ] || exit $UNSUPPORTED 1.34 + DECOMPRESS="$d" 1.35 + COMPRESS="$c" 1.36 + [ "$(which ${c% *})" ] || COMPRESS="false" 1.37 + break 1.38 done <<EOT 1.39 unlzma\ -c lzma\ e\ -si\ -so $LZMA_EXTS 1.40 bunzip2\ -c bzip2\ -c $BZIP2_EXTS 1.41 @@ -123,11 +129,6 @@ 1.42 exit $status 1.43 } 1.44 1.45 -not_busybox() 1.46 -{ 1.47 -[ "$(basename $(readlink $(which $1)))" != "busybox" ] 1.48 -} 1.49 - 1.50 addcpio() 1.51 { 1.52 find $@ | cpio -o -H newc 1.53 @@ -155,10 +156,9 @@ 1.54 shift 1.55 tmp="$(mktemp -d -t fstmp.XXXXXX)" 1.56 while read command umnt exts; do 1.57 - case " $exts " in *\ $lc_ext\ *) 1.58 - $command "$archive" $tmp 1.59 - break 1.60 - esac 1.61 + in_exts $exts || continue 1.62 + $command "$archive" $tmp 1.63 + break 1.64 done <<EOT 1.65 cromfs-driver fusermount\ -u $CROMFS_EXTS 1.66 mount\ -o\ loop=/dev/cloop,ro umount\ -d $CLOOP_EXTS 1.67 @@ -191,44 +191,42 @@ 1.68 action=$1 1.69 shift 1.70 tardir="$(dirname "$archive")" 1.71 -if not_busybox tar && [ "$action" != "-n" ]; then 1.72 - case " $TAR_EXTS $XZ_EXTS $LRZIP_EXTS " in *\ $lc_ext\ *) 1.73 - decompress_func 1.74 - case "$action" in 1.75 - -r) tar --delete -f "$archive" "$@";; 1.76 - -a) cd "$tardir" 1.77 - while [ -n "$1" ]; do 1.78 - tar -rf "$archive" "${1#$tardir/}" 1.79 - done 1.80 - esac 1.81 - compress_func 1.82 +if [ "$(readlink /bin/tar)" != "busybox" ] && [ "$action" != "-n" ] && 1.83 + in_exts $TAR_EXTS $XZ_EXTS $LRZIP_EXTS ; then 1.84 + decompress_func 1.85 + case "$action" in 1.86 + -r) tar --delete -f "$archive" "$@";; 1.87 + -a) cd "$tardir" 1.88 + while [ -n "$1" ]; do 1.89 + tar -rf "$archive" "${1#$tardir/}" 1.90 + done 1.91 esac 1.92 + compress_func 1.93 fi 1.94 while read add extract exts; do 1.95 - case " $exts " in *\ $lc_ext\ *) 1.96 - if [ "$action" = "-n" ]; then 1.97 - decompress_func 1.98 - cd "$tardir" 1.99 - $add "${1#$tardir/}" > "$archive" 1.100 - compress_func 1.101 - fi 1.102 - tmp="$(mktemp -d -t tartmp.XXXXXX)" 1.103 - cd $tmp 1.104 - $DECOMPRESS "$archive" | $extract 1.105 + in_exts $exts || continue 1.106 + if [ "$action" = "-n" ]; then 1.107 + decompress_func 1.108 + cd "$tardir" 1.109 + $add "${1#$tardir/}" > "$archive" 1.110 + compress_func 1.111 + fi 1.112 + tmp="$(mktemp -d -t tartmp.XXXXXX)" 1.113 + cd $tmp 1.114 + $DECOMPRESS "$archive" | $extract 1.115 + status=$? 1.116 + if [ $status -eq 0 -a -n "$1" ]; then 1.117 + while [ "$1" ]; do 1.118 + ${action#-}_file "${1#$tardir/}" $here 1.119 + shift 1.120 + done 1.121 + $add $(ls -a | grep -v ^\.$ | grep -v ^\.\.$) | \ 1.122 + $COMPRESS > "$archive" 1.123 status=$? 1.124 - if [ $status -eq 0 -a -n "$1" ]; then 1.125 - while [ "$1" ]; do 1.126 - ${action#-}_file "${1#$tardir/}" $here 1.127 - shift 1.128 - done 1.129 - $add $(ls -a | grep -v ^\.$ | grep -v ^\.\.$) | \ 1.130 - $COMPRESS > "$archive" 1.131 - status=$? 1.132 - fi 1.133 - cd - >/dev/null 1.134 - rm -rf $tmp 1.135 - exit $status 1.136 - esac 1.137 + fi 1.138 + cd - >/dev/null 1.139 + rm -rf $tmp 1.140 + exit $status 1.141 done <<EOT 1.142 tar\ -cf\ - tar\ -xf\ - $TAR_EXTS $XZ_EXTS $LRZIP_EXTS 1.143 addcpio cpio\ -id\ >\ /dev/null $CPIO_EXTS $CPIOXZ_EXTS $CPIOLRZIP_EXTS 1.144 @@ -294,7 +292,6 @@ 1.145 $AWK_PROG -v uuid=$(id -u -n) "$AWK_MISC $1" 1.146 } 1.147 1.148 - 1.149 # main: option switches 1.150 case "$opt" in 1.151 -i) # info: output supported extentions for progs that exist 1.152 @@ -327,8 +324,7 @@ 1.153 -o) # open: mangle output for xarchive 1.154 while read filter exts; do 1.155 # lrwxrwxrwx USR/GRP 0 2005-05-12 00:32:03 file -> /path/to/link 1.156 - case " $exts " in *\ $lc_ext\ *) 1.157 - $DECOMPRESS "$archive" | $filter | awk0 ' 1.158 + in_exts $exts && $DECOMPRESS "$archive" | $filter | awk0 ' 1.159 { 1.160 attr=$1 1.161 size=$3 1.162 @@ -336,14 +332,13 @@ 1.163 time=$5 1.164 show($5 " ") 1.165 }' 1.166 - esac 1.167 done <<EOT 1.168 cpio\ -tv $CPIO_EXTS $CPIOXZ_EXTS $CPIOLRZIP_EXTS $RPM_EXTS $TAZPKG_EXTS 1.169 tar\ -tvf\ - $TAR_EXTS $XZ_EXTS $LRZIP_EXTS $IPK_EXTS 1.170 dpkg_c $DEB_EXTS 1.171 EOT 1.172 loop_fs $opt 1.173 - case " $ZIP_EXTS " in *\ $lc_ext\ *) 1.174 + if in_exts $ZIP_EXTS; then 1.175 if [ "$(which zipinfo)" ]; then 1.176 # -rw-r--r-- 2.3 unx 11512 tx defN YYYYMMDD.HHMMSS file 1.177 zipinfo -T -s-h-t "$archive" | awku ' 1.178 @@ -364,22 +359,21 @@ 1.179 show($3 " ") 1.180 }' 1.181 fi 1.182 - esac 1.183 + fi 1.184 # -----------+---------------------+------- 1.185 # 6622 | 22.04.2005 12:29:14 | file 1.186 - [ "$lc_ext" == "cab" ] && cabextract -q -l "$archive" | awku ' 1.187 + in_exts cab && cabextract -q -l "$archive" | awku ' 1.188 /[0-9]+ |/ { 1.189 size=$1 1.190 date=$3 1.191 time=$4 1.192 show($4 " | ") 1.193 }' 1.194 - case " $RAR_EXTS " in *\ $lc_ext\ *) 1.195 #------------------------------------- 1.196 # bookmarks/mozilla_bookmarks.html 1.197 # 11512 5231 45% 28-02-05 16:19 -rw-r--r-- F3F3477F m3b 2.9 1.198 # (or 11512 5231 45% 28-02-05 16:19 .D.... 00000000 m3b 2.9) 1.199 - rar v -c- "$archive" | awku ' 1.200 + in_exts $RAR_EXTS && rar v -c- "$archive" | awku ' 1.201 /-[0-9]+-/ { 1.202 getattr($6) 1.203 size=$1 1.204 @@ -390,12 +384,9 @@ 1.205 { 1.206 name=substr($0,2) 1.207 }' 1.208 - esac 1.209 - case "$lc_ext" in 1.210 - ace) 1.211 # Date ³Time ³Packed ³Size ³Ratio³File 1.212 # 17.09.02³00:32³ 394116³ 414817³ 95%³ OggDS0993.exe 1.213 - unace v -c- "$archive" | awku ' 1.214 + in_exts ace && unace v -c- "$archive" | awku ' 1.215 /^[0-9][0-9]\./ { 1.216 # strip the funky little 3 off the end of size 1.217 size=substr($3,1,(length($3)-1)) 1.218 @@ -403,11 +394,9 @@ 1.219 time=substr($1,10,5) 1.220 show($4 " ") 1.221 }' 1.222 - ;; 1.223 - 7z|bcj|bcj2) 1.224 # ------------------- ----- ------------ ------------ ------------ 1.225 # 1992-04-12 11:39:46 ....A 356 ANKETA.FRG 1.226 - 7zr l "$archive" | awku ' 1.227 + in_exts 7z bcj bcj2 && 7zr l "$archive" | awku ' 1.228 /^[0-9]+-/ { 1.229 date=$1 1.230 time=$2 1.231 @@ -419,11 +408,9 @@ 1.232 gsub(/\\/, "/", name) 1.233 display() 1.234 }' 1.235 - esac 1.236 - case " $ARJ_EXTS " in *\ $lc_ext\ *) 1.237 # 001) ANKETA.FRG 1.238 # 3 MS-DOS 356 121 0.340 92-04-12 11:39:46 1 1.239 - arj v "$archive" | awku ' 1.240 + in_exts $ARJ_EXTS && arj v "$archive" | awku ' 1.241 BEGIN { name="" } 1.242 /^[0-9]+\) / { 1.243 display() 1.244 @@ -439,11 +426,9 @@ 1.245 /^[\t ]+SymLink -> / { link=$3; attr="l"substr(attr, 2) } 1.246 /^---/ { display() } 1.247 ' 1.248 - esac 1.249 - case " $LHA_EXTS " in *\ $lc_ext\ *) 1.250 # Desktop/up -> .. 1.251 # lrwxrwxrwx 0/0 0 0 ****** -lhd- 0000 2009-05-03 16:59:03 [2] 1.252 - lha v -q -v "$archive" | awk0 ' 1.253 + in_exts $LHA_EXTS && lha v -q -v "$archive" | awk0 ' 1.254 { 1.255 if ($4 == "") { getlink($0); next } 1.256 attr=$1 1.257 @@ -453,35 +438,30 @@ 1.258 time=$9 1.259 display() 1.260 }' 1.261 - esac 1.262 - case " $LZO_EXTS " in *\ $lc_ext\ *) 1.263 # ------ ------ ------ ----- ---- ---- ---- 1.264 # LZO1X-1 10057 5675 56.4% 2005-07-25 16:26 path/file 1.265 - lzop -Plv "$archive" | awku ' 1.266 + in_exts $LZO_EXTS && lzop -Plv "$archive" | awku ' 1.267 /-[0-9]+-/ { 1.268 size=$2 1.269 date=$5 1.270 time=$6 1.271 show($6 " ") 1.272 }' 1.273 - esac 1.274 exit 0 1.275 ;; 1.276 -a|-n) # add to archive / new: create new archive 1.277 update $opt "$@" 1.278 while read exe args exts; do 1.279 - [ "$(which $exe)" ] || continue 1.280 + in_exts $exts && [ "$(which $exe)" ] || continue 1.281 [ "$opt$exe" = "-nzip" ] && args="-r" 1.282 - case " $exts " in *\ $lc_ext\ *) 1.283 - # only add the file's basename, not the full path 1.284 - while [ "$1" ]; do 1.285 - cd "$(dirname "$1")" 1.286 - $exe $args "$archive" "$(basename "$1")" 1.287 - status=$? 1.288 - shift 1.289 - done 1.290 - exit $status 1.291 - esac 1.292 + # only add the file's basename, not the full path 1.293 + while [ "$1" ]; do 1.294 + cd "$(dirname "$1")" 1.295 + $exe $args "$archive" "$(basename "$1")" 1.296 + status=$? 1.297 + shift 1.298 + done 1.299 + exit $status 1.300 done <<EOT 1.301 zip -g\ -r $ZIP_EXTS 1.302 rar a $RAR_EXTS 1.303 @@ -493,14 +473,12 @@ 1.304 -r) # remove from archive passed files 1.305 update $opt "$@" 1.306 while read exe args exts; do 1.307 - [ "$(which $exe)" ] || continue 1.308 - case " $exts " in *\ $lc_ext\ *) 1.309 - $exe $args "$archive" "$@" | grep -q E_NOTIMPL && { 1.310 - echo -e "7z cannot delete files from solid archive." >&2 1.311 - exit $UNSUPPORTED 1.312 - } 1.313 - exit 0 1.314 - esac 1.315 + in_exts $exts && [ "$(which $exe)" ] || continue 1.316 + $exe $args "$archive" "$@" | grep -q E_NOTIMPL && { 1.317 + echo -e "7z cannot delete files from solid archive." >&2 1.318 + exit $UNSUPPORTED 1.319 + } 1.320 + exit 0 1.321 done <<EOT 1.322 zip -d $ZIP_EXTS 1.323 rar d $RAR_EXTS 1.324 @@ -511,26 +489,23 @@ 1.325 ;; 1.326 -e) # extract from archive passed files 1.327 while read arch exts; do 1.328 - case " $exts " in *\ $lc_ext\ *) 1.329 - $DECOMPRESS "$archive" | $arch "$@" 1.330 - exit $? 1.331 - esac 1.332 + in_exts $exts || continue 1.333 + $DECOMPRESS "$archive" | $arch "$@" 1.334 + exit $? 1.335 done <<EOT 1.336 tar\ -xf\ - $TAR_EXTS $IPK_EXTS $XZ_EXTS $LRZIP_EXTS 1.337 cpio\ -idm $CPIO_EXTS $CPIOXZ_EXTS $CPIOLRZIP_EXTS $RPM_EXTS $TAZPKG_EXTS 1.338 EOT 1.339 while read exe x p exts; do 1.340 - [ "$(which $exe)" ] || continue 1.341 - case " $exts " in *\ $lc_ext\ *) 1.342 - [ "$x" != "N/A" ] && $exe $x "$archive" "$@" 1.343 - status=$? 1.344 - if [ "$p" != "N/A" -a $status -ne 0 ]; then 1.345 - echo Password protected, opening an x-term... 1.346 - $XTERM_PROG -e $exe $p "$archive" "$@" 1.347 - exit $? 1.348 - fi 1.349 - exit $status 1.350 - esac 1.351 + in_exts $exts && [ "$(which $exe)" ] || continue 1.352 + [ "$x" != "N/A" ] && $exe $x "$archive" "$@" 1.353 + status=$? 1.354 + if [ "$p" != "N/A" -a $status -ne 0 ]; then 1.355 + echo Password protected, opening an x-term... 1.356 + $XTERM_PROG -e $exe $p "$archive" "$@" 1.357 + exit $? 1.358 + fi 1.359 + exit $status 1.360 done <<EOT 1.361 unzip -n N/A $ZIP_EXTS 1.362 dpkg-deb -X N/A $DEB_EXTS