- fix version number, bump release number, added changelog
[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 # data/root (root's homedir)
14 #
15 # Mark Huang <mlhuang@cs.princeton.edu>
16 # Copyright (C) 2006 The Trustees of Princeton University
17 #
18 # $Id: build.sh,v 1.33 2006/08/18 14:35:52 thierry Exp $
19 #
20
21 . build.functions
22
23 #
24 # Build myplc inside myplc-devel. Infinite recursion is avoided only
25 # if PLC_DEVEL_BOOTSTRAP is false in the default configuration file.
26 #
27
28 if [ "$PLC_DEVEL_BOOTSTRAP" = "true" ] ; then
29     # So that we don't pollute the actual myplc-devel image, we use
30     # the directory that was used to build the image instead of the
31     # image itself, and mount everything by hand.
32     mount -o bind,rw devel/data devel/root/data
33     mount -t proc none devel/root/proc
34
35     # If we used a local mirror, bind mount it into the chroot so that
36     # we can use it again.
37     if [ "${PLC_DEVEL_FEDORA_URL:0:7}" = "file://" ] ; then
38         mkdir -p devel/root/data/fedora
39         mount -o bind,ro ${PLC_DEVEL_FEDORA_URL#file://} devel/root/data/fedora
40     fi
41
42     # Clean up before exiting if anything goes wrong
43     trap "umount $PWD/devel/root/data/fedora;
44           umount $PWD/devel/root/data;
45           umount $PWD/devel/root/proc" ERR INT
46
47     # Build myplc inside myplc-devel. Make sure PLC_DEVEL_BOOTSTRAP is
48     # false to avoid infinite recursion.
49     chroot devel/root su - <<EOF
50 set -x
51 service plc start
52 plc-config --category=plc_devel --variable=bootstrap --value="false" --save
53 service plc reload
54 cd /
55 cvs -d /cvs checkout -r $BUILD_TAG build
56 make TAG=$BUILD_TAG -C /build myplc
57 EOF
58
59     # Yoink the image that was just built
60     mv devel/data/build/BUILD/myplc-*/myplc/root{,.img} devel/data/build/BUILD/myplc-*/myplc/data .
61
62     # Clean up
63     umount devel/root/data/fedora || :
64     umount devel/root/data
65     umount devel/root/proc
66     rm -rf devel/data/build
67     mkdir -p devel/data/build
68
69     # No need to continue
70     exit 0
71 fi
72
73 #
74 # Build myplc in the host environment. This section is executed if
75 # PLC_DEVEL_BOOTSTRAP is false.
76 #
77
78 echo "* myplc: Installing base filesystem"
79 mkdir -p root data
80 make_chroot root plc_config.xml
81
82 # Build schema
83 echo "* myplc: Building database schema"
84 make -C $srcdir/pl_db
85
86 # Install configuration scripts
87 echo "* myplc: Installing configuration scripts"
88 install -D -m 755 plc_config.py root/tmp/plc_config.py
89 chroot root sh -c 'cd /tmp; python plc_config.py build; python plc_config.py install'
90 install -D -m 755 plc-config root/usr/bin/plc-config
91 install -D -m 755 plc-config-tty root/usr/bin/plc-config-tty
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 # handle root's homedir and tweak root prompt
131 echo "* myplc: root's homedir and prompt"
132 roothome=data/root
133 mkdir -p $roothome
134 cat << EOF > $roothome/.profile
135 export PS1="<plc> \$PS1"
136 EOF
137 chmod 644 $roothome/.profile
138
139 # Move "data" directories out of the installation
140 echo "* myplc: Moving data directories out of the installation"
141 datadirs=(
142 /etc/planetlab
143 /root
144 /var/lib/pgsql
145 /var/www/html/alpina-logs
146 /var/www/html/boot
147 /var/www/html/download
148 /var/www/html/generated
149 /var/www/html/install-rpms
150 /var/www/html/xml
151 )
152
153 move_datadirs root data "${datadirs[@]}"
154
155 # Remove generated bootmanager script
156 rm -f data/var/www/html/boot/bootmanager.sh
157
158 # Initialize node RPMs directory. The PlanetLab-Bootstrap.tar.bz2
159 # tarball already contains all of the node RPMs pre-installed. Only
160 # updates or optional packages should be placed in this directory.
161 install -D -m 644 ../build/groups/v3_yumgroups.xml \
162     data/var/www/html/install-rpms/planetlab/yumgroups.xml
163
164 # Make image out of directory
165 echo "* myplc: Building loopback image"
166 make_image root root.img
167
168 exit 0