- split build.sh into two pieces: build_devel.sh, which builds
[myplc.git] / build.sh
1 #!/bin/bash
2 #
3 # Builds MyPLC, either inside the MyPLC development environment in
4 # devel/root (if PLC_DEVEL_BOOTSTRAP is true), or in the current host
5 # environment (may be itself a MyPLC development environment or a
6 # Fedora Core 4 environment with the appropriate development packages
7 # installed).
8 #
9 # root.img (loopback image)
10 # root/ (mount point)
11 # data/ (various data files)
12 # data/etc/planetlab/ (configuration files)
13 #
14 # Mark Huang <mlhuang@cs.princeton.edu>
15 # Copyright (C) 2006 The Trustees of Princeton University
16 #
17 # $Id$
18 #
19
20 . build.functions
21
22 #
23 # Build myplc inside myplc-devel. Infinite recursion is avoided only
24 # if PLC_DEVEL_BOOTSTRAP is false in the default configuration file.
25 #
26
27 if [ "$PLC_DEVEL_BOOTSTRAP" = "true" ] ; then
28     # So that we don't pollute the actual myplc-devel image, we use
29     # the directory that was used to build the image instead of the
30     # image itself, and mount everything by hand.
31     mount -o bind,rw devel/data devel/root/data
32     mount -t proc none devel/root/proc
33
34     # If we used a local mirror, bind mount it into the chroot so that
35     # we can use it again.
36     if [ "${PLC_DEVEL_FEDORA_URL:0:7}" = "file://" ] ; then
37         mkdir -p devel/root/usr/share/mirrors/fedora
38         mount -o bind,ro ${PLC_DEVEL_FEDORA_URL#file://} devel/root/usr/share/mirrors/fedora
39     fi
40
41     # Clean up before exiting if anything goes wrong
42     trap "umount $PWD/devel/root/data;
43           umount $PWD/devel/root/proc;
44           umount $PWD/devel/root/usr/share/mirrors/fedora" ERR INT
45
46     # Build myplc inside myplc-devel. Make sure PLC_DEVEL_BOOTSTRAP is
47     # false to avoid infinite recursion.
48     chroot devel/root sh -s <<EOF
49 set -x
50 service plc start
51 plc-config --category=plc_devel --variable=bootstrap --value="false" --save
52 service plc reload
53 cd /
54 cvs -d /cvs checkout build
55 make -C /build myplc
56 EOF
57
58     # Yoink the image that was just built
59     mv devel/data/build/BUILD/myplc-*/myplc/root{,.img} devel/data/build/BUILD/myplc-*/myplc/data .
60
61     # Clean up
62     umount devel/root/data
63     umount devel/root/proc
64     umount devel/root/usr/share/mirrors/fedora || :
65
66     # Could leave it around, but it does consume a lot of disk space
67     # rm -rf devel/data/build
68     # mkdir -p devel/data/build
69
70     # No need to continue
71     exit 0
72 fi
73
74 #
75 # Build myplc in the host environment. This section is executed if
76 # PLC_DEVEL_BOOTSTRAP is false.
77 #
78
79 echo "* myplc: Installing base filesystem"
80 mkdir -p root data
81 make_chroot root plc_config.xml
82
83 # Build schema
84 echo "* myplc: Building database schema"
85 make -C $srcdir/pl_db
86
87 # Install configuration scripts
88 echo "* myplc: Installing configuration scripts"
89 install -D -m 755 plc_config.py root/tmp/plc_config.py
90 chroot root sh -c 'cd /tmp; python plc_config.py build; python plc_config.py install'
91 install -D -m 755 plc-config root/usr/bin/plc-config
92 install -D -m 755 api-config root/usr/bin/api-config
93 install -D -m 755 db-config root/usr/bin/db-config
94 install -D -m 755 dns-config root/usr/bin/dns-config
95
96 # Install initscripts
97 echo "* myplc: Installing initscripts"
98 find plc.d | cpio -p -d -u root/etc/
99 install -D -m 755 guest.init root/etc/init.d/plc
100 chroot root sh -c 'chkconfig --add plc; chkconfig plc on'
101
102 # Install DB schema and API code
103 echo "* myplc: Installing DB schema and API code"
104 mkdir -p root/usr/share
105 rsync -a $srcdir/pl_db $srcdir/plc_api root/usr/share/
106
107 # Install web scripts
108 echo "* myplc: Installing web scripts"
109 mkdir -p root/usr/bin
110 install -m 755 \
111     $srcdir/plc/scripts/gen-sites-xml.py \
112     $srcdir/plc/scripts/gen-slices-xml-05.py \
113     $srcdir/plc/scripts/gen-static-content.py \
114     root/usr/bin/
115
116 # Install web pages
117 echo "* myplc: Installing web pages"
118 mkdir -p root/var/www/html
119 # Exclude old cruft, unrelated GENI pages, and official documents
120 rsync -a \
121     --exclude='*2002' --exclude='*2003' \
122     --exclude=geni --exclude=PDN --exclude=Talks \
123     $srcdir/plc_www/ root/var/www/html/
124
125 # Install configuration file
126 echo "* myplc: Installing configuration file"
127 install -D -m 444 $config data/etc/planetlab/default_config.xml
128 install -D -m 444 plc_config.dtd data/etc/planetlab/plc_config.dtd
129
130 # Move "data" directories out of the installation
131 datadirs=(
132 /etc/planetlab
133 /var/lib/pgsql
134 /var/www/html/alpina-logs
135 /var/www/html/boot
136 /var/www/html/download
137 /var/www/html/generated
138 /var/www/html/install-rpms
139 /var/www/html/xml
140 )
141
142 move_datadirs root data "${datadirs[@]}"
143
144 # Initialize node RPMs directory. The PlanetLab-Bootstrap.tar.bz2
145 # tarball already contains all of the node RPMs pre-installed. Only
146 # updates or optional packages should be placed in this directory.
147 if [ -n "$RPM_BUILD_DIR" ] ; then
148     echo "* myplc: Initializing node RPMs directory"
149     RPM_RPMS_DIR=$(cd $(dirname $RPM_BUILD_DIR)/RPMS && pwd -P)
150     mkdir -p data/var/www/html/install-rpms/planetlab
151     if [ -f $RPM_RPMS_DIR/yumgroups.xml ] ; then
152         install -D -m 644 $RPM_RPMS_DIR/yumgroups.xml \
153             data/var/www/html/install-rpms/planetlab/yumgroups.xml
154     fi
155     # yum-2.0.x
156     if [ -x /usr/bin/yum-arch ] ; then
157         yum-arch data/var/www/html/install-rpms/planetlab
158     fi
159     # yum-2.4.x
160     if [ -x /usr/bin/createrepo ] ; then
161         if [ -f data/var/www/html/install-rpms/planetlab/yumgroups.xml ] ; then
162             groupfile="-g yumgroups.xml"
163         fi
164         createrepo $groupfile data/var/www/html/install-rpms/planetlab
165     fi
166 fi
167
168 # Make image out of directory
169 echo "* myplc: Building loopback image"
170 make_image root root.img
171
172 exit 0