and again
[bootstrapfs.git] / build.sh
index 8165fa5..371faa8 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -1,25 +1,29 @@
 #!/bin/bash
 #
-# Build PlanetLab-Bootstrap.tar.bz2, the reference image for PlanetLab
-# nodes.
+# Build tgz root image for PlanetLab nodes.
 #
 # Mark Huang <mlhuang@cs.princeton.edu>
 # Marc E. Fiuczynski <mef@cs.princeton.edu>
 # Copyright (C) 2005-2007 The Trustees of Princeton University
 #
-# $Id: buildnode.sh,v 1.12.6.1 2007/08/30 20:09:20 mef Exp $
+
+#
+# This will build the bootstrafs-*.tar.bz2 images, which comprises
+# the base root image on the node, then create the ${NAME} bootstrap image
+# which is made up of just the additional files needed for a ${NAME} nodegroup 
+# node.
 #
+# It is expected to be in sync with the getNodeFlavour PLCAPI method
 
 PATH=/sbin:/bin:/usr/sbin:/usr/bin
 
-# In both a normal CVS environment and a PlanetLab RPM
-# build environment, all of our dependencies are checked out into
-# directories at the same level as us.
+# in the PlanetLab build environment, our dependencies are checked out 
+# into directories at the same level as us.
 if [ -d ../build ] ; then
     PATH=$PATH:../build
     srcdir=../
 else
-    echo "Error: Could not find $(cd ../.. && pwd -P)/build/"
+    echo "Error: Could not find ../build in $(pwd)"
     exit 1
 fi
 
@@ -31,6 +35,13 @@ pl_process_fedora_options $@
 shiftcount=$?
 shift $shiftcount
 
+# expecting fcdistro and pldistro on the command line
+pldistro=$1; shift
+fcdistro=${pl_DISTRO_NAME}
+arch=${pl_DISTRO_ARCH}
+nodefamily=${pldistro}-${fcdistro}-${arch}
+extensionfamily=${fcdistro}-${arch}
+
 # Do not tolerate errors
 set -e
 
@@ -39,35 +50,43 @@ set -e
 # would like to pretend that we are.
 export PL_BOOTCD=1
 
-# "Parse" out the packages and groups into the options passed to mkfedora
-# -k = exclude kernel* packages
-options="-k"
-packages=$(grep "^package:.*" base.lst | awk '{print $2}')
-groups=$(grep "^group:.*" base.lst | awk '{print $2}')
-for package in ${packages} ; do  options="$options -p $package"; done
-for group in ${groups} ; do options="$options -g $group"; done
-
-# Populate a minimal /dev and then the files for the base PlanetLab-Bootstrap content
+# Populate a minimal /dev and then the files for the base nodeimage content
 vref=${PWD}/base
 install -d -m 755 ${vref}
-pl_makedevs ${vref}
-pl_setup_chroot ${vref} -k ${options}
+pl_root_makedevs $vref
 
-# Build the base Bootstrap filesystem
-echo "--------STARTING tar'ing PlanetLab-Bootstrap.tar.bz2: $(date)"
-tar -cpjf PlanetLab-Bootstrap.tar.bz2 -C ${vref} .
-echo "--------FINISHED tar'ing PlanetLab-Bootstrap.tar.bz2: $(date)"
+pkgsfile=$(pl_locateDistroFile ../build/ ${pldistro} nodeimage.pkgs)
+echo "* Building nodeimage for ${pldistro}: $(date)"
+# -k = exclude kernel* packages
+pl_root_mkfedora ${vref} ${pldistro} $pkgsfile
+
+# optionally invoke a post processing script after packages from
+# $pkgsfile have been installed
+postfile=$(pl_locateDistroFile ../build/ ${pldistro} nodeimage.post || : )
+[ -f $postfile ] && { echo "Running post install file $postfile" ; /bin/bash $postfile ${vref} || : ; }
+
+displayed=""
 
-for bootstrapfs in bootstrap-filesystems/*.lst ; do
-    NAME=$(basename $bootstrapfs .lst)
+# for distros that do define node extensions
+pkgs_count=$(ls ../build/config.${pldistro}/nodeimage-*.pkgs 2> /dev/null | wc -l)
+[ $pkgs_count -gt 0 ] && for pkgs in $(ls ../build/config.${pldistro}/nodeimage-*.pkgs); do
+    NAME=$(basename $pkgs .pkgs | sed -e s,nodeimage-,,)
 
-    echo "--------START BUILDING PlanetLab-Bootstrap-${NAME}: $(date)"
+    [ -z "$displayed" ] && echo "* Handling ${pldistro} nodeimage extensions"
+    displayed=true
+
+    extension_plain=nodeimage-${NAME}-${extensionfamily}.tar
+    extension_name=nodeimage-${NAME}-${extensionfamily}.tar.bz2
+
+    echo "* Start Building $extension_name: $(date)"
 
     # "Parse" out the packages and groups for yum
-    packages=$(grep "^package:.*" $bootstrapfs | awk '{print $2}')
-    groups=$(grep "^group:.*" $bootstrapfs | awk '{print $2}')
+    packages=$(pl_getPackages $fcdistro $pldistro $pkgs)
+    groups=$(pl_getGroups $fcdistro $pldistro $pkgs)
+    echo "${NAME} has the following packages : ${packages}"
+    echo "${NAME} has the following groups : ${groups}"
 
-    vdir=${PWD}/bootstrap-filesystems/${NAME}
+    vdir=${PWD}/${pldistro}-filesystems/${NAME}
     rm -rf ${vdir}/*
     install -d -m 755 ${vdir}
 
@@ -76,14 +95,29 @@ for bootstrapfs in bootstrap-filesystems/*.lst ; do
     rm -f ${vdir}/var/lib/rpm/__db*
 
     # Install the system vserver specific packages
-    [ -n "$systempackages" ] && yum -c ${vdir}/etc/yum.conf --installroot=${vdir} -y install $systempackages
-    [ -n "$systemgroups" ] && yum -c ${vdir}/etc/yum.conf --installroot=${vdir} -y groupinstall $systemgroups
+    [ -n "$packages" ] && yum -c ${vdir}/etc/mkfedora-yum.conf --installroot=${vdir} -y install $packages
+    for group_plus in $groups; do
+       group=$(echo $group_plus | sed -e "s,+++, ,g")
+        yum -c ${vdir}/etc/mkfedora-yum.conf --installroot=${vdir} -y groupinstall "$group"
+    done
+
+
+    if [ -f "${vdir}/proc/cpuinfo" ] ; then
+        echo "WARNING: some RPM appears to have mounted /proc in ${NAME}. Unmounting it!"
+        umount ${vdir}/proc
+    fi
 
-    # Create a copy of the system vserver w/o the vserver reference files and make it smaller. 
-    # This is a three step process:
+    # optionally invoke a post processing script after packages from
+    # $pkgs have been installed
+    postfile=$(pl_locateDistroFile ../build/ ${pldistro} nodeimage-${NAME}.post || : )
+    [ -f $postfile ] && { echo "Running post install file $postfile" ; /bin/bash $postfile ${vdir} || : ; }
+
+    # Create a copy of the ${NAME} bootstrap filesystem w/o the base
+    # bootstrap filesystem and make it smaller.  This is a three step
+    # process:
 
     # step 1: clean out yum cache to reduce space requirements
-    yum -c ${vdir}/etc/yum.conf --installroot=${vdir} -y clean all
+    yum -c ${vdir}/etc/mkfedora-yum.conf --installroot=${vdir} -y clean all
 
     # step 2: figure out the new/changed files in ${vdir} vs. ${vref} and compute ${vdir}.changes
     rsync -anv ${vdir}/ ${vref}/ > ${vdir}.changes
@@ -105,11 +139,27 @@ for bootstrapfs in bootstrap-filesystems/*.lst ; do
     rm -rf ${vdir}
     rm -f  ${vdir}.changes
     mv ${vdir}-tmp ${vdir}
-
-    echo "--------STARTING tar'ing PlanetLab-Bootstrap-${NAME}.tar.bz2: $(date)"
-    tar -cpjf bootstrap-filesystems/PlanetLab-Bootstrap-${NAME}.tar.bz2 -C ${vdir} .
-    echo "--------FINISHED tar'ing PlanetLab-Bootstrap-${NAME}.tar.bz2: $(date)"
-    echo "--------DONE BUILDING PlanetLab-Bootstrap-${NAME}: $(date)"
+    
+    echo -n "* tar $extension_name s=$(date +%H-%M-%S)"
+    tar -cpf ${pldistro}-filesystems/$extension_plain -C ${vdir} .
+    echo -n " m=$(date +%H-%M-%S) "
+    bzip2 --compress --stdout ${pldistro}-filesystems/$extension_plain > ${pldistro}-filesystems/$extension_name
+    echo " e=$(date +%H-%M-%S) "
 done
 
+# Build the base Bootstrap filesystem
+# clean out yum cache to reduce space requirements
+yum -c ${vref}/etc/mkfedora-yum.conf --installroot=${vref} -y clean all
+# create stamp on node image to help out node upgrades in the future
+mkdir -p ${vref}/etc/planetlab
+echo ${nodefamily} > ${vref}/etc/planetlab/nodefamily
+
+bootstrapfs_plain=bootstrapfs-${nodefamily}.tar
+bootstrapfs_name=bootstrapfs-${nodefamily}.tar.bz2
+echo -n "* tar $bootstrapfs_name s=$(date +%H-%M-%S)"
+tar -cpf $bootstrapfs_plain -C ${vref} .
+echo -n " m=$(date +%H-%M-%S) "
+bzip2 --compress --stdout $bootstrapfs_plain > $bootstrapfs_name
+echo " e=$(date +%H-%M-%S) "
+
 exit 0