pass CVS tag through to internal myplc build
[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 su - <<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 -r $TAG build
55 make TAG=$TAG -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     rm -rf devel/data/build
66     mkdir -p devel/data/build
67
68     # No need to continue
69     exit 0
70 fi
71
72 #
73 # Build myplc in the host environment. This section is executed if
74 # PLC_DEVEL_BOOTSTRAP is false.
75 #
76
77 echo "* myplc: Installing base filesystem"
78 mkdir -p root data
79 make_chroot root plc_config.xml
80
81 # Build schema
82 echo "* myplc: Building database schema"
83 make -C $srcdir/pl_db
84
85 # Install configuration scripts
86 echo "* myplc: Installing configuration scripts"
87 install -D -m 755 plc_config.py root/tmp/plc_config.py
88 chroot root sh -c 'cd /tmp; python plc_config.py build; python plc_config.py install'
89 install -D -m 755 plc-config root/usr/bin/plc-config
90 install -D -m 755 api-config root/usr/bin/api-config
91 install -D -m 755 db-config root/usr/bin/db-config
92 install -D -m 755 dns-config root/usr/bin/dns-config
93
94 # Install initscripts
95 echo "* myplc: Installing initscripts"
96 find plc.d | cpio -p -d -u root/etc/
97 install -D -m 755 guest.init root/etc/init.d/plc
98 chroot root sh -c 'chkconfig --add plc; chkconfig plc on'
99
100 # Install DB schema and API code
101 echo "* myplc: Installing DB schema and API code"
102 mkdir -p root/usr/share
103 rsync -a $srcdir/pl_db $srcdir/plc_api root/usr/share/
104
105 # Install web scripts
106 echo "* myplc: Installing web scripts"
107 mkdir -p root/usr/bin
108 install -m 755 \
109     $srcdir/plc/scripts/gen-sites-xml.py \
110     $srcdir/plc/scripts/gen-slices-xml-05.py \
111     $srcdir/plc/scripts/gen-static-content.py \
112     root/usr/bin/
113
114 # Install web pages
115 echo "* myplc: Installing web pages"
116 mkdir -p root/var/www/html
117 # Exclude old cruft, unrelated GENI pages, and official documents
118 rsync -a \
119     --exclude='*2002' --exclude='*2003' \
120     --exclude=geni --exclude=PDN --exclude=Talks \
121     $srcdir/plc_www/ root/var/www/html/
122
123 # Install configuration file
124 echo "* myplc: Installing configuration file"
125 install -D -m 444 $config data/etc/planetlab/default_config.xml
126 install -D -m 444 plc_config.dtd data/etc/planetlab/plc_config.dtd
127
128 # Move "data" directories out of the installation
129 datadirs=(
130 /etc/planetlab
131 /var/lib/pgsql
132 /var/www/html/alpina-logs
133 /var/www/html/boot
134 /var/www/html/download
135 /var/www/html/generated
136 /var/www/html/install-rpms
137 /var/www/html/xml
138 )
139
140 move_datadirs root data "${datadirs[@]}"
141
142 # Remove generated bootmanager script
143 rm -f data/var/www/html/boot/bootmanager.sh
144
145 # Initialize node RPMs directory. The PlanetLab-Bootstrap.tar.bz2
146 # tarball already contains all of the node RPMs pre-installed. Only
147 # updates or optional packages should be placed in this directory.
148 install -D -m 644 ../build/groups/v3_yumgroups.xml \
149     data/var/www/html/install-rpms/planetlab/yumgroups.xml
150
151 # Make image out of directory
152 echo "* myplc: Building loopback image"
153 make_image root root.img
154
155 exit 0