[csw-devel] SF.net SVN: gar:[13059] csw/mgar/gar/v2/lib/sh/libcheckpkg.sh

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Sun Jan 23 09:00:37 CET 2011


Revision: 13059
          http://gar.svn.sourceforge.net/gar/?rev=13059&view=rev
Author:   wahwah
Date:     2011-01-23 08:00:37 +0000 (Sun, 23 Jan 2011)

Log Message:
-----------
checkpkg: Better pkgtrans

Doesn't use trial and error to unpack srv4 files.  It understands how to
extract the right values from the file.

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/sh/libcheckpkg.sh

Modified: csw/mgar/gar/v2/lib/sh/libcheckpkg.sh
===================================================================
--- csw/mgar/gar/v2/lib/sh/libcheckpkg.sh	2011-01-23 08:00:09 UTC (rev 13058)
+++ csw/mgar/gar/v2/lib/sh/libcheckpkg.sh	2011-01-23 08:00:37 UTC (rev 13059)
@@ -2,45 +2,37 @@
 #
 # $Id$
 
-# pkgtrans leaves a directory in /var/tmp/aaXXXXXXX even after clean quit.
-# Emulating pkgtrans behaviour, for "pkgtrans src destdir pkgname".  Except
-# that the pkgname arg is ignored, and only the first pkg is processed.
+# A srv4 .pkg file is a header + 2 cpio archives.  The header is 1 (but maybe
+# more?) 512 byte block.  The cpio archives use a 512b block size too.  We find
+# the end of the first cpio archive (marked by 'TRAILER!!!' inside the last
+# block) and then determine how many bytes into the file this is, divide by
+# block size to find the number of blocks until the trailer and add another
+# block to get the number of blocks in the file to skip so that we're at the
+# second cpio archive.
+#
+# These two options need to be assumed to be set:
+# set -e
+# set -u
 
-get_header_blocks() {
-  dd if="$1" skip=1 \
-    | cpio -i -t 2>&1  >/dev/null \
-    | nawk '{print $1; exit;}'
-}
-
-custom_pkgtrans() {
-  local hdrblks
-  if [[ ! -d "$2" ]] ; then
-    echo ERROR: "$2" is not a directory >/dev/fd/2
-    return 1
+function custom_pkgtrans {
+  local outd
+  local skipblks
+  if ! [[ -d "$2" ]]; then
+    echo "'$2' is not a directory"
+    exit 1
   fi
-  hdrblks=$(get_header_blocks "$1")
+  outd=$2/$3
+  skipblks=$(expr $(ggrep -a -b -o -m 1 'TRAILER!!!' "$1" \
+    | awk -F: '{print $1}') / 512 + 1)
+  mkdir -p "${outd}"
 
-  echo "initial hdrblks=$hdrblks"
+  (
+    dd if="$1" skip="${skipblks}" 2>/dev/null \
+      | (cd "${outd}" ; cpio -ivdm || true)
+  ) >/dev/null 2>&1
 
-  hdrblks=$(( $hdrblks + 1 ))
-  mkdir $2/$3
-
-  local counter=0
-  while :; do
-    echo "Attempting ${hdrblks} offset"
-    # cpio sometimes returns 1, and we don't want to bail out when it happens.
-    dd if="$1" skip="$hdrblks" | (cd $2/$3 ; cpio -ivdm) || true
-    if [[ -d "$2/$3/install" ]]; then
-      echo "Unpack successful."
-      break
-    fi
-    hdrblks=$(( $hdrblks + 1 ))
-    counter=$(( $counter + 1 ))
-    # To prevent us from going on forever.
-    if [[ "${counter}" -gt 100 ]]; then
-      echo "Unpack keeps on being unsuccessful. Bailing out."
-      return 1
-    fi
-    echo "Unpack unsuccessful, trying offset ${hdrblks}"
-  done
+  if [ ! -d "${outd}/install" ]; then
+    echo "Failed to extract '$1' to ${outd}"
+    exit 1
+  fi
 }


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.


More information about the devel mailing list