typo in BootstrapFS dependency
[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: make.sh,v 1.2 2007/02/07 23:49:42 mlhuang Exp $
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 # Make sure "build" user has proper sudoers setup
50 if [ $(sudo grep "build.*ALL=(ALL).*NOPASSWD:.*ALL" $PLC_ROOT/etc/sudoers | wc -l) -eq 0 ] ; then
51         sudo echo "build ALL=(ALL) NOPASSWD: ALL" >> $PLC_ROOT/etc/sudoers
52 fi
53
54 # Cross mount the current build directory to the build user home directory
55 sudo mount -o bind,rw $BASE $PLC_ROOT/data/build
56
57 # Also cross mount /data/fedora if it exists
58 if [ -d /data/fedora ] ; then
59     sudo mkdir -p $PLC_ROOT/data/fedora
60     sudo mount -o bind,ro /data/fedora $PLC_ROOT/data/fedora
61 fi
62
63 # Delete .rpmmacros and parseSpec files so that they get regenerated
64 # appropriately in the development environment.
65 rm -f $BASE/.rpmmacros $BASE/parseSpec
66
67 # Enable networking
68 sudo cp -f /etc/hosts /etc/resolv.conf $PLC_ROOT/etc/
69
70 # Run the rest of the build
71 sudo chroot $PLC_ROOT su - build -c "make $@"
72 rc=$?
73
74 # Clean up
75 cleanup
76 trap - ERR INT
77
78 exit $rc