add comment header
[build.git] / make.sh
1 #!/bin/bash
2 #
3 # make(1) wrapper to build PlanetLab RPMS inside a myplc-devel
4 # development environment.
5 #
6 # 1. $BASE is the build/ directory containing this script.
7 # 2. Builds myplc-devel using host tools.
8 # 3. Mounts $BASE onto the home directory of the build user inside
9 #    myplc-devel.
10 # 4. Executes "make" on the specified targets.
11 #
12 # Can be used to manally restart a build also, e.g.,
13 #
14 # cd build/nightly/2007.02.07/
15 # ./make.sh kernel
16
17 # Mark Huang <mlhuang@cs.princeton.edu>
18 # Copyright (C) 2007 The Trustees of Princeton University
19 #
20 # $Id$
21 #
22
23 PATH=/sbin:/bin:/usr/sbin:/usr/bin
24
25 BASE=$(cd "$(dirname $0)" && pwd -P)
26
27 # Delete .rpmmacros and parseSpec files in case we are restarting
28 rm -f $BASE/.rpmmacros $BASE/parseSpec
29
30 # Build development environment first
31 make -C $BASE myplc-devel
32
33 # Build everything else inside the development environment
34 export PLC_ROOT=$(echo $BASE/BUILD/myplc-devel-*/myplc/devel/root)
35 export PLC_DATA=$(echo $BASE/BUILD/myplc-devel-*/myplc/devel/data)
36
37 cleanup() {
38     sudo umount $PLC_ROOT/data/fedora
39     sudo umount $PLC_ROOT/data/build
40     sudo $BASE/BUILD/myplc-devel-*/myplc/host.init stop
41     sudo chown -h -R $USER $PLC_DATA
42 }
43
44 trap "cleanup" ERR INT
45
46 # Start development environment
47 sudo $BASE/BUILD/myplc-devel-*/myplc/host.init start
48
49 # Cross mount the current build directory to the build user home directory
50 sudo mount -o bind,rw $BASE $PLC_ROOT/data/build
51
52 # Also cross mount /data/fedora if it exists
53 if [ -d /data/fedora ] ; then
54     sudo mkdir -p $PLC_ROOT/data/fedora
55     sudo mount -o bind,ro /data/fedora $PLC_ROOT/data/fedora
56 fi
57
58 # Delete .rpmmacros and parseSpec files so that they get regenerated
59 # appropriately in the development environment.
60 rm -f $BASE/.rpmmacros $BASE/parseSpec
61
62 # Enable networking
63 sudo cp -f /etc/hosts /etc/resolv.conf $PLC_ROOT/etc/
64
65 # Run the rest of the build
66 sudo chroot $PLC_ROOT su - build -c "make $@"
67 rc=$?
68
69 # Clean up
70 cleanup
71 trap - ERR INT
72
73 exit $rc