c05b1c6000c307f8b4ab363e1b4b0851aa33be9c
[myplc.git] / build.sh
1 #!/bin/bash
2 #
3 # Builds MyPLC in the current host environment
4 # This is for the so-called chroot installation mode, meaning that
5 # the resulting rpm will install a full chroot image in /plc/root
6 # that can be run through chroot /plc/root
7 # This chroot mode is to be opposed to the native mode (see build-native.sh)
8 # that can be used in the host's root context or within a vserver
9 #
10 # root.img (loopback image)
11 # root/ (mount point)
12 # data/ (various data files)
13 # data/etc/planetlab/ (configuration files)
14 # data/root (root's homedir)
15 #
16 # Mark Huang <mlhuang@cs.princeton.edu>
17 # Copyright (C) 2006 The Trustees of Princeton University
18 #
19 # $Id$
20 #
21
22 . build.functions
23
24 # pldistro expected as $1 - defaults to planetlab
25 pldistro=$1 ; shift
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 pl_root_makedevs root
54 pkgsfile=$(pl_locateDistroFile ../build/ ${pldistro} myplc.pkgs)
55 pl_root_mkfedora root $pldistro $pkgsfile
56 pl_root_tune_image root
57
58 # Install configuration scripts
59 echo "* myplc: Installing configuration scripts"
60 install -D -m 755 plc_config.py root/tmp/plc_config.py
61 chroot root sh -c 'cd /tmp; python plc_config.py build; python plc_config.py install'
62 install -D -m 755 plc-config root/usr/bin/plc-config
63 install -D -m 755 plc-config-tty root/usr/bin/plc-config-tty
64 install -D -m 755 db-config root/usr/bin/db-config
65 install -D -m 755 dns-config root/usr/bin/dns-config
66 install -D -m 755 plc-map.py root/usr/bin/plc-map.py
67 install -D -m 755 clean-empty-dirs.py root/usr/bin/clean-empty-dirs.py
68 install -D -m 755 mtail.py root/usr/bin/mtail.py
69 install -D -m 755 check-ssl-peering.py root/usr/bin/check-ssl-peering.py
70 # Extra scripts (mostly for mail and dns) not installed by myplc by default.  Used in production
71 mkdir root/etc/support-scripts
72 cp support-scripts/* root/etc/support-scripts 
73 # copy initscripts to etc/plc_sliceinitscripts
74 mkdir root/etc/plc_sliceinitscripts
75 cp plc_sliceinitscripts/* root/etc/plc_sliceinitscripts
76
77 # Install initscripts
78 echo "* myplc: Installing initscripts"
79 find plc.d | cpio -p -d -u root/etc/
80 install -D -m 755 guest.init root/etc/init.d/plc
81 chroot root sh -c 'chkconfig --add plc; chkconfig plc on'
82
83 # fetch the release stamp from the build if any
84 # I could not come up with any more sensitive scheme 
85 if [ -f ../../../myplc-release ] ; then
86   cp ../../../myplc-release myplc-release
87 else
88   echo "Cannot find release information." > myplc-release
89   date >> myplc-release
90   echo "$HeadURL$" >> myplc-release
91 fi
92 # install it in /etc/myplc-release 
93 install -m 444 myplc-release root/etc/myplc-release
94
95 ### Thierry Parmentelat - april 16 2007
96 # fix the yum.conf as produced by mkfedora
97 # so we can use the build's fc4 mirror for various installs/upgrades
98 # within the chroot jail
99 # yum_conf_to_build_host is defined in build.functions
100 yum_conf_to_build_host ../build > root/etc/yum.conf
101
102 ### Thierry Parmentelat - july 20 2007
103 # we now build the myplc doc
104 # beware that making the pdf file somehow overwrites the html
105 make -C doc myplc.pdf 
106 rm -f doc/myplc.html
107 make -C doc myplc.html 
108
109 # install at the same place as plcapi - better ideas ?
110 for doc in myplc.html myplc.pdf ; do
111     install -m 644 doc/$doc root/usr/share/plc_api/doc/$doc
112 done
113
114 # we now build the plcapi doc
115 # this generates a drupal php file from a docbook-generated html
116 # quick & dirty
117 docbook_html_to_drupal "${pldistro} PLCAPI Documentation" \
118     root/usr/share/plc_api/doc/PLCAPI.html \
119     root/var/www/html/planetlab/doc/plcapi.php
120 # pdf just get copied
121 install -m 644 root/usr/share/plc_api/doc/PLCAPI.pdf root/var/www/html/planetlab/doc/plcapi.pdf
122
123 docbook_html_to_drupal "Myplc User Guide" \
124     root/usr/share/plc_api/doc/myplc.html \
125     root/var/www/html/planetlab/doc/myplc.php
126 # pdf just get copied
127 install -m 644 root/usr/share/plc_api/doc/myplc.pdf root/var/www/html/planetlab/doc/myplc.pdf
128
129 # Install configuration file
130 echo "* myplc: Installing configuration file"
131 install -D -m 444 default_config.xml data/etc/planetlab/default_config.xml
132 install -D -m 444 plc_config.dtd data/etc/planetlab/plc_config.dtd
133
134 # handle root's homedir and tweak root prompt
135 echo "* myplc: root's homedir and prompt"
136 roothome=data/root
137 mkdir -p $roothome
138 cat << EOF > $roothome/.profile
139 export PS1="<plc> \$PS1"
140 EOF
141 chmod 644 $roothome/.profile
142
143 # Move "data" directories out of the installation
144 echo "* myplc: Moving data directories out of the installation"
145 pl_move_dirs root data /data "${datadirs[@]}"
146
147 # Fix permissions on tmp directories
148 pl_fixtmp_permissions data
149
150 # Remove generated bootmanager script
151 rm -f data/var/www/html/boot/bootmanager.sh
152
153 # Initialize node RPMs directory. The PlanetLab-Bootstrap.tar.bz2
154 # tarball already contains all of the node RPMs pre-installed. Only
155 # updates or optional packages should be placed in this directory.
156 nodefamily=${pldistro}-${pl_DISTRO_ARCH}
157 install -D -m 644 $pl_DISTRO_YUMGROUPS \
158     data/var/www/html/install-rpms/$nodefamily/yumgroups.xml
159 # temporary - so that node update still work until yum.conf.php gets fixed
160 ( cd data/var/www/html/install-rpms ; ln -s $nodefamily planetlab)
161
162 # Make image out of directory
163 echo "* myplc: Building loopback image"
164 pl_make_image root root.img 100000000
165
166 exit 0