wok-next diff xarchive/stuff/slitaz-wrap.sh @ rev 799
lxpanel: have nice icons for network status + split netstat/wifi and kbled plugins
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Thu May 15 21:25:18 2008 +0200 (2008-05-15) |
parents | |
children | cee7a7cd19eb |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xarchive/stuff/slitaz-wrap.sh Thu May 15 21:25:18 2008 +0200 1.3 @@ -0,0 +1,529 @@ 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 +# 1.9 +# This program is free software; you can redistribute it and/or modify 1.10 +# it under the terms of the GNU General Public License as published by 1.11 +# the Free Software Foundation; either version 2 of the License, or 1.12 +# (at your option) any later version. 1.13 +# 1.14 +# This program is distributed in the hope that it will be useful, 1.15 +# but WITHOUT ANY WARRANTY; without even the implied warranty of 1.16 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1.17 +# GNU General Public License for more details. 1.18 +# 1.19 +# You should have received a copy of the GNU General Public License 1.20 +# along with this program; if not, write to the Free Software 1.21 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 1.22 + 1.23 +# set up exit status variables 1.24 +E_UNSUPPORTED=65 1.25 + 1.26 +# Supported file extentions for tar 1.27 +TAR_EXTS="tar" 1.28 +GZIP_EXTS="tar.gz tgz" 1.29 +LZMA_EXTS="tar.lz tar.lzma tlz" 1.30 +BZIP2_EXTS="tar.bz tbz tar.bz2 tbz2" 1.31 +COMPRESS_EXTS="tar.z tar.Z" 1.32 +CPIO_EXTS="cpio" 1.33 +CPIOGZ_EXTS="cpio.gz" 1.34 +ZIP_EXTS="zip cbz jar" 1.35 +RPM_EXTS="rpm" 1.36 +DEB_EXTS="deb" 1.37 +TAZPKG_EXTS="tazpkg" 1.38 + 1.39 +# Setup awk program 1.40 +AWK_PROGS="mawk gawk awk" 1.41 +AWK_PROG="" 1.42 +for awkprog in $AWK_PROGS; do 1.43 + if [ "$(which $awkprog)" ]; then 1.44 + AWK_PROG="$awkprog" 1.45 + break 1.46 + fi 1.47 +done 1.48 + 1.49 +# setup variables opt and archive. 1.50 +# the shifting will leave the files passed as 1.51 +# all the remaining args "$@" 1.52 +opt="$1" 1.53 +test -z $1 || shift 1 1.54 +archive="$1" 1.55 +test -z $1 || shift 1 1.56 + 1.57 +# set up compression variables for our compression functions. 1.58 +# translate archive name to lower case for pattern matching. 1.59 +# use compressor -c option to output to stdout and direct it where we want 1.60 +lc_archive="$(echo $archive|tr [:upper:] [:lower:])" 1.61 +DECOMPRESS="cat" 1.62 +COMPRESS="cat" 1.63 +COMPRESS2="" 1.64 +TAR_COMPRESS_OPT="" 1.65 +for ext in $GZIP_EXTS $CPIOGZ_EXTS; do 1.66 + if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.67 + DECOMPRESS="gzip -dc" 1.68 + COMPRESS="gzip -c" 1.69 + TAR_COMPRESS_OPT="z" 1.70 + fi 1.71 +done 1.72 +for ext in $BZIP2_EXTS; do 1.73 + if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.74 + DECOMPRESS="bzip2 -dc" 1.75 + COMPRESS="bzip2 -c" 1.76 + TAR_COMPRESS_OPT="j" 1.77 + fi 1.78 +done 1.79 +for ext in $LZMA_EXTS; do 1.80 + if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.81 + DECOMPRESS="unlzma -c" 1.82 + COMPRESS="lzma e" 1.83 + COMPRESS2=" -so" 1.84 + TAR_COMPRESS_OPT="a" 1.85 + fi 1.86 +done 1.87 +for ext in $COMPRESS_EXTS; do 1.88 + if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.89 + DECOMPRESS="uncompress -dc" 1.90 + COMPRESS="compress -c" 1.91 + TAR_COMPRESS_OPT="--use-compress-prog=compress" 1.92 + fi 1.93 +done 1.94 + 1.95 +# Compression functions 1.96 +decompress_func() 1.97 +{ 1.98 + if [ "$DECOMPRESS" ]; then 1.99 + tmpname="$(mktemp -t tartmp.XXXXXX)" 1.100 + if [ -f "$archive" ]; then 1.101 + $DECOMPRESS "$archive" > "$tmpname" 1.102 + fi 1.103 + # store old name for when we recompress 1.104 + oldarch="$archive" 1.105 + # change working file to decompressed tmp 1.106 + archive="$tmpname" 1.107 + fi 1.108 +} 1.109 + 1.110 +compress_func() 1.111 +{ 1.112 + if [ "$COMPRESS" ] && [ "$oldarch" ]; then 1.113 + [ -f "$oldarch" ] && rm "$oldarch" 1.114 + if $COMPRESS "$archive" $COMPRESS2 > "$oldarch"; then 1.115 + rm "$archive" 1.116 + fi 1.117 + fi 1.118 +} 1.119 + 1.120 +not_busybox() 1.121 +{ 1.122 + case "$(readlink $(which $1))" in 1.123 + *busybox*) return 1;; 1.124 + esac 1.125 + return 0 1.126 +} 1.127 + 1.128 +# the option switches 1.129 +case "$opt" in 1.130 + -i) # info: output supported extentions for progs that exist 1.131 + for ext in $TAR_EXTS $GZIP_EXTS $BZIP2_EXTS $COMPRESS_EXTS $LZMA_EXTS \ 1.132 + $CPIO_EXTS $CPIOGZ_EXTS $ZIP_EXTS $DEB_EXTS $RPM_EXTS \ 1.133 + $TAZPKG_EXTS ; do 1.134 + printf "%s;" $ext 1.135 + if [ "$ext" = "zip" -a ! "$(which zip)" ]; then 1.136 + echo warning: zip not found, extract only >/dev/stderr 1.137 + fi 1.138 + if [ "$ext" = "tar" ] && ! not_busybox tar; then 1.139 + echo warning: gnu/tar not found, extract only >/dev/stderr 1.140 + fi 1.141 + done 1.142 + printf "\n" 1.143 + exit 1.144 + ;; 1.145 + 1.146 + -o) # open: mangle output of tar cmd for xarchive 1.147 + for ext in $TAR_EXTS $GZIP_EXTS $BZIP2_EXTS $COMPRESS_EXTS $LZMA_EXTS; do 1.148 + # format of tar output: 1.149 +# lrwxrwxrwx USR/GRP 0 2005-05-12 00:32:03 file -> /path/to/link 1.150 +# -rw-r--r-- USR/GRP 6622 2005-04-22 12:29:14 file 1.151 +# 1 2 3 4 5 6 1.152 + if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.153 + tar -tv${TAR_COMPRESS_OPT}f "$archive" | $AWK_PROG ' 1.154 + { 1.155 + attr=$1 1.156 + split($2,ids,"/") #split up the 2nd field to get uid/gid 1.157 + uid=ids[1] 1.158 + gid=ids[2] 1.159 + size=$3 1.160 + date=$4 1.161 + time=$5 1.162 + 1.163 + #this method works with filenames that start with a space (evil!) 1.164 + #split line a time and a space 1.165 + split($0,linesplit, $5 " ") 1.166 + #then split the second item (name&link) at the space arrow space 1.167 + split(linesplit[2], nlsplit, " -> ") 1.168 + 1.169 + name=nlsplit[1] 1.170 + link=nlsplit[2] 1.171 + 1.172 + if (! link) {link="-"} #if there was no link set it to a dash 1.173 + 1.174 + printf "%s;%s;%s;%s;%s;%s;%s;%s\n",name,size,attr,uid,gid,date,time,link 1.175 + }' 1.176 + exit 1.177 + fi 1.178 + done 1.179 + 1.180 + for ext in $CPIO_EXTS $CPIOGZ_EXTS; do 1.181 + # format of cpio output: 1.182 +# lrwxrwxrwx USR/GRP 0 2005-05-12 00:32:03 file -> /path/to/link 1.183 +# -rw-r--r-- USR/GRP 6622 2005-04-22 12:29:14 file 1.184 +# 1 2 3 4 5 6 1.185 + if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.186 + $DECOMPRESS "$archive" | cpio -tv | $AWK_PROG ' 1.187 + { 1.188 + attr=$1 1.189 + split($2,ids,"/") #split up the 2nd field to get uid/gid 1.190 + uid=ids[1] 1.191 + gid=ids[2] 1.192 + size=$3 1.193 + date=$4 1.194 + time=$5 1.195 + 1.196 + #this method works with filenames that start with a space (evil!) 1.197 + #split line a time and a space 1.198 + split($0,linesplit, $5 " ") 1.199 + #then split the second item (name&link) at the space arrow space 1.200 + split(linesplit[2], nlsplit, " -> ") 1.201 + 1.202 + name=nlsplit[1] 1.203 + link=nlsplit[2] 1.204 + 1.205 + if (! link) {link="-"} #if there was no link set it to a dash 1.206 + 1.207 + if (name != "" && uid != "blocks") printf "%s;%s;%s;%s;%s;%s;%s;%s\n",name,size,attr,uid,gid,date,time,link 1.208 + }' 1.209 + exit 1.210 + fi 1.211 + done 1.212 + 1.213 + for ext in $ZIP_EXTS; do 1.214 + if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.215 + if which zipinfo; then 1.216 + # format of zipinfo -T -s-h- output: 1.217 + # -rw-r--r-- 2.3 unx 11512 tx defN YYYYMMDD.HHMMSS file 1.218 + # 1 2 3 4 5 6 7 8 1.219 + zipinfo -T -s-h-t "$archive" | $AWK_PROG -v uuid=$(id -u -n) ' 1.220 + { 1.221 + attr=$1; size=$4 1.222 + 1.223 + year=substr($7,1,4) 1.224 + month=substr($7,5,2) 1.225 + day=substr($7,7,2) 1.226 + date=year "-" month "-" day 1.227 + 1.228 + hours=substr($7,10,2) 1.229 + mins=substr($7,12,2) 1.230 + secs=substr($7,14,2) 1.231 + time=hours ":" mins ":" secs 1.232 + 1.233 + uid=uuid; gid=uuid; link="-" 1.234 + #split line at the time and a space, second item is our name 1.235 + split($0, linesplit, ($7 " ")) 1.236 + name=linesplit[2] 1.237 + printf "%s;%s;%s;%s;%s;%s;%s;%s\n",name,size,attr,uid,gid,date,time,link 1.238 + }' 1.239 + exit 1.240 + else 1.241 + # format of unzip -l output: 1.242 + # 6622 2005-04-22 12:29:14 file 1.243 + # 1 2 3 4 1.244 + unzip -l "$archive" | $AWK_PROG -v uuid=$(id -u -n) ' 1.245 + BEGIN { n = 0} 1.246 + { 1.247 + n=n+1 1.248 + attr="" 1.249 + uid=uuid; gid=uuid 1.250 + size=$1 1.251 + date=$2 1.252 + time=$3 1.253 + 1.254 + #this method works with filenames that start with a space (evil!) 1.255 + #split line a time and a space 1.256 + split($0,linesplit, $3 " ") 1.257 + #then split the second item (name&link) at the space arrow space 1.258 + split(linesplit[2], nlsplit, " -> ") 1.259 + 1.260 + name=nlsplit[1] 1.261 + link=nlsplit[2] 1.262 + 1.263 + if (! link) {link="-"} #if there was no link set it to a dash 1.264 + 1.265 + if (name != "" && n > 3) printf "%s;%s;%s;%s;%s;%s;%s;%s\n",name,size,attr,uid,gid,date,time,link 1.266 + }' 1.267 + exit 1.268 + fi 1.269 + fi 1.270 + done 1.271 + 1.272 + for ext in $RPM_EXTS; do 1.273 + if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.274 + rpm2cpio "$archive" | cpio -tv | $AWK_PROG ' 1.275 + { 1.276 + attr=$1 1.277 + split($2,ids,"/") #split up the 2nd field to get uid/gid 1.278 + uid=ids[1] 1.279 + gid=ids[2] 1.280 + size=$3 1.281 + date=$4 1.282 + time=$5 1.283 + 1.284 + #this method works with filenames that start with a space (evil!) 1.285 + #split line a time and a space 1.286 + split($0,linesplit, $5 " ") 1.287 + #then split the second item (name&link) at the space arrow space 1.288 + split(linesplit[2], nlsplit, " -> ") 1.289 + 1.290 + name=substr(nlsplit[1],2) 1.291 + link=nlsplit[2] 1.292 + 1.293 + if (! link) {link="-"} #if there was no link set it to a dash 1.294 + 1.295 + if (name != "" && uid != "blocks") printf "%s;%s;%s;%s;%s;%s;%s;%s\n",name,size,attr,uid,gid,date,time,link 1.296 + }' 1.297 + exit 1.298 + fi 1.299 + done 1.300 + 1.301 + for ext in $DEB_EXTS; do 1.302 + if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.303 + dpkg-deb -c "$archive" | $AWK_PROG ' 1.304 + { 1.305 + attr=$1 1.306 + split($2,ids,"/") #split up the 2nd field to get uid/gid 1.307 + uid=ids[1] 1.308 + gid=ids[2] 1.309 + size=$3 1.310 + date=$4 1.311 + time=$5 1.312 + 1.313 + #this method works with filenames that start with a space (evil!) 1.314 + #split line a time and a space 1.315 + split($0,linesplit, $5 " ") 1.316 + #then split the second item (name&link) at the space arrow space 1.317 + split(linesplit[2], nlsplit, " -> ") 1.318 + 1.319 + name=substr(nlsplit[1],2) 1.320 + link=nlsplit[2] 1.321 + 1.322 + if (! link) {link="-"} #if there was no link set it to a dash 1.323 + 1.324 + printf "%s;%s;%s;%s;%s;%s;%s;%s\n",name,size,attr,uid,gid,date,time,link 1.325 + }' 1.326 + exit 1.327 + fi 1.328 + done 1.329 + 1.330 + for ext in $TAZPKG_EXTS; do 1.331 + # format of cpio output: 1.332 +# lrwxrwxrwx USR/GRP 0 2005-05-12 00:32:03 file -> /path/to/link 1.333 +# -rw-r--r-- USR/GRP 6622 2005-04-22 12:29:14 file 1.334 +# 1 2 3 4 5 6 1.335 + if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.336 + tmpcpio="$(mktemp -d -t cpiotmp.XXXXXX)" 1.337 + here="$(pwd)" 1.338 + cd $tmpcpio 1.339 + cpio -i fs.cpio.gz > /dev/null < "$archive" 1.340 + zcat fs.cpio.gz | cpio -tv | $AWK_PROG ' 1.341 + { 1.342 + attr=$1 1.343 + split($2,ids,"/") #split up the 2nd field to get uid/gid 1.344 + uid=ids[1] 1.345 + gid=ids[2] 1.346 + size=$3 1.347 + date=$4 1.348 + time=$5 1.349 + 1.350 + #this method works with filenames that start with a space (evil!) 1.351 + #split line a time and a space 1.352 + split($0,linesplit, $5 " ") 1.353 + #then split the second item (name&link) at the space arrow space 1.354 + split(linesplit[2], nlsplit, " -> ") 1.355 + 1.356 + name=substr(nlsplit[1],3) 1.357 + link=nlsplit[2] 1.358 + 1.359 + if (! link) {link="-"} #if there was no link set it to a dash 1.360 + 1.361 + if (name != "" && uid != "blocks") printf "%s;%s;%s;%s;%s;%s;%s;%s\n",name,size,attr,uid,gid,date,time,link 1.362 + }' 1.363 + cd $here 1.364 + rm -rf $tmpcpio 1.365 + exit 1.366 + fi 1.367 + done 1.368 + exit $E_UNSUPPORTED 1.369 + ;; 1.370 + 1.371 + -a) # add to archive passed files 1.372 + not_busybox tar && \ 1.373 + for ext in $TAR_EXTS $GZIP_EXTS $BZIP2_EXTS $COMPRESS_EXTS $LZMA_EXTS; do 1.374 + if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.375 + # we only want to add the file's basename, not 1.376 + # the full path so... 1.377 + decompress_func 1.378 + while [ "$1" ]; do 1.379 + cd "$(dirname "$1")" 1.380 + tar -rf "$archive" "$(basename "$1")" 1.381 + wrapper_status=$? 1.382 + shift 1 1.383 + done 1.384 + compress_func 1.385 + exit $wrapper_status 1.386 + fi 1.387 + done 1.388 + which zip >/dev/null && for ext in $ZIP_EXTS; do 1.389 + if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.390 + # we only want to add the file's basename, not 1.391 + # the full path so... 1.392 + while [ "$1" ]; do 1.393 + cd "$(dirname "$1")" 1.394 + zip -g -r "$archive" "$(basename "$1")" 1.395 + wrapper_status=$? 1.396 + shift 1 1.397 + done 1.398 + exit $wrapper_status 1.399 + fi 1.400 + done 1.401 + exit $E_UNSUPPORTED 1.402 + ;; 1.403 + 1.404 + -n) # new: create new archive with passed files 1.405 + not_busybox tar && \ 1.406 + for ext in $TAR_EXTS $GZIP_EXTS $BZIP2_EXTS $COMPRESS_EXTS $LZMA_EXTS; do 1.407 + if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.408 + # create will only be passed the first file, the 1.409 + # rest will be "added" to the new archive 1.410 + decompress_func 1.411 + cd "$(dirname "$1")" 1.412 + tar -cf "$archive" "$(basename "$1")" 1.413 + wrapper_status=$? 1.414 + compress_func 1.415 + exit $wrapper_status 1.416 + fi 1.417 + done 1.418 + which zip >/dev/null && for ext in $ZIP_EXTS; do 1.419 + if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.420 + # create will only be passed the first file, the 1.421 + # rest will be "added" to the new archive 1.422 + cd "$(dirname "$1")" 1.423 + zip -r "$archive" "$(basename "$1")" 1.424 + fi 1.425 + done 1.426 + exit $E_UNSUPPORTED 1.427 + ;; 1.428 + 1.429 + -r) # remove: from archive passed files 1.430 + not_busybox tar && \ 1.431 + for ext in $TAR_EXTS $GZIP_EXTS $BZIP2_EXTS $COMPRESS_EXTS $LZMA_EXTS; do 1.432 + if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.433 + decompress_func 1.434 + tar --delete -f "$archive" "$@" 1.435 + wrapper_status=$? 1.436 + compress_func 1.437 + exit $wrapper_status 1.438 + fi 1.439 + done 1.440 + which zip >/dev/null && for ext in $ZIP_EXTS; do 1.441 + if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.442 + zip -d "$archive" "$@" 1.443 + fi 1.444 + done 1.445 + exit $E_UNSUPPORTED 1.446 + ;; 1.447 + 1.448 + -e) # extract: from archive passed files 1.449 + for ext in $TAR_EXTS $GZIP_EXTS $BZIP2_EXTS $COMPRESS_EXTS $LZMA_EXTS; do 1.450 + if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.451 + # xarchive will put is the right extract dir 1.452 + # so we just have to extract. 1.453 + tar -x${TAR_COMPRESS_OPT}f "$archive" "$@" 1.454 + exit $? 1.455 + fi 1.456 + done 1.457 + for ext in $CPIO_EXTS $CPIOGZ_EXTS; do 1.458 + if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.459 + if [ -n "$1" ]; then 1.460 + while [ "$1" ]; do 1.461 + $DECOMPRESS "$archive" | cpio -idv "$1" 1.462 + shift 1 1.463 + done 1.464 + else 1.465 + $DECOMPRESS "$archive" | cpio -idv 1.466 + fi 1.467 + exit $? 1.468 + fi 1.469 + done 1.470 + for ext in $ZIP_EXTS; do 1.471 + if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.472 + # xarchive will put is the right extract dir 1.473 + # so we just have to extract. 1.474 + unzip -n "$archive" "$@" 1.475 + exit $? 1.476 + fi 1.477 + done 1.478 + for ext in $RPM_EXTS; do 1.479 + if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.480 + if [ -n "$1" ]; then 1.481 + while [ "$1" ]; do 1.482 + rpm2cpio "$archive" | cpio -idv "$1" 1.483 + shift 1 1.484 + done 1.485 + else 1.486 + rpm2cpio "$archive" | cpio -idv 1.487 + fi 1.488 + exit $? 1.489 + fi 1.490 + done 1.491 + 1.492 + for ext in $DEB_EXTS; do 1.493 + if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.494 + dpkg-deb -X "$archive" "$@" 1.495 + exit $? 1.496 + fi 1.497 + done 1.498 + for ext in $TAZPKG_EXTS; do 1.499 + if [ $(expr "$lc_archive" : ".*\."$ext"$") -gt 0 ]; then 1.500 + tmpcpio="$(mktemp -d -t cpiotmp.XXXXXX)" 1.501 + here="$(pwd)" 1.502 + cd $tmpcpio 1.503 + cpio -i < "$archive" > /dev/null 1.504 + zcat fs.cpio.gz | cpio -id > /dev/null 1.505 + status=$? 1.506 + if [ -n "$1" ]; then 1.507 + while [ "$1" ]; do 1.508 + dir=$(dirname "$here/$1") 1.509 + mkdir -p "$dir" 2> /dev/null 1.510 + mv "fs/$1" "$dir" 2> /dev/null 1.511 + done 1.512 + else 1.513 + mv fs/* fs/.* $here 2> /dev/null 1.514 + fi 1.515 + cd $here 1.516 + rm -rf $tmpcpio 1.517 + exit $status 1.518 + fi 1.519 + done 1.520 + exit $E_UNSUPPORTED 1.521 + ;; 1.522 + 1.523 + *) echo "error, option $opt not supported" 1.524 + echo "use one of these:" 1.525 + echo "-i #info" 1.526 + echo "-o archive #open" 1.527 + echo "-a archive files #add" 1.528 + echo "-n archive file #new" 1.529 + echo "-r archive files #remove" 1.530 + echo "-e archive files #extract" 1.531 + exit 1.532 +esac