3 # Common functions for MyPLC build scripts (build_devel.sh and
6 # Mark Huang <mlhuang@cs.princeton.edu>
7 # Copyright (C) 2006 The Trustees of Princeton University
9 # $Id: build.functions,v 1.3 2006/08/09 21:38:05 mlhuang Exp $
12 PATH=/sbin:/bin:/usr/sbin:/usr/bin
14 # In both a normal CVS environment and a PlanetLab RPM
15 # build environment, all of our dependencies are checked out into
16 # directories at the same level as us.
17 if [ -d ../build ] ; then
21 echo "Error: Could not find $(cd .. && pwd -P)/build/"
27 # Release and architecture to install
28 PLC_DEVEL_FEDORA_RELEASE=4
29 PLC_DEVEL_FEDORA_ARCH=i386
31 # Fedora Core mirror from which to install filesystems
32 PLC_DEVEL_FEDORA_URL=file:///data/fedora
34 # Build myplc inside myplc-devel
35 PLC_DEVEL_BOOTSTRAP=true
37 # Source tag to use for initial import of sources into local CVS
38 IMPORT_TAG=planetlab-$(date +%Y-%m-%d)
40 # Source tag to use for building from local CVS
43 # We may be running inside a myplc-devel environment, which can
44 # override these defaults. Specifically, whether to build myplc inside
45 # myplc-devel (PLC_DEVEL_BOOTSTRAP).
46 if [ -f /etc/planetlab/plc_config ] ; then
47 . /etc/planetlab/plc_config
52 echo "Usage: $0 [OPTION]..."
53 echo " -l url Fedora mirror location (default: $PLC_DEVEL_FEDORA_URL)"
54 echo " -r release Fedora release number (default: $PLC_DEVEL_FEDORA_RELEASE)"
55 echo " -a arch Fedora architecture (default: $PLC_DEVEL_FEDORA_ARCH)"
56 echo " -t tag Source tag (default: $TAG)"
57 echo " -h This message"
62 while getopts "l:r:a:t:h" opt ; do
65 PLC_DEVEL_FEDORA_URL=$OPTARG
68 PLC_DEVEL_FEDORA_RELEASE=$OPTARG
71 PLC_DEVEL_FEDORA_ARCH=$OPTARG
83 # Do not tolerate errors
89 # Make a basic chroot at the specified location given the specified
98 groups="$groups -g \"$group\""
99 done < <(./plc-config --groups $config)
103 while read package ; do
104 packages="$packages -p \"$package\""
105 done < <(./plc-config --packages $config)
107 # Install base system
108 eval mkfedora -v -l $PLC_DEVEL_FEDORA_URL -r $PLC_DEVEL_FEDORA_RELEASE -a $PLC_DEVEL_FEDORA_ARCH $packages $groups $root
110 # Disable all services in reference image
111 chroot $root sh -c "/sbin/chkconfig --list | awk '{ print \$1 }' | xargs -i /sbin/chkconfig {} off"
113 # FC2 minilogd starts up during shutdown and makes unmounting
114 # impossible. Just get rid of it.
115 rm -f $root/sbin/minilogd
116 ln -nsf /bin/true $root/sbin/minilogd
119 # Move specified directories out of the chroot and into a "data"
120 # directory that will be bind mounted on /data inside the chroot.
127 for datadir in "$@" ; do
128 mkdir -p ${data}$datadir
129 if [ -d $root/$datadir -a ! -h $root/$datadir ] ; then
130 (cd $root && find ./$datadir | cpio -p -d -u ../$data/)
132 rm -rf $root/$datadir
133 mkdir -p $(dirname $root/$datadir)
134 ln -nsf /data$datadir $root/$datadir
138 # Make loopback filesystem from specified location
143 # Leave about 100 MB free space and allow for about 20% inode overhead
144 bytes=$((($(du -sb $root | cut -f1) + 100000000) * 120 / 100))
146 blocks=$(($bytes / $bs))
147 dd bs=$bs count=$blocks if=/dev/zero of=$image
148 mkfs.ext3 -b $bs -j -F $image
150 # Temporarily mount it
151 tmp=$(mktemp -d tmp.XXXXXX)
152 mount -o loop $image $tmp
153 trap "umount $tmp; rmdir $tmp" ERR INT
156 (cd $root && tar cpf - .) | (cd $tmp && tar xpf -)