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