- no need to always_update blacklist or sysctl.conf
[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     if [ -h root/$datadir ] ; then
99         rm -f root/$datadir
100         mkdir -p root/$datadir
101     fi
102 done
103
104 echo "* myplc: Installing base filesystem"
105 mkdir -p root data
106 make_chroot root plc_config.xml
107
108 # Install configuration scripts
109 echo "* myplc: Installing configuration scripts"
110 install -D -m 755 plc_config.py root/tmp/plc_config.py
111 chroot root sh -c 'cd /tmp; python plc_config.py build; python plc_config.py install'
112 install -D -m 755 plc-config root/usr/bin/plc-config
113 install -D -m 755 plc-config-tty root/usr/bin/plc-config-tty
114 install -D -m 755 api-config root/usr/bin/api-config
115 install -D -m 755 db-config root/usr/bin/db-config
116 install -D -m 755 dns-config root/usr/bin/dns-config
117
118 # Install initscripts
119 echo "* myplc: Installing initscripts"
120 find plc.d | cpio -p -d -u root/etc/
121 install -D -m 755 guest.init root/etc/init.d/plc
122 chroot root sh -c 'chkconfig --add plc; chkconfig plc on'
123
124 # Install web scripts
125 echo "* myplc: Installing web scripts"
126 mkdir -p root/usr/bin
127 install -m 755 \
128     $srcdir/plc/scripts/gen-sites-xml.py \
129     $srcdir/plc/scripts/gen-slices-xml-05.py \
130     $srcdir/plc/scripts/gen-static-content.py \
131     root/usr/bin/
132
133 # Install web pages
134 echo "* myplc: Installing web pages"
135 mkdir -p root/var/www/html
136 rsync -a $srcdir/new_plc_www/ root/var/www/html/
137
138 # Install Drupal rewrite rules
139 install -D -m 644 $srcdir/new_plc_www/drupal.conf root/etc/httpd/conf.d/drupal.conf
140
141 # Install configuration file
142 echo "* myplc: Installing configuration file"
143 install -D -m 444 $config data/etc/planetlab/default_config.xml
144 install -D -m 444 plc_config.dtd data/etc/planetlab/plc_config.dtd
145
146 # handle root's homedir and tweak root prompt
147 echo "* myplc: root's homedir and prompt"
148 roothome=data/root
149 mkdir -p $roothome
150 cat << EOF > $roothome/.profile
151 export PS1="<plc> \$PS1"
152 EOF
153 chmod 644 $roothome/.profile
154
155 # Move "data" directories out of the installation
156 echo "* myplc: Moving data directories out of the installation"
157 move_datadirs root data "${datadirs[@]}"
158
159 # Fix permissions on tmp directories
160 chmod 1777 data/tmp data/usr/tmp data/var/tmp
161
162 # Remove generated bootmanager script
163 rm -f data/var/www/html/boot/bootmanager.sh
164
165 # Initialize node RPMs directory. The PlanetLab-Bootstrap.tar.bz2
166 # tarball already contains all of the node RPMs pre-installed. Only
167 # updates or optional packages should be placed in this directory.
168 install -D -m 644 ../build/groups/v3_yumgroups.xml \
169     data/var/www/html/install-rpms/planetlab/yumgroups.xml
170
171 # Make image out of directory
172 echo "* myplc: Building loopback image"
173 make_image root root.img
174
175 exit 0