X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=build.sh;h=914101e14e7d6b0bf89acb3c314755b04eeacbc9;hb=b8ada6d36e6e6359b8af7c951d10df89fa3c4514;hp=44f0385374e5b0c316f75c446ea202d3f3a1fa83;hpb=77dcd34ba4469156297c742aad0e7c51f6c77f44;p=myplc.git diff --git a/build.sh b/build.sh index 44f0385..914101e 100755 --- a/build.sh +++ b/build.sh @@ -1,216 +1,176 @@ #!/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: build.sh,v 1.1.1.1 2006/03/27 17:36:46 mlhuang Exp $ +# $Id$ # -PATH=/sbin:/bin:/usr/sbin:/usr/bin - -# In a normal CVS environment, the requisite CVS modules (including -# build/) are located at the same level we are. In a PlanetLab RPM -# build environment (see the RPM spec file), they are checked out into -# a subdirectory. -if [ -d ./build ] ; then - PATH=$PATH:./build - srcdir=. -elif [ -d ../build ] ; then - PATH=$PATH:../build - srcdir=.. -else - echo "Error: Could not find sources in either . or .." - exit 1 -fi - -export PATH - -# PLC configuration file -config=plc_config.xml - -# Release and architecture to install -releasever=2 -basearch=i386 - -# Data directory base -usr_share=/usr/share - -# Initial size of the image -size=1000000000 - -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 " -d datadir Data directory base (default: $usr_share)" - echo " -s size Approximate size of the installation (default: $size)" - echo " -h This message" - exit 1 -} - -# Get options -while getopts "c:r:a:d:s:h" opt ; do - case $opt in - c) - config=$OPTARG - ;; - r) - releasever=$OPTARG - ;; - a) - basearch=$OPTARG - ;; - d) - usr_share=$OPTARG - ;; - s) - size=$OPTARG - ;; - h|*) - usage - ;; - esac -done - -root=fc$releasever -data=data$releasever - -if [ ! -f $root.img ] ; then - bs=4096 - count=$(($size / 4096)) - dd bs=$bs count=$count if=/dev/zero of=$root.img - mkfs.ext3 -j -F $root.img -fi - -mkdir -p $root $data -mount -o loop $root.img $root -trap "umount $root; exit 1" ERR +. build.functions # -# Build +# Build myplc inside myplc-devel. Infinite recursion is avoided only +# if PLC_DEVEL_BOOTSTRAP is false in the default configuration file. # -# Get package list -while read package ; do - packages="$packages -p $package" -done < <(./plc-config --packages $config) +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 + + # 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 -datadirs=( -/etc/planetlab -/var/lib/pgsql -/var/www/html/alpina-logs -/var/www/html/boot -/var/www/html/download -/var/www/html/generated -/var/www/html/install-rpms -/var/www/html/xml -) +echo "* myplc: Moving data directories out of the installation" +move_datadirs root data "${datadirs[@]}" -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 +# Fix permissions on tmp directories +chmod 1777 data/tmp data/usr/tmp data/var/tmp -# Shrink to 100 MB free space -kb=$(python < target: - print (df.f_blocks - (df.f_bavail - target)) * df.f_bsize / 1024 -EOF -) +# Remove generated bootmanager script +rm -f data/var/www/html/boot/bootmanager.sh -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 - - # Resize the filesystem - e2fsck -f $dev_loop - 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 +# Initialize node RPMs directory. The PlanetLab-Bootstrap.tar.bz2 +# tarball already contains all of the node RPMs pre-installed. Only +# updates or optional packages should be placed in this directory. +install -D -m 644 ../build/groups/v3_yumgroups.xml \ + data/var/www/html/install-rpms/planetlab/yumgroups.xml -# Write sysconfig -cat >plc.sysconfig <