fix needed
[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 # pldistro expected as $1 - defaults to planetlab
24 pldistro=planetlab
25 [ -n "$@" ] && pldistro=$1
26
27 # These directories are allowed to grow to unspecified size, so they
28 # are stored as symlinks to the /data partition. mkfedora and yum
29 # expect some of them to be real directories, however.
30 datadirs=(
31 /etc/planetlab
32 /root
33 /var/lib/pgsql
34 /var/www/html/alpina-logs
35 /var/www/html/boot
36 /var/www/html/download
37 /var/www/html/files
38 /var/www/html/sites
39 /var/www/html/generated
40 /var/www/html/install-rpms
41 /var/www/html/xml
42 /tmp
43 /usr/tmp
44 /var/tmp
45 /var/log
46 )
47
48 pl_fixdirs root "${datadirs[@]}"
49
50 echo "* myplc: Installing base filesystem"
51 mkdir -p root data
52
53 lst=${pldistro}-plc.lst
54 make_chroot_from_lst root ${pl_DISTRO_NAME} $lst
55
56 # Install configuration scripts
57 echo "* myplc: Installing configuration scripts"
58 install -D -m 755 plc_config.py root/tmp/plc_config.py
59 chroot root sh -c 'cd /tmp; python plc_config.py build; python plc_config.py install'
60 install -D -m 755 plc-config root/usr/bin/plc-config
61 install -D -m 755 plc-config-tty root/usr/bin/plc-config-tty
62 install -D -m 755 db-config root/usr/bin/db-config
63 install -D -m 755 dns-config root/usr/bin/dns-config
64 install -D -m 755 plc-map.py root/usr/bin/plc-map.py
65 install -D -m 755 clean-empty-dirs.py root/usr/bin/clean-empty-dirs.py
66 install -D -m 755 mtail.py root/usr/bin/mtail.py
67 install -D -m 755 check-ssl-peering.py root/usr/bin/check-ssl-peering.py
68
69 # Install initscripts
70 echo "* myplc: Installing initscripts"
71 find plc.d | cpio -p -d -u root/etc/
72 install -D -m 755 guest.init root/etc/init.d/plc
73 chroot root sh -c 'chkconfig --add plc; chkconfig plc on'
74
75 # Install web scripts
76 #echo "* myplc: Installing web scripts"
77 #mkdir -p root/usr/bin
78 #install -m 755 \
79     #$srcdir/plc/scripts/gen-sites-xml.py \
80     #$srcdir/plc/scripts/gen-slices-xml-05.py \
81     #$srcdir/plc/scripts/gen-static-content.py \
82     #root/usr/bin/
83
84 ### Thierry Parmentelat - april 16 2007
85 ### from now on we package plcwww separately in the plcwww rpm
86 #### Install web pages
87 ###echo "* myplc: Installing web pages"
88 ###mkdir -p root/var/www/html
89 ###rsync -a $srcdir/new_plc_www/ root/var/www/html/
90
91 #### Install Drupal rewrite rules
92 ###install -D -m 644 $srcdir/new_plc_www/drupal.conf root/etc/httpd/conf.d/drupal.conf
93
94 ### Thierry Parmentelat - april 16 2007
95 # fetch the release stamp from the build if any
96 # I could not come up with any more sensitive scheme 
97 if [ -f ../../../SOURCES/myplc-release ] ; then
98   cp ../../../SOURCES/myplc-release myplc-release
99 else
100   echo "No build information found in ../.." > myplc-release
101 fi
102 # install it in /etc/myplc-release 
103 install -m 444 myplc-release root/etc/myplc-release
104
105 ### Thierry Parmentelat - april 16 2007
106 # fix the yum.conf as produced by mkfedora
107 # so we can use the build's fc4 mirror for various installs/upgrades
108 # within the chroot jail
109 # yum_conf_to_build_host is defined in build.functions
110 yum_conf_to_build_host > root/etc/yum.conf
111
112 ### Thierry Parmentelat - may 16 2007
113 # the node-dependent image generation script requires root privilege
114 # to perform various mount operations
115 sudoers_bootcustom_apache > root/etc/sudoers
116 chown root:root root/etc/sudoers
117 chmod 400 root/etc/sudoers
118
119 ### Thierry Parmentelat - july 20 2007
120 # we now build the myplc doc
121 # beware that making the pdf file somehow overwrites the html
122 make -C doc myplc.pdf 
123 rm -f doc/myplc.html
124 make -C doc myplc.html 
125
126 # install at the same place as plcapi - better ideas ?
127 for doc in myplc.html myplc.pdf ; do
128     install -m 644 doc/$doc root/usr/share/plc_api/doc/$doc
129 done
130
131 # we now build the plcapi doc
132 # this generates a drupal php file from a docbook-generated html
133 # quick & dirty
134 docbook_html_to_drupal "OneLab PLCAPI Documentation" \
135     root/usr/share/plc_api/doc/PLCAPI.html \
136     root/var/www/html/planetlab/doc/plcapi.php
137 # pdf just get copied
138 install -m 644 root/usr/share/plc_api/doc/PLCAPI.pdf root/var/www/html/planetlab/doc/plcapi.pdf
139
140 docbook_html_to_drupal "Myplc User Guide" \
141     root/usr/share/plc_api/doc/myplc.html \
142     root/var/www/html/planetlab/doc/myplc.php
143 # pdf just get copied
144 install -m 644 root/usr/share/plc_api/doc/myplc.pdf root/var/www/html/planetlab/doc/myplc.pdf
145
146 # Install configuration file
147 echo "* myplc: Installing configuration file"
148 install -D -m 444 default_config.xml data/etc/planetlab/default_config.xml
149 install -D -m 444 plc_config.dtd data/etc/planetlab/plc_config.dtd
150
151 # handle root's homedir and tweak root prompt
152 echo "* myplc: root's homedir and prompt"
153 roothome=data/root
154 mkdir -p $roothome
155 cat << EOF > $roothome/.profile
156 export PS1="<plc> \$PS1"
157 EOF
158 chmod 644 $roothome/.profile
159
160 # Move "data" directories out of the installation
161 echo "* myplc: Moving data directories out of the installation"
162 pl_move_dirs root data /data "${datadirs[@]}"
163
164 # Fix permissions on tmp directories
165 pl_fixtmp_permissions data
166
167 # Remove generated bootmanager script
168 rm -f data/var/www/html/boot/bootmanager.sh
169
170 # Initialize node RPMs directory. The PlanetLab-Bootstrap.tar.bz2
171 # tarball already contains all of the node RPMs pre-installed. Only
172 # updates or optional packages should be placed in this directory.
173 install -D -m 644 $pl_DISTRO_YUMGROUPS \
174     data/var/www/html/install-rpms/planetlab/yumgroups.xml
175
176 # Make image out of directory
177 echo "* myplc: Building loopback image"
178 pl_make_image root root.img 100000000
179
180 exit 0