X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=build.sh;h=3352f1f222c984def6d01f575e019e3f03e6264f;hb=391310e122de0536c08f62bd46acd3b3b7b13964;hp=cfa47ca1ff457a78cc0feb90d0d20c8931dddb7e;hpb=4f2c4db0bdee8e3260693bfa30a2159fe8f5865e;p=myplc.git diff --git a/build.sh b/build.sh index cfa47ca..3352f1f 100755 --- a/build.sh +++ b/build.sh @@ -1,244 +1,180 @@ #!/bin/bash # -# Builds a Fedora based PLC image. You should be able to run this -# script multiple times without a problem. +# Builds MyPLC, either inside the MyPLC development environment in +# devel/root (if PLC_DEVEL_BOOTSTRAP is true), or in the current host +# environment (may be itself a MyPLC development environment or a +# Fedora Core 4 environment with the appropriate development packages +# installed). +# +# root.img (loopback image) +# root/ (mount point) +# data/ (various data files) +# data/etc/planetlab/ (configuration files) +# data/root (root's homedir) # # Mark Huang # Copyright (C) 2006 The Trustees of Princeton University # -# $Id: build.sh,v 1.2 2006/03/27 18:08:06 mlhuang Exp $ +# $Id: build.sh 1095 2007-11-16 09:52:30Z thierry $ # -PATH=/sbin:/bin:/usr/sbin:/usr/bin - -# In a normal CVS environment, the requisite CVS modules (including -# build/) are located at the same level we are. In a PlanetLab RPM -# build environment (see the RPM spec file), they are checked out into -# a subdirectory. -if [ -d ./build ] ; then - PATH=$PATH:./build - srcdir=. -elif [ -d ../build ] ; then - PATH=$PATH:../build - srcdir=.. -else - echo "Error: Could not find sources in either . or .." - exit 1 -fi - -export PATH - -# PLC configuration file -config=plc_config.xml - -# Release and architecture to install -releasever=2 -basearch=i386 - -# Data directory base -usr_share=/usr/share - -# Initial size of the image -size=1000000000 - -usage() -{ - echo "Usage: build.sh [OPTION]..." - echo " -c file PLC configuration file (default: $config)" - echo " -r release Fedora release number (default: $releasever)" - echo " -a arch Fedora architecture (default: $basearch)" - echo " -d datadir Data directory base (default: $usr_share)" - echo " -s size Approximate size of the installation (default: $size)" - echo " -h This message" - exit 1 -} - -# Get options -while getopts "c:r:a:d:s:h" opt ; do - case $opt in - c) - config=$OPTARG - ;; - r) - releasever=$OPTARG - ;; - a) - basearch=$OPTARG - ;; - d) - usr_share=$OPTARG - ;; - s) - size=$OPTARG - ;; - h|*) - usage - ;; - esac -done - -root=fc$releasever -data=data$releasever - -if [ ! -f $root.img ] ; then - bs=4096 - count=$(($size / 4096)) - dd bs=$bs count=$count if=/dev/zero of=$root.img - mkfs.ext3 -j -F $root.img -fi - -mkdir -p $root $data -mount -o loop $root.img $root -trap "umount $root; exit 1" ERR - -# -# Build -# - -# Get package list -while read package ; do - packages="$packages -p $package" -done < <(./plc-config --packages $config) - -# Install base system -mkfedora -v -r $releasever -a $basearch $packages $root - -# FC2 minilogd starts up during shutdown and makes unmounting -# impossible. Just get rid of it. -rm -f $root/sbin/minilogd -ln -nsf /bin/true $root/sbin/minilogd - -# Build schema -make -C $srcdir/pl_db - -# -# Install -# - -# Install configuration scripts -install -D -m 755 plc_config.py $root/tmp/plc_config.py -chroot $root sh -c 'cd /tmp; python plc_config.py build; python plc_config.py install' -install -D -m 755 plc-config $root/usr/bin/plc-config -install -D -m 755 api-config $root/usr/bin/api-config +. build.functions -# Install init script -install -D -m 755 guest.init $root/etc/init.d/plc -chroot $root sh -c 'chkconfig --add plc; chkconfig plc on' +# pldistro expected as $1 - defaults to planetlab +pldistro=planetlab +[ -n "$@" ] && pldistro=$1 -# Install DB schema and API code -mkdir -p $root/usr/share -rsync -a $srcdir/pl_db $srcdir/plc_api $root/usr/share/ - -# Install web scripts -mkdir -p $root/usr/bin -install -m 755 \ - $srcdir/plc/scripts/gen-sites-xml.py \ - $srcdir/plc/scripts/gen-slices-xml-05.py \ - $srcdir/plc/scripts/gen-static-content.py \ - $root/usr/bin/ - -# Install web pages -mkdir -p $root/var/www/html -rsync -a $srcdir/plc_www/ $root/var/www/html/ - -# Install node RPMs -if [ -n "$RPM_BUILD_DIR" ] ; then - RPM_RPMS_DIR=$(cd $(dirname $RPM_BUILD_DIR)/RPMS && pwd -P) - mkdir -p $root/var/www/html/install-rpms/planetlab - find $RPM_RPMS_DIR -type f -and -not -name '*-debuginfo-*' | \ - cpio -p -d -u $root/var/www/html/install-rpms/planetlab/ - yum-arch $root/var/www/html/install-rpms/planetlab || : - createrepo $root/var/www/html/install-rpms/planetlab || : -fi - -# XXX Build imprintable BootCD and BootManager images. - -# Install configuration file -install -D -m 644 $config $data/etc/planetlab/plc_config.xml - -# Move "data" directories out of the installation +# These directories are allowed to grow to unspecified size, so they +# are stored as symlinks to the /data partition. mkfedora and yum +# expect some of them to be real directories, however. datadirs=( /etc/planetlab +/root /var/lib/pgsql /var/www/html/alpina-logs /var/www/html/boot /var/www/html/download +/var/www/html/files +/var/www/html/sites /var/www/html/generated /var/www/html/install-rpms /var/www/html/xml +/tmp +/usr/tmp +/var/tmp +/var/log ) -mkdir -p $root/data -for datadir in "${datadirs[@]}" ; do - mkdir -p ${data}$datadir - if [ -d $root/$datadir -a ! -h $root/$datadir ] ; then - (cd $root && find ./$datadir | cpio -p -d -u ../$data/) - fi - rm -rf $root/$datadir - mkdir -p $(dirname $root/$datadir) - ln -nsf /data$datadir $root/$datadir -done +pl_fixdirs root "${datadirs[@]}" -# Shrink to 100 MB free space -kb=$(python < target: - print (df.f_blocks - (df.f_bavail - target)) * df.f_bsize / 1024 -EOF -) +echo "* myplc: Installing base filesystem" +mkdir -p root data + +lst=${pldistro}-${pl_DISTRO_NAME}-plc.lst +make_chroot_from_lst root $lst -umount $root -trap - ERR - -if [ -n "$kb" ] ; then - # Setup loopback association. Newer versions of losetup have a -f - # option which finds an unused loopback device, but we must - # support FC2 for now. - # dev_loop=$(losetup -f) - for i in `seq 1 7` ; do - if ! grep -q "^/dev/loop$i" /proc/mounts ; then - dev_loop="/dev/loop$i" - break - fi - done - losetup $dev_loop $root.img - trap "losetup -d $dev_loop" ERR - - # Resize the filesystem - e2fsck -f $dev_loop - resize2fs $dev_loop ${kb}K - - # Tear down loopback association - losetup -d $dev_loop - trap - ERR - - # Truncate the image file - perl -e "truncate '$root.img', $kb*1024" +# Install configuration scripts +echo "* myplc: Installing configuration scripts" +install -D -m 755 plc_config.py root/tmp/plc_config.py +chroot root sh -c 'cd /tmp; python plc_config.py build; python plc_config.py install' +install -D -m 755 plc-config root/usr/bin/plc-config +install -D -m 755 plc-config-tty root/usr/bin/plc-config-tty +install -D -m 755 db-config root/usr/bin/db-config +install -D -m 755 dns-config root/usr/bin/dns-config +install -D -m 755 plc-map.py root/usr/bin/plc-map.py +install -D -m 755 clean-empty-dirs.py root/usr/bin/clean-empty-dirs.py +install -D -m 755 mtail.py root/usr/bin/mtail.py +install -D -m 755 check-ssl-peering.py root/usr/bin/check-ssl-peering.py + +# Install initscripts +echo "* myplc: Installing initscripts" +find plc.d | cpio -p -d -u root/etc/ +install -D -m 755 guest.init root/etc/init.d/plc +chroot root sh -c 'chkconfig --add plc; chkconfig plc on' + +# Install web scripts +#echo "* myplc: Installing web scripts" +#mkdir -p root/usr/bin +#install -m 755 \ + #$srcdir/plc/scripts/gen-sites-xml.py \ + #$srcdir/plc/scripts/gen-slices-xml-05.py \ + #$srcdir/plc/scripts/gen-static-content.py \ + #root/usr/bin/ + +### Thierry Parmentelat - april 16 2007 +### from now on we package plcwww separately in the plcwww rpm +#### Install web pages +###echo "* myplc: Installing web pages" +###mkdir -p root/var/www/html +###rsync -a $srcdir/new_plc_www/ root/var/www/html/ + +#### Install Drupal rewrite rules +###install -D -m 644 $srcdir/new_plc_www/drupal.conf root/etc/httpd/conf.d/drupal.conf + +### Thierry Parmentelat - april 16 2007 +# fetch the release stamp from the build if any +# I could not come up with any more sensitive scheme +if [ -f ../../../SOURCES/myplc-release ] ; then + cp ../../../SOURCES/myplc-release myplc-release +else + echo "No build information found in ../.." > myplc-release fi +# install it in /etc/myplc-release +install -m 444 myplc-release root/etc/myplc-release + +### Thierry Parmentelat - april 16 2007 +# fix the yum.conf as produced by mkfedora +# so we can use the build's fc4 mirror for various installs/upgrades +# within the chroot jail +# yum_conf_to_build_host is defined in build.functions +yum_conf_to_build_host > root/etc/yum.conf + +### Thierry Parmentelat - may 16 2007 +# the node-dependent image generation script requires root privilege +# to perform various mount operations +sudoers_bootcustom_apache > root/etc/sudoers +chown root:root root/etc/sudoers +chmod 400 root/etc/sudoers + +### Thierry Parmentelat - july 20 2007 +# we now build the myplc doc +# beware that making the pdf file somehow overwrites the html +make -C doc myplc.pdf +rm -f doc/myplc.html +make -C doc myplc.html + +# install at the same place as plcapi - better ideas ? +for doc in myplc.html myplc.pdf ; do + install -m 644 doc/$doc root/usr/share/plc_api/doc/$doc +done + +# we now build the plcapi doc +# this generates a drupal php file from a docbook-generated html +# quick & dirty +docbook_html_to_drupal "OneLab PLCAPI Documentation" \ + root/usr/share/plc_api/doc/PLCAPI.html \ + root/var/www/html/planetlab/doc/plcapi.php +# pdf just get copied +install -m 644 root/usr/share/plc_api/doc/PLCAPI.pdf root/var/www/html/planetlab/doc/plcapi.pdf + +docbook_html_to_drupal "Myplc User Guide" \ + root/usr/share/plc_api/doc/myplc.html \ + root/var/www/html/planetlab/doc/myplc.php +# pdf just get copied +install -m 644 root/usr/share/plc_api/doc/myplc.pdf root/var/www/html/planetlab/doc/myplc.pdf -# Write sysconfig -cat >plc.sysconfig < $roothome/.profile +export PS1=" \$PS1" EOF +chmod 644 $roothome/.profile -# Bootstrap the system. Configure the web server to run on an -# alternate port (in case the build machine is running a web server), -# start everything up, then shut it back down again. -./plc-config --save $data/etc/planetlab/plc_config.xml bootstrap.xml +# Move "data" directories out of the installation +echo "* myplc: Moving data directories out of the installation" +pl_move_dirs root data /data "${datadirs[@]}" -export PLC_ROOT=$PWD/$root -export PLC_DATA=$PWD/$data +# Fix permissions on tmp directories +pl_fixtmp_permissions data -./host.init start -RETVAL=$? +# Remove generated bootmanager script +rm -f data/var/www/html/boot/bootmanager.sh -# Restore default configuration before shutting down -install -D -m 644 $config $data/etc/planetlab/plc_config.xml +# Initialize node RPMs directory. The PlanetLab-Bootstrap.tar.bz2 +# tarball already contains all of the node RPMs pre-installed. Only +# updates or optional packages should be placed in this directory. +install -D -m 644 $pl_DISTRO_YUMGROUPS \ + data/var/www/html/install-rpms/planetlab/yumgroups.xml -./host.init stop +# Make image out of directory +echo "* myplc: Building loopback image" +pl_make_image root root.img 100000000 -exit $RETVAL +exit 0