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.6 2007/08/16 21:42:02 mef 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=$([ -f "/etc/fedora-release" ] && awk ' { if ($3=="Core") print $4; else print $3 } ' /etc/fedora-release || echo 4)
29 PLC_DEVEL_FEDORA_ARCH=$(uname -i)
30 # Fedora Core mirror from which to install filesystems
31 PLC_DEVEL_FEDORA_URL=file:///data/fedora
33 # We may be running inside a myplc-devel environment, which can
34 # override these defaults.
35 if [ -f /etc/planetlab/plc_config ] ; then
36 . /etc/planetlab/plc_config
41 echo "Usage: $0 [OPTION]..."
42 echo " -l url Fedora mirror location (default: $PLC_DEVEL_FEDORA_URL)"
43 echo " -r release Fedora release number (default: $PLC_DEVEL_FEDORA_RELEASE)"
44 echo " -a arch Fedora architecture (default: $PLC_DEVEL_FEDORA_ARCH)"
45 echo " -h This message"
50 while getopts "l:r:a:h" opt ; do
53 PLC_DEVEL_FEDORA_URL=$OPTARG
56 PLC_DEVEL_FEDORA_RELEASE=$OPTARG
59 PLC_DEVEL_FEDORA_ARCH=$OPTARG
67 # Do not tolerate errors
73 # Make a basic chroot at the specified location given the specified
82 groups="$groups -g \"$group\""
83 done < <(./plc-config --groups $config)
87 while read package ; do
88 packages="$packages -p \"$package\""
89 done < <(./plc-config --packages $config)
92 eval mkfedora -v -l $PLC_DEVEL_FEDORA_URL -r $PLC_DEVEL_FEDORA_RELEASE -a $PLC_DEVEL_FEDORA_ARCH $packages $groups $root
94 # Disable all services in reference image
95 chroot $root sh -c "/sbin/chkconfig --list | awk '{ print \$1 }' | xargs -i /sbin/chkconfig {} off"
97 # FC2 minilogd starts up during shutdown and makes unmounting
98 # impossible. Just get rid of it.
99 rm -f $root/sbin/minilogd
100 ln -nsf /bin/true $root/sbin/minilogd
103 # Move specified directories out of the chroot and into a "data"
104 # directory that will be bind mounted on /data inside the chroot.
111 for datadir in "$@" ; do
112 mkdir -p ${data}$datadir
113 if [ -d $root/$datadir -a ! -h $root/$datadir ] ; then
114 (cd $root && find ./$datadir | cpio -p -d -u ../$data/)
116 rm -rf $root/$datadir
117 mkdir -p $(dirname $root/$datadir)
118 ln -nsf /data$datadir $root/$datadir
122 # Make loopback filesystem from specified location
127 # Leave about 100 MB free space and allow for about 20% inode overhead
128 bytes=$((($(du -sb $root | cut -f1) + 100000000) * 120 / 100))
130 blocks=$(($bytes / $bs))
131 dd bs=$bs count=$blocks if=/dev/zero of=$image
132 mkfs.ext3 -b $bs -j -F $image
134 # Temporarily mount it
135 tmp=$(mktemp -d tmp.XXXXXX)
136 mount -o loop $image $tmp
137 trap "umount $tmp; rmdir $tmp" ERR INT
140 (cd $root && tar cpf - .) | (cd $tmp && tar xpf -)