[51709] contrib/mpab

febeling at macports.org febeling at macports.org
Mon Jun 1 01:17:58 PDT 2009


Revision: 51709
          http://trac.macports.org/changeset/51709
Author:   febeling at macports.org
Date:     2009-06-01 01:17:57 -0700 (Mon, 01 Jun 2009)
Log Message:
-----------
Merging changes from dev branch 

* branch: http://svn.macports.org/repository/macports/users/febeling/mpab
* see ChangeLog for details

Modified Paths:
--------------
    contrib/mpab/ReadMe.txt
    contrib/mpab/chroot-scripts/buildports
    contrib/mpab/mpab
    contrib/mpab/mpab-functions
    contrib/mpab/mpsync.sh

Added Paths:
-----------
    contrib/mpab/ChangeLog
    contrib/mpab/chroot-scripts/chrootshell

Added: contrib/mpab/ChangeLog
===================================================================
--- contrib/mpab/ChangeLog	                        (rev 0)
+++ contrib/mpab/ChangeLog	2009-06-01 08:17:57 UTC (rev 51709)
@@ -0,0 +1,32 @@
+2009-06-01  Florian Ebeling  <febeling at macports.org>
+
+	* mpab-functions (uninstallPorts): operate on `port list active'
+	instead of `port installed'
+
+	* mpab-functions: factor out function `chroot_exec' 
+
+	* mpab-functions: add /Developer/Applications/Xcode.app to
+	pathsToCopy list
+	
+2009-04-13  Florian Ebeling  <febeling at macports.org>
+
+	* chroot-scripts/buildports (uninstallPorts): Fix: use -x on
+	deactivate to see real success of operation.
+
+2009-04-09  Florian Ebeling  <febeling at macports.org>
+
+	* mpab-functions (chrootShell): add new function for interactive
+	shell inside of chroot
+
+2009-04-07  Florian Ebeling  <febeling at macports.org>
+
+	* mpab, mpab-functions (buildmp, rebuildmp): Accept a path to a
+	release tarball of MP to install into chroot.
+
+	* mpab: Add support for a data directory distinct from current
+	working directory.
+
+	* mpab-functions: Use local variables in functions.
+
+	* mpab: by default look for a SVN working copy named 'mpexport',
+	then fallback to 'macports_dist.tar.bz2'.

Modified: contrib/mpab/ReadMe.txt
===================================================================
--- contrib/mpab/ReadMe.txt	2009-06-01 07:57:29 UTC (rev 51708)
+++ contrib/mpab/ReadMe.txt	2009-06-01 08:17:57 UTC (rev 51709)
@@ -14,10 +14,11 @@
 You need to have 10.5, Xcode 3.0, and Apple's X11 (other versions of Xcode
 and X11 may work, but these are the ones tested so far).
 
-For the MacPorts which will live in the chroot, you'll need (in the same
-directory as the mpab script) a tarball named macports_dist.tar.bz2.  To
-create this straight from the MacPorts svn server (assuming current
-working directory is the same as the mpab script):
+For the MacPorts which will live in the chroot, you'll need (in the
+same directory you run the command from) a tarball named
+macports_dist.tar.bz2.  To create this straight from the MacPorts svn
+server (assuming current working directory is the same as the mpab
+script):
 
    svn export http://svn.macports.org/repository/macports/trunk mpexport
    cd mpexport
@@ -39,7 +40,7 @@
 ------------
 Once the MPAB tarball is extracted (which you've probably done if you're
 reading this), make sure the above prerequisites are available, then you
-are ready to go
+are ready to go.
 
 
 Running

Modified: contrib/mpab/chroot-scripts/buildports
===================================================================
--- contrib/mpab/chroot-scripts/buildports	2009-06-01 07:57:29 UTC (rev 51708)
+++ contrib/mpab/chroot-scripts/buildports	2009-06-01 08:17:57 UTC (rev 51709)
@@ -32,9 +32,9 @@
 
 function uninstallPorts()
 {
-   installedPorts=`/opt/local/bin/port installed | /usr/bin/tail +2 | /usr/bin/awk '{print $1}'`
+   installedPorts=`/opt/local/bin/port list active | /usr/bin/awk '{print $1}'`
    for uninstallPort in $installedPorts; do
-      portOutput=`/opt/local/bin/port -dvf deactivate $uninstallPort 2>&1`
+      portOutput=`/opt/local/bin/port -xdvf deactivate $uninstallPort 2>&1`
       if [[ $? != 0 ]]; then
          echo $portOutput
          break

Added: contrib/mpab/chroot-scripts/chrootshell
===================================================================
--- contrib/mpab/chroot-scripts/chrootshell	                        (rev 0)
+++ contrib/mpab/chroot-scripts/chrootshell	2009-06-01 08:17:57 UTC (rev 51709)
@@ -0,0 +1,2 @@
+#!/bin/sh
+PS1="[MPAB_CHROOT \w] \$ " sh -i 

Modified: contrib/mpab/mpab
===================================================================
--- contrib/mpab/mpab	2009-06-01 07:57:29 UTC (rev 51708)
+++ contrib/mpab/mpab	2009-06-01 08:17:57 UTC (rev 51709)
@@ -38,8 +38,17 @@
 
 # Name of the file containing all of MacPorts
 MPTARBALL="macports_dist.tar.bz2"
+# Alternatively, the SVN checkout dir of MacPorts
 MP_SVN_WORKDIR="mpexport"
 
+baseDir=$(dirname $0)
+
+dataDir=$(pwd)
+if [[ $MPAB_DATA ]]; then
+   dataDir=$MPAB_DATA
+fi
+chrootPath="${dataDir}/${CHROOTSUBDIR}"
+
 if [[ -n ${MPABDEBUG} ]]; then
    HDIUTILDEBUG="-verbose"
 else
@@ -47,11 +56,6 @@
 fi
 export HDIUTILDEBUG
 
-cd `dirname $0`
-baseDir=`pwd -P`
-chrootPath="${baseDir}/${CHROOTSUBDIR}"
-cd - > /dev/null
-
 . ${baseDir}/mpab-functions
 
 command="buildports"
@@ -60,9 +64,13 @@
    command=$1 && shift
    if [[ ${command} != "help" && ${command} != "mount" &&
          ${command} != "umount" && ${command} != "buildmp" &&
-         ${command} != "rebuildmp" && ${command} != "buildports" ]]; then
+         ${command} != "rebuildmp" && ${command} != "buildports" && 
+         ${command} != "shell" ]]; then
       printUsageAndExit
    fi
+   if [[ ${command} == "buildmp" || ${command} == "rebuildmp" ]]; then
+      installPackage=$1 && shift
+   fi
    if [[ ${command} == "buildports" && -n $1 ]]; then
       portlistFile=$1 && shift
       if [[ ! -e ${portlistFile} ]]; then
@@ -75,35 +83,47 @@
    fi
 fi
 
-checkDependencies ${baseDir} ${MPTARBALL} ${MP_SVN_WORKDIR}
+if [[ ${command} == "umount" ]]; then
+   umountChroot ${chrootPath}
+   exit 0
+fi
+
+if [[ ${command} == "shell" ]]; then
+   chrootShell
+   exit 0
+fi
+
+checkDependencies ${dataDir} ${MPTARBALL} ${MP_SVN_WORKDIR} ${installPackage}
 returnValue=$?
 if [[ ${returnValue} != 0 ]]; then
    exit ${returnValue}
 fi
 
-if [[ ${command} == "umount" ]]; then
-   umountChroot ${chrootPath}
-   exit 0
-fi
-
 if [[ ${command} == "mount" || ${command} == "buildmp" ||
    ${command} == "rebuildmp" || ${command} == "buildports" ]]; then
-   buildImages ${baseDir} ${chrootPath} ${IMGBASENAME}
-   mountChroot ${baseDir} ${chrootPath} ${IMGBASENAME}
+   buildImages ${dataDir} ${chrootPath} ${IMGBASENAME}
+   mountChroot ${dataDir} ${chrootPath} ${IMGBASENAME}
    if [[ $? == 0 &&
          ( ${command} == "buildmp" || ${command} == "rebuildmp" ||
            ${command} == "buildports" ) ]]; then
-      trap "exitFunction ${baseDir} ${chrootPath}" EXIT
+      trap "exitFunction ${dataDir} ${chrootPath}" EXIT
       exitMessage="Stopping..."
       if [[ ${command} == "rebuildmp" ]]; then
          rm -rf ${chrootPath}/opt/mports
          rm -f ${chrootPath}/opt/local/bin/port
       fi
-      if [[ -d ${MP_SVN_WORKDIR} ]]; then
-         buildMacPorts ${baseDir} ${chrootPath} ${MP_SVN_WORKDIR}
+      
+      if [[ -n ${installPackage} ]]; then
+         buildMacPorts ${baseDir} ${dataDir} ${chrootPath} ${installPackage} ||
+            ( echo "Failed to build MacPorts from release archive" && exit 1 )
+      elif [[ -d ${MP_SVN_WORKDIR} ]]; then
+         buildMacPorts ${baseDir} ${dataDir} ${chrootPath} ${MP_SVN_WORKDIR} ||
+            ( echo "Failed to build MacPorts from SVN checkout directory (MP_SVN_WORKDIR)" && exit 1 )
       else
-         buildMacPorts ${baseDir} ${chrootPath} ${MPTARBALL}
+         buildMacPorts ${baseDir} ${dataDir} ${chrootPath} ${MPTARBALL} ||
+            ( echo "Failed to build MacPorts from ${mpExport}" && exit 1 )
       fi
+
       exitMessage=""
       if [[ $? == 0 && ${command} == "buildports" ]]; then
          if [[ -e ${portlistFile} ]]; then

Modified: contrib/mpab/mpab-functions
===================================================================
--- contrib/mpab/mpab-functions	2009-06-01 07:57:29 UTC (rev 51708)
+++ contrib/mpab/mpab-functions	2009-06-01 08:17:57 UTC (rev 51709)
@@ -28,22 +28,26 @@
 #
 
 #------------------------------------------------------------------------
-# Check necessary bits are available
-# $1 - base directory
+# Check necessary bits are available. Either svn export tarball, or svn
+# working directory, or release tarball have to be present.
+# $1 - data directory
 # $2 - MacPorts source tarball
+# $3 - MacPosts svn working copy
+# $4 - MacPorts release tarball
 function checkDependencies()
 {
-   baseDir=$1
-   mpTarball=$2
-   mpSvnWorkdir=$3
+   local dataDir=$1
+   local mpTarball=$2
+   local mpSvnWorkdir=$3
+   local installPackage=$4
 
    if [[ `id -u` != 0 ]]; then
       echo "This must be run as root, please do so"
       return 1
    fi
-   if [[ ! -f ${baseDir}/${mpTarball} && ! -d ${baseDir}/${mpSvnWorkdir} ]]; then
+   if [[ ! -f ${dataDir}/${mpTarball} && ! -d ${dataDir}/${mpSvnWorkdir} && ! -f ${dataDir}/${installPackage} ]]; then
       cat << EOF
-Need to have a MacPorts source tarball ${baseDir}/${mpTarball} or svn working directory ${baseDir}/${mpSvnWorkDir}
+Need to have a MacPorts source tarball ${mpTarball} or svn working directory ${mpSvnWorkDir}
 See the ReadMe.txt file.
 EOF
    return 2
@@ -56,11 +60,12 @@
 function printUsageAndExit()
 {
    cat << EOF
-Usage: $0 [help | mount | umount | buildmp | rebuildmp |
+Usage: $0 [help | mount | umount | shell | buildmp [RELEASE_FILE] | rebuildmp [RELEASE_FILE] |
            buildports [portlist_file]]
    help:        this help
    mount:       just mount the chroot images
    umount:      unmount the chroot images
+   shell:       start an interactive shell in the chroot
    buildmp:     build/install MacPorts inside the chroot
    rebuildmp:   force a rebuild of MacPorts inside the chroot
    buildports:  build ports; if a portlist file is given, use it, otherwise
@@ -79,8 +84,8 @@
 # $2 - chroot path
 function exitFunction()
 {
-   baseDir=$1
-   chrootPath=$2
+   local baseDir=$1
+   local chrootPath=$2
 
    if [[ -n $exitMessage ]]; then
       echo $exitMessage
@@ -101,9 +106,9 @@
 # $3 - base name for the disk images
 function buildImages()
 {
-   baseDir=$1
-   chrootPath=$2
-   imgBaseName=$3
+   local baseDir=$1
+   local chrootPath=$2
+   local imgBaseName=$3
 
    echo "Building MP chroot images, if necessary"
 
@@ -111,7 +116,7 @@
    pathsToCreate="private/etc private/var/folders private/var/log private/var/spool private/var/run private/var/tmp private/var/db/dyld private/tmp"
 
    # Paths to copy to the chroot
-   pathsToCopy="private/etc/bashrc private/etc/group private/etc/hosts private/etc/pam.d private/etc/passwd private/etc/profile private/etc/shells private/var/root bin sbin etc tmp var usr/bin usr/include usr/lib usr/libexec usr/sbin usr/share usr/X11 usr/X11R6 Developer/Headers Developer/Library Developer/Makefiles Developer/Platforms Developer/Private Developer/SDKs Developer/Tools Developer/usr System/Library/CoreServices System/Library/Filesystems System/Library/Frameworks System/Library/Java System/Library/Perl System/Library/PrivateFrameworks System/Library/Tcl"
+   pathsToCopy="private/etc/bashrc private/etc/group private/etc/hosts private/etc/pam.d private/etc/passwd private/etc/profile private/etc/shells private/var/root bin sbin etc tmp var usr/bin usr/include usr/lib usr/libexec usr/sbin usr/share usr/X11 usr/X11R6 Developer/Headers Developer/Library Developer/Makefiles Developer/Platforms Developer/Private Developer/SDKs Developer/Tools Developer/usr System/Library/CoreServices System/Library/Filesystems System/Library/Frameworks System/Library/Java System/Library/Perl System/Library/PrivateFrameworks System/Library/Tcl Developer/Applications/Xcode.app"
 
    # Size of the disk images (hdiutil nomenclature)
    imageSize="32g"
@@ -146,6 +151,7 @@
          done
 
          for copypath in ${pathsToCopy}; do
+            echo "Copying ${copypath}..." ###
             pax -r -w -pe $copypath ${chrootPath}
          done
          cd - > /dev/null
@@ -182,27 +188,36 @@
 
 
 #------------------------------------------------------------------------
-# Build MacPorts in the chroot
+# Build MacPorts in the chroot (if not already there)
 # $1 - base directory
-# $2 - chroot path
-# $3 - MacPorts source tarball or svn export dir
+# $2 - dataDir
+# $3 - chroot path
+# $4 - MacPorts source tarball or svn checkout directory
 function buildMacPorts()
 {
-   baseDir=$1
-   chrootPath=$2
-   mpExport=$3
+   local baseDir=$1
+   local dataDir=$2
+   local chrootPath=$3
+   local mpExport=$4
 
-   echo "Building/installing MP in chroot, if necessary"
-
    if [[ ! -d ${chrootPath}/opt/mports ]]; then
-      if [[ -f ${baseDir}/${mpExport} ]]; then
+      if [[ -f ${dataDir}/${mpExport} ]]; then
 	 mkdir -p ${chrootPath}/opt/mports
-	 cd ${chrootPath}/opt/mports
-	 bunzip2 -c ${baseDir}/${mpExport} | tar xf -
+         echo ${mpExport} | grep -q "MacPorts-......tar.gz"
+         if [[ $? == 0 ]]; then
+            cp ${mpExport} ${chrootPath}/opt/mports
+	    cd ${chrootPath}/opt/mports
+            tar xzf ${mpExport} || return 1
+            rm -rf base 2>/dev/null
+            mv $(ls -d MacPorts-?.?.?) base || return 1
+         else
+	    cd ${chrootPath}/opt/mports
+	    bunzip2 -c ${dataDir}/${mpExport} | tar xf -
+         fi
 	 cd - > /dev/null
-      elif [[ -d ${baseDir}/${mpExport} ]]; then
+      elif [[ -d ${dataDir}/${mpExport} ]]; then
 	 mkdir -p ${chrootPath}/opt/mports
-         cd ${baseDir}/${mpExport} && \
+         cd ${dataDir}/${mpExport} && \
             rsync -r --del --exclude '*~' --exclude '.svn' . ${chrootPath}/opt/mports
          cd - > /dev/null
       else
@@ -212,12 +227,9 @@
    fi
 
    if [[ ! -f ${chrootPath}/opt/local/bin/port ]]; then
-      cp -p ${baseDir}/chroot-scripts/installmacports ${chrootPath}/var/tmp/
-      # Set DYLD_NO_FIX_PREBINDING as otherwise, on 10.5, dyld will spew
-      # errors to syslog/console log like:
-      # com.apple.launchd[1] (com.apple.dyld): Throttling respawn: Will start in 10 seconds
-      env -i PATH=/bin:/usr/bin:/sbin:/usr/sbin HOME=/var/root DYLD_NO_FIX_PREBINDING=1 /usr/sbin/chroot ${chrootPath} /bin/sh /var/tmp/installmacports
-      rm ${chrootPath}/var/tmp/installmacports
+
+      chroot_exec installmacports
+
       sed 's/portarchivemode.*no/portarchivemode yes/' ${chrootPath}/opt/local/etc/macports/macports.conf > ${chrootPath}/opt/local/etc/macports/macports.conf.new
       mv ${chrootPath}/opt/local/etc/macports/macports.conf.new ${chrootPath}/opt/local/etc/macports/macports.conf
    fi
@@ -233,31 +245,43 @@
 # $2 - chroot path
 function buildPorts()
 {
-   baseDir=$1
-   chrootPath=$2
+   local baseDir=$1
+   local chrootPath=$2
 
    echo "Building ports"
 
-   cp -p ${baseDir}/chroot-scripts/buildports ${chrootPath}/var/tmp/
    cp -p ${baseDir}/chroot-scripts/genportlist.tcl ${chrootPath}/var/tmp/
 
-   # Set DYLD_NO_FIX_PREBINDING as otherwise, on 10.5, dyld will spew
-   # errors to syslog/console log like:
-   # com.apple.launchd[1] (com.apple.dyld): Throttling respawn: Will start in 10 seconds
-   env -i PATH=/bin:/usr/bin:/sbin:/usr/sbin HOME=/var/root DYLD_NO_FIX_PREBINDING=1 /usr/sbin/chroot ${chrootPath} /bin/sh /var/tmp/buildports
+   chroot_exec buildports
 
    return 0
 }
 
 
 #------------------------------------------------------------------------
+# Start a shell inside of the chroot jail.
+function chrootShell()
+{
+   echo "Starting chroot shell"
+
+   cp -p ${baseDir}/chroot-scripts/chrootshell ${chrootPath}/var/tmp/
+
+   chroot_exec chrootshell
+
+   echo "Chroot shell exited"
+
+   return 0
+}
+
+
+#------------------------------------------------------------------------
 # Move logs and report results
 # $1 - base directory
 # $2 - chroot path
 function moveAndReport()
 {
-   baseDir=$1
-   chrootPath=$2
+   local baseDir=$1
+   local chrootPath=$2
 
    now=`date '+%Y%m%d-%H%M%S'`
    mkdir ${baseDir}/logs-${now}
@@ -280,9 +304,9 @@
 # $3 - base name for the disk images
 function mountChroot()
 {
-   baseDir=$1
-   chrootPath=$2
-   imgBaseName=$3
+   local baseDir=$1
+   local chrootPath=$2
+   local imgBaseName=$3
 
    echo "Mounting chroot images"
 
@@ -320,7 +344,7 @@
 # $1 - chroot path
 function umountChroot()
 {
-   chrootPath=$1
+   local chrootPath=$1
 
    if [[ -d ${chrootPath}/dev ]]; then
       # First for the fdesc
@@ -341,6 +365,21 @@
    return 0
 }
 
+
+#------------------------------------------------------------------------
+# Execute a script inside the chroot environment. Includes copying it
+# into a temp file and removing it afterwards
+# $1 - script to execute
+function chroot_exec () {
+    cp -p ${baseDir}/chroot-scripts/$1 ${chrootPath}/var/tmp
+    # Set DYLD_NO_FIX_PREBINDING as otherwise, on 10.5, dyld will spew
+    # errors to syslog/console log like:
+    # com.apple.launchd[1] (com.apple.dyld): Throttling respawn: Will start in 10 seconds
+    env -i PATH=/bin:/usr/bin:/sbin:/usr/sbin HOME=/var/root DYLD_NO_FIX_PREBINDING=1 /usr/sbin/chroot ${chrootPath} /bin/sh /var/tmp/$1
+    rm ${chrootPath}/var/tmp/$1
+}
+
+
 # Local Variables:
 # mode: shell-script
 # indent-tabs-mode: nil

Modified: contrib/mpab/mpsync.sh
===================================================================
--- contrib/mpab/mpsync.sh	2009-06-01 07:57:29 UTC (rev 51708)
+++ contrib/mpab/mpsync.sh	2009-06-01 08:17:57 UTC (rev 51709)
@@ -1,9 +1,18 @@
 #!/bin/sh
 
-baseDir=`dirname $0`
-chrootPath=${baseDir}/mpchroot
 exportDir=mpexport
 
+CHROOTSUBDIR=mpchroot
+
+baseDir=$(dirname $0)
+
+dataDir=$(pwd)
+if [[ $MPAB_DATA ]]; then
+   dataDir=$MPAB_DATA
+fi
+
+chrootPath="${dataDir}/${CHROOTSUBDIR}"
+
 # $1 - script to execute
 function chroot_exec () {
     cp -p ${baseDir}/chroot-scripts/$1 ${chrootPath}/var/tmp/
@@ -14,29 +23,29 @@
     rm ${chrootPath}/var/tmp/$1
 }
 
-if [[ -d ${baseDir}/${exportDir} ]] ; then 
+if [[ -d ${dataDir}/${exportDir} ]] ; then 
     svn update --non-interactive \
-	-r HEAD ${baseDir}/${exportDir} \
+	-r HEAD ${dataDir}/${exportDir} \
 	> /dev/null || exit 1
 else
     echo "Checking out macports from svn..."
     svn checkout --non-interactive -r HEAD \
 	http://svn.macports.org/repository/macports/trunk \
-	${baseDir}/${exportDir} > /dev/null || exit 1
+	${dataDir}/${exportDir} > /dev/null || exit 1
 fi
 
-if [[ ! -d ${baseDir}/mpchroot ]] ; then
+if [[ ! -d ${dataDir}/mpchroot ]] ; then
     sudo ${baseDir}/mpab mount || exit 1
     umount=yes
 fi
 
 rsync -r --del --exclude '*~' --exclude '.svn' \
-    ${baseDir}/${exportDir}/dports \
-    ${baseDir}/mpchroot/opt/mports || exit 1
+    ${dataDir}/${exportDir}/dports \
+    ${dataDir}/mpchroot/opt/mports || exit 1
 
 echo "Re-creating portindex in chroot"
 chroot_exec recreateportindex
 
 if [[ "${umount}" = yes ]] ; then
-    sudo ${baseDir}/mpab mount || exit 1
+    sudo ${baseDir}/mpab umount || exit 1
 fi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20090601/f5c8392b/attachment.html>


More information about the macports-changes mailing list