[51462] users/febeling/mpab

febeling at macports.org febeling at macports.org
Mon May 25 14:07:52 PDT 2009


Revision: 51462
          http://trac.macports.org/changeset/51462
Author:   febeling at macports.org
Date:     2009-05-25 14:07:52 -0700 (Mon, 25 May 2009)
Log Message:
-----------
Various changes, see ChangeLog for details.

* install from release tarball
* ability to update port tree, using mpsync.sh
* a shell running inside the chroot jail
* use a svn working copy instead of a gzipped export
* add ChangeLog file

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

Added Paths:
-----------
    users/febeling/mpab/ChangeLog
    users/febeling/mpab/chroot-scripts/chrootshell

Added: users/febeling/mpab/ChangeLog
===================================================================
--- users/febeling/mpab/ChangeLog	                        (rev 0)
+++ users/febeling/mpab/ChangeLog	2009-05-25 21:07:52 UTC (rev 51462)
@@ -0,0 +1,22 @@
+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: users/febeling/mpab/ReadMe.txt
===================================================================
--- users/febeling/mpab/ReadMe.txt	2009-05-25 20:59:22 UTC (rev 51461)
+++ users/febeling/mpab/ReadMe.txt	2009-05-25 21:07:52 UTC (rev 51462)
@@ -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: users/febeling/mpab/chroot-scripts/buildports
===================================================================
--- users/febeling/mpab/chroot-scripts/buildports	2009-05-25 20:59:22 UTC (rev 51461)
+++ users/febeling/mpab/chroot-scripts/buildports	2009-05-25 21:07:52 UTC (rev 51462)
@@ -34,7 +34,7 @@
 {
    installedPorts=`/opt/local/bin/port installed | /usr/bin/tail +2 | /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
@@ -107,7 +107,7 @@
          fi
       done
       if [[ -z $skipPort ]]; then
-         /opt/local/bin/port -dvx install $portName > ${PORTRESULTSDIR}/${portName}.log 2>&1
+         /opt/local/bin/port -dvxo install $portName > ${PORTRESULTSDIR}/${portName}.log 2>&1
          if [[ $? == 0 ]]; then
             /bin/mv ${PORTRESULTSDIR}/${portName}.log ${PORTRESULTSDIR}/success
             echo "success"

Added: users/febeling/mpab/chroot-scripts/chrootshell
===================================================================
--- users/febeling/mpab/chroot-scripts/chrootshell	                        (rev 0)
+++ users/febeling/mpab/chroot-scripts/chrootshell	2009-05-25 21:07:52 UTC (rev 51462)
@@ -0,0 +1,2 @@
+#!/bin/sh
+PS1="[MPAB_CHROOT \w] \$ " sh -i 


Property changes on: users/febeling/mpab/chroot-scripts/chrootshell
___________________________________________________________________
Added: svn:executable
   + *

Modified: users/febeling/mpab/mpab
===================================================================
--- users/febeling/mpab/mpab	2009-05-25 20:59:22 UTC (rev 51461)
+++ users/febeling/mpab/mpab	2009-05-25 21:07:52 UTC (rev 51462)
@@ -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: users/febeling/mpab/mpab-functions
===================================================================
--- users/febeling/mpab/mpab-functions	2009-05-25 20:59:22 UTC (rev 51461)
+++ users/febeling/mpab/mpab-functions	2009-05-25 21:07:52 UTC (rev 51462)
@@ -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 directhory ${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"
 
@@ -182,27 +187,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
@@ -217,7 +231,7 @@
       # 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
+      rm ${chrootPath}/var/tmp/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,8 +247,8 @@
 # $2 - chroot path
 function buildPorts()
 {
-   baseDir=$1
-   chrootPath=$2
+   local baseDir=$1
+   local chrootPath=$2
 
    echo "Building ports"
 
@@ -251,13 +265,32 @@
 
 
 #------------------------------------------------------------------------
+# Start a shell inside of the chroot jail.
+function chrootShell()
+{
+   echo "Starting chroot shell"
+
+   cp -p ${baseDir}/chroot-scripts/chrootshell ${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/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 +313,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 +353,7 @@
 # $1 - chroot path
 function umountChroot()
 {
-   chrootPath=$1
+   local chrootPath=$1
 
    if [[ -d ${chrootPath}/dev ]]; then
       # First for the fdesc

Modified: users/febeling/mpab/mpsync.sh
===================================================================
--- users/febeling/mpab/mpsync.sh	2009-05-25 20:59:22 UTC (rev 51461)
+++ users/febeling/mpab/mpsync.sh	2009-05-25 21:07:52 UTC (rev 51462)
@@ -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/20090525/15fa33e1/attachment-0001.html>


More information about the macports-changes mailing list