545d040bdc96a2a90f1bb33f3d489abc9dc1cb60
[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$
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 # These directories are allowed to grow to unspecified size, so they
79 # are stored as symlinks to the /data partition. mkfedora and yum
80 # expect some of them to be real directories, however.
81 datadirs=(
82 /etc/planetlab
83 /root
84 /var/lib/pgsql
85 /var/www/html/alpina-logs
86 /var/www/html/boot
87 /var/www/html/download
88 /var/www/html/generated
89 /var/www/html/install-rpms
90 /var/www/html/xml
91 /tmp
92 /usr/tmp
93 /var/tmp
94 /var/log
95 )
96 for datadir in "${datadirs[@]}" ; do
97     # If we are being re-run, it may be a symlink
98     rm -f root/$datadir || :
99     mkdir -p root/$datadir
100 done
101
102 echo "* myplc: Installing base filesystem"
103 mkdir -p root data
104 make_chroot root plc_config.xml
105
106 # Install configuration scripts
107 echo "* myplc: Installing configuration scripts"
108 install -D -m 755 plc_config.py root/tmp/plc_config.py
109 chroot root sh -c 'cd /tmp; python plc_config.py build; python plc_config.py install'
110 install -D -m 755 plc-config root/usr/bin/plc-config
111 install -D -m 755 plc-config-tty root/usr/bin/plc-config-tty
112 install -D -m 755 api-config root/usr/bin/api-config
113 install -D -m 755 db-config root/usr/bin/db-config
114 install -D -m 755 dns-config root/usr/bin/dns-config
115
116 # Install initscripts
117 echo "* myplc: Installing initscripts"
118 find plc.d | cpio -p -d -u root/etc/
119 install -D -m 755 guest.init root/etc/init.d/plc
120 chroot root sh -c 'chkconfig --add plc; chkconfig plc on'
121
122 # Install web scripts
123 echo "* myplc: Installing web scripts"
124 mkdir -p root/usr/bin
125 install -m 755 \
126     $srcdir/plc/scripts/gen-sites-xml.py \
127     $srcdir/plc/scripts/gen-slices-xml-05.py \
128     $srcdir/plc/scripts/gen-static-content.py \
129     root/usr/bin/
130
131 # Install web pages
132 echo "* myplc: Installing web pages"
133 mkdir -p root/var/www/html
134 # Exclude old cruft, unrelated GENI pages, and official documents
135 rsync -a $srcdir/new_plc_www/ root/var/www/html/
136
137 # Make the Drupal files upload directory owned by Apache
138 chown apache:apache root/var/www/html/files
139
140 # Install Drupal rewrite rules
141 install -D -m 644 $srcdir/new_plc_www/drupal.conf root/etc/httpd/conf.d/drupal.conf
142
143 # Install configuration file
144 echo "* myplc: Installing configuration file"
145 install -D -m 444 $config data/etc/planetlab/default_config.xml
146 install -D -m 444 plc_config.dtd data/etc/planetlab/plc_config.dtd
147
148 # handle root's homedir and tweak root prompt
149 echo "* myplc: root's homedir and prompt"
150 roothome=data/root
151 mkdir -p $roothome
152 cat << EOF > $roothome/.profile
153 export PS1="<plc> \$PS1"
154 EOF
155 chmod 644 $roothome/.profile
156
157 # Move "data" directories out of the installation
158 echo "* myplc: Moving data directories out of the installation"
159 move_datadirs root data "${datadirs[@]}"
160
161 # Fix permissions on tmp directories
162 chmod 1777 data/tmp data/usr/tmp data/var/tmp
163
164 # Remove generated bootmanager script
165 rm -f data/var/www/html/boot/bootmanager.sh
166
167 # Initialize node RPMs directory. The PlanetLab-Bootstrap.tar.bz2
168 # tarball already contains all of the node RPMs pre-installed. Only
169 # updates or optional packages should be placed in this directory.
170 install -D -m 644 ../build/groups/v3_yumgroups.xml \
171     data/var/www/html/install-rpms/planetlab/yumgroups.xml
172
173 # Make image out of directory
174 echo "* myplc: Building loopback image"
175 make_image root root.img
176
177 exit 0