OSDN Git Service

debExtract.sh master
authorfakesh <fakesh@users.sourceforge.jp>
Mon, 9 Dec 2013 14:48:17 +0000 (23:48 +0900)
committerfakesh <fakesh@users.sourceforge.jp>
Mon, 9 Dec 2013 14:48:17 +0000 (23:48 +0900)
root/bin/ar.sh
root/bin/debExtract.sh [new symlink]
root/bin/screenShot-jpeg.sh

index 8eb86bf..323fe64 100755 (executable)
@@ -1,21 +1,34 @@
 #!/bin/busybox sh
 
-showUsage () {
-  echo "Usage: ${0##*/} t file.deb                 # listing"
-  echo "       ${0##*/} x file.deb [filename ...]  # extract"
-  exit 1
-}
-
-if [ $# -le 1 ] ; then
-  showUsage
-fi 1>&2
+case "${0##*/}" in
+deb*) cmd=X ;;
+*) cmd="$1"; shift ;;
+esac
 
-cmd="$1"; shift
 case "$cmd" in
-[tlx]) ;;
+[txXT]) ;;
 *) showUsage ;;
 esac 1>&2
 
+showUsage () {
+  case "${0##*/}" in
+  deb*) cat <<- EOUSAGE1
+       Usage: ${0##*/} file.deb [tar_options ...]  # deb extract
+              ${0##*/} file.deb --list             # deb listing
+       EOUSAGE1
+  ;;
+  *) cat <<- EOUSAGE2
+       Usage: ${0##*/} t file.a                     # ar listing
+              ${0##*/} x file.a [filename ...]      # ar extract
+              ${0##*/} T file.deb [tar_options ...] # deb listing
+              ${0##*/} X file.deb [tar_options ...] # deb extract
+       EOUSAGE2
+  ;;
+  esac 1>&2
+  exit 1
+}
+
+[ $# -eq 0 ] && showUsage
 deb="$1"; shift
 
 # Usage: binAccess offset size
@@ -44,7 +57,7 @@ binAccess () {
 
 magicAR="$(printf '!<arch>\n' | od -v -A n -t x)"
 if [ "$magicAR" != "$(binAccess 0 8 | od -v -A n -t x)" ] ; then
-  echo "non ar archive: $deb" 1>&2
+  echo "not .a nor .deb archive: $deb" 1>&2
   exit 1
 fi
 
@@ -62,7 +75,7 @@ while [ $p -lt $sz ] ; do
     exit 1
   fi
   case "$cmd" in
-  [lt])
+  t)
     p=$((p+60+fsize))
     echo "$fname"
   ;;
@@ -75,6 +88,25 @@ while [ $p -lt $sz ] ; do
     fi
     p=$((p+fsize))
   ;;
+  [XT])
+    p=$((p+60))
+    case "$fname" in
+    data.tar) tarcmd=f ;;
+    data.tar.gz | data.tgz) tarcmd=fz ;;
+    data.tar.bz2) tarcmd=fj ;;
+    data.tar.xz | data.tar.lzma) tarcmd=fa ;;
+    *) p=$((p+fsize)) ; continue ;;
+    esac
+    if [ "x$1" = x--list ] ; then
+      shift
+      tarcmd=t$tarcmd
+    elif [ $cmd = T ] ; then
+      tarcmd=t$tarcmd
+    else
+      tarcmd=x$tarcmd
+    fi
+    binAccess $p $fsize | tar $tarcmd - "$@"
+    exit
   esac
 done
 
diff --git a/root/bin/debExtract.sh b/root/bin/debExtract.sh
new file mode 120000 (symlink)
index 0000000..b39f665
--- /dev/null
@@ -0,0 +1 @@
+ar.sh
\ No newline at end of file
index 1276132..3f0cfc4 100755 (executable)
@@ -2,7 +2,8 @@
 #
 # exit 1 is not fatal
 export LANG=C LC_ALL=C GZIP=-9
-df /tmp | awk '$NF=="/tmp"&&$4<4096{exit 1;}' || exit 1
+awk=`which awk`
+df /tmp | $awk '$NF=="/tmp"&&$4<4096{exit 1;}' || exit 1
 pickel=/usr/local/Kobo/pickel
 if [ -x $pickel ] ; then
   pictd=/mnt/onboard/screenShots
@@ -101,7 +102,7 @@ case "$opts" in
        Usage: ${0##*/} [pathto/pict] [10-999] [cmd]$cjpegopt
          pathto/pict : path to output file. (${pictw%.wait})
          10-999 : shutter timer sec. ($timer)
-         cmd : help , conv , wait, showfb , fb:_params_ , silent,
+         cmd : help , conv , wait , fb:_params_ , showfb , silent
                fmt:_output_format_ (${fmt##*[!jpegm1234LGraw]}).
        EOHELP
   exit
@@ -131,7 +132,7 @@ cd /
 # rP=red_pos;gP=green_pos;rP=blue_pos;
 # landscape orientation
 w=''; rB=''
-eval $(fbset | awk '
+eval $(fbset | $awk '
   $1=="geometry"{printf "w=%d; h=%d; bpp=%d;", $2, $3, $6;}
   $1=="rgba"{
     gsub(/[\/,]/," ");
@@ -147,7 +148,7 @@ case "$opts" in
 esac
 case "$opts" in
 */showfb*)
-  echo "w=$w;h=$h;rB=$rB;rP=$rP;gB=$gB;gP=$gP;bB=$bB;bP=$bP;"
+  echo "w=$w;h=$h;rB=$rB;rP=$rP;gB=$gB;gP=$gP;bB=$bB;bP=$bP;bpp=$bpp"
   rm -f "$pictw"
   exit 0
 esac
@@ -205,7 +206,7 @@ awkBEGIN="BEGIN{
   fmtP2i=\"%0${xf}x %d\n\";
 }"
 # some "sh"s do not recog $((2**dp))
-maxv=$(printf \\n | awk "$awkBEGIN{printf mx}")
+maxv=$(printf \\n | $awk "$awkBEGIN{printf mx}")
 
 #### 1st filters
 
@@ -213,7 +214,7 @@ maxv=$(printf \\n | awk "$awkBEGIN{printf mx}")
 ## suffix 'i' means index for "sort"
 toP3L () {
   [ $hdpos = 1 ] && printf 'P3\n%d %d\n%d\n' $w $h $maxv
-  awk "$awkBEGIN"'{
+  $awk "$awkBEGIN"'{
     for (i=1; i<=NF; i++) {
       r=(int($i/rQ)%rD)*rR;
       g=(int($i/gQ)%gD)*gR;
@@ -226,7 +227,7 @@ toP3L () {
 
 toP3i () {
   [ $hdpos = 1 ] && printf 'idx P3 %d %d %d\n' $h $w $maxv
-  awk "$awkBEGIN"'{
+  $awk "$awkBEGIN"'{
     for (i=1; i<=NF; i++) {
       r=(int($i/rQ)%rD)*rR;
       g=(int($i/gQ)%gD)*gR;
@@ -240,7 +241,7 @@ toP3i () {
 
 toP2L () {
   [ $hdpos = 1 ] && printf 'P2\n%d %d\n%s\n' $w $h $maxv
-  awk "$awkBEGIN"' {
+  $awk "$awkBEGIN"' {
     for (i=1; i<=NF; i++) {
       g=(int($i/rQ)%rD)*rG+(int($i/gQ)%gD)*gG+(int($i/bQ)%bD)*bG;
       print (g<mx)?int(g):mx;
@@ -251,7 +252,7 @@ toP2L () {
 
 toP2i () {
   [ $hdpos = 1 ] && printf 'idx P2 %d %d %d\n' $h $w $maxv
-  awk "$awkBEGIN"'{
+  $awk "$awkBEGIN"'{
     for (i=1; i<=NF; i++) {
       g=(int($i/rQ)%rD)*rG+(int($i/gQ)%gD)*gG+(int($i/bQ)%bD)*bG;
       printf fmtP2i, h*(n%w)+h1-int(n/w), (g<mx)?g:mx;
@@ -266,7 +267,7 @@ trset="$(printf '\\%o\\377 \\%o\\0' $((maxv+1)) $maxv)"
 # awk : printf "%c", x+0; <==> printf "%c", int(x); # x+0 : str to real
 toP6L () {
   [ $hdpos = 1 ] && printf 'P6\n%d %d\n%d\n' $w $h $maxv
-  awk "$awkBEGIN"'{
+  $awk "$awkBEGIN"'{
     for (i=1; i<=NF; i++) {
       r=(int($i/rQ)%rD)*rR;
       g=(int($i/gQ)%gD)*gR;
@@ -279,7 +280,7 @@ toP6L () {
 
 toP5L () {
   [ $hdpos = 1 ] && printf 'P5\n%d %d\n%d\n' $w $h $maxv
-  awk "$awkBEGIN"' {
+  $awk "$awkBEGIN"' {
     for (i=1; i<=NF; i++) {
       g=(int($i/rQ)%rD)*rG+(int($i/gQ)%gD)*gG+(int($i/bQ)%bD)*bG;
       printf "%c", (g<1)?255:g;
@@ -290,7 +291,7 @@ toP5L () {
 
 # raw gray, opp : octets par pix, {printf "%c", g+0;} eqv. {printf "%c", g%256;}
 toRAWG () {
-  awk -v rv=$hdpos "$awkBEGIN"' {
+  $awk -v rv=$hdpos "$awkBEGIN"' {
     for (i=1; i<=NF; i++) {
       g=(int($i/rQ)%rD)*rG+(int($i/gQ)%gD)*gG+(int($i/bQ)%bD)*bG;
       if (rv) {g=mx-int(g);} else {g=int(g);}
@@ -317,7 +318,7 @@ sed_cjpeg () {
 P3i2P6gz () {
   {
     [ $hdpos = 2 ] && printf 'P6\n%d %d\n%s\n' $h $w $maxv
-    awk '{printf "%c%c%c", ($2<1)?255:$2, ($3<1)?255:$3, ($4<1)?255:$4;}' |
+    $awk '{printf "%c%c%c", ($2<1)?255:$2, ($3<1)?255:$3, ($4<1)?255:$4;}' |
       tr \\377 \\0
   } | gzip
 }
@@ -325,7 +326,7 @@ P3i2P6gz () {
 P2i2P5gz () {
   {
     [ $hdpos = 2 ] && printf 'P5\n%d %d\n%s\n' $h $w $maxv
-    awk '{printf "%c", ($2<1)?255:$2;}' | tr \\377 \\0
+    $awk '{printf "%c", ($2<1)?255:$2;}' | tr \\377 \\0
   } | gzip
 }