X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=build.sh;h=3635abf811ad610dd50801430e325b41be0e746a;hb=refs%2Fheads%2Fmyplc-0_4-branch;hp=3b7a379726d0a8f65a523dac3e176daed04335b7;hpb=f872afaa7976264819814d3e3289e020c0f77eae;p=myplc.git diff --git a/build.sh b/build.sh index 3b7a379..3635abf 100755 --- a/build.sh +++ b/build.sh @@ -1,160 +1,146 @@ #!/bin/bash # -# Builds a Fedora based PLC image. You should be able to run this -# script multiple times without a problem. +# Builds MyPLC, either inside the MyPLC development environment in +# devel/root (if PLC_DEVEL_BOOTSTRAP is true), or in the current host +# environment (may be itself a MyPLC development environment or a +# Fedora Core 4 environment with the appropriate development packages +# installed). +# +# root.img (loopback image) +# root/ (mount point) +# data/ (various data files) +# data/etc/planetlab/ (configuration files) +# data/root (root's homedir) # # Mark Huang # Copyright (C) 2006 The Trustees of Princeton University # -# $Id$ +# $Id: build.sh,v 1.33 2006/08/18 14:35:52 thierry Exp $ # -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. -if [ -d ../build ] ; then - PATH=$PATH:../build - srcdir=.. -else - echo "Error: Could not find $(cd .. && pwd -P)/build/" - exit 1 -fi - -export PATH - -# PLC configuration file -config=plc_config.xml +. build.functions -# Release and architecture to install -releasever=2 -basearch=i386 - -# Initial size of the image -size=1000000000 +# +# Build myplc inside myplc-devel. Infinite recursion is avoided only +# if PLC_DEVEL_BOOTSTRAP is false in the default configuration file. +# -usage() -{ - echo "Usage: build.sh [OPTION]..." - echo " -c file PLC configuration file (default: $config)" - echo " -r release Fedora release number (default: $releasever)" - echo " -a arch Fedora architecture (default: $basearch)" - echo " -s size Approximate size of the installation (default: $size)" - echo " -h This message" - exit 1 -} +if [ "$PLC_DEVEL_BOOTSTRAP" = "true" ] ; then + # So that we don't pollute the actual myplc-devel image, we use + # the directory that was used to build the image instead of the + # image itself, and mount everything by hand. + mount -o bind,rw devel/data devel/root/data + mount -t proc none devel/root/proc + + # If we used a local mirror, bind mount it into the chroot so that + # we can use it again. + if [ "${PLC_DEVEL_FEDORA_URL:0:7}" = "file://" ] ; then + mkdir -p devel/root/data/fedora + mount -o bind,ro ${PLC_DEVEL_FEDORA_URL#file://} devel/root/data/fedora + fi -# Get options -while getopts "c:r:a:s:h" opt ; do - case $opt in - c) - config=$OPTARG - ;; - r) - releasever=$OPTARG - ;; - a) - basearch=$OPTARG - ;; - s) - size=$OPTARG - ;; - h|*) - usage - ;; - esac -done + # Clean up before exiting if anything goes wrong + trap "umount $PWD/devel/root/data/fedora; + umount $PWD/devel/root/data; + umount $PWD/devel/root/proc" ERR INT + + # Build myplc inside myplc-devel. Make sure PLC_DEVEL_BOOTSTRAP is + # false to avoid infinite recursion. + chroot devel/root su - < $roothome/.profile +export PS1=" \$PS1" +EOF +chmod 644 $roothome/.profile # Move "data" directories out of the installation +echo "* myplc: Moving data directories out of the installation" datadirs=( /etc/planetlab +/root /var/lib/pgsql /var/www/html/alpina-logs /var/www/html/boot @@ -164,117 +150,19 @@ datadirs=( /var/www/html/xml ) -echo "* Moving data directories out of the installation" -mkdir -p $root/data -for datadir in "${datadirs[@]}" ; do - mkdir -p ${data}$datadir - if [ -d $root/$datadir -a ! -h $root/$datadir ] ; then - (cd $root && find ./$datadir | cpio -p -d -u ../$data/) - fi - rm -rf $root/$datadir - mkdir -p $(dirname $root/$datadir) - ln -nsf /data$datadir $root/$datadir -done - -# Shrink to 100 MB free space -kb=$(python < target: - print (df.f_blocks - (df.f_bavail - target)) * df.f_bsize / 1024 -EOF -) - -umount $root -trap - ERR - -if [ -n "$kb" ] ; then - # Setup loopback association. Newer versions of losetup have a -f - # option which finds an unused loopback device, but we must - # support FC2 for now. - # dev_loop=$(losetup -f) - for i in `seq 1 7` ; do - if ! grep -q "^/dev/loop$i" /proc/mounts ; then - dev_loop="/dev/loop$i" - break - fi - done - losetup $dev_loop $root.img - trap "losetup -d $dev_loop" ERR +move_datadirs root data "${datadirs[@]}" - # Resize the filesystem - echo "* Checking filesystem" - e2fsck -a -f $dev_loop - echo "* Shrinking filesystem" - resize2fs $dev_loop ${kb}K - - # Tear down loopback association - losetup -d $dev_loop - trap - ERR - - # Truncate the image file - perl -e "truncate '$root.img', $kb*1024" -fi - -# Write sysconfig -cat >plc.sysconfig <100MB but only take a -# couple of seconds to generate at first boot. -rm -f $data/var/www/html/download/*.{iso,usb} -install -D -m 644 $config $data/etc/planetlab/plc_config.xml +install -D -m 644 ../build/groups/v3_yumgroups.xml \ + data/var/www/html/install-rpms/planetlab/yumgroups.xml -./host.init stop -RETVAL=$(($RETVAL+$?)) +# Make image out of directory +echo "* myplc: Building loopback image" +make_image root root.img -exit $RETVAL +exit 0