From 1dc466186b2ba51649ffc000429fe9496ca467bb Mon Sep 17 00:00:00 2001 From: Mark Huang Date: Mon, 17 Jul 2006 21:31:31 +0000 Subject: [PATCH] - split build.sh into two pieces: build_devel.sh, which builds myplc-devel, and build.sh, which builds myplc itself (optionally inside of the myplc-devel environment just built) - add plc_devel_config.xml, the configuration for myplc-devel --- build.functions | 151 ++++++++++++++++++++++ build.sh | 302 ++++++++++++++----------------------------- build_devel.sh | 76 +++++++++++ myplc.spec | 151 +++++++++++++++++++++- plc_devel_config.xml | 153 ++++++++++++++++++++++ 5 files changed, 623 insertions(+), 210 deletions(-) create mode 100644 build.functions create mode 100755 build_devel.sh create mode 100644 plc_devel_config.xml diff --git a/build.functions b/build.functions new file mode 100644 index 0000000..8281801 --- /dev/null +++ b/build.functions @@ -0,0 +1,151 @@ +# -*-Shell-script-*- +# +# Common functions for MyPLC build scripts (build_devel.sh and +# build.sh) +# +# Mark Huang +# Copyright (C) 2006 The Trustees of Princeton University +# +# $Id: functions,v 1.6 2006/07/10 21:05:37 mlhuang Exp $ +# + +PATH=/sbin:/bin:/usr/sbin:/usr/bin + +# In both a normal CVS environment and a PlanetLab RPM +# build environment, all of our dependencies are checked out into +# directories at the same level as us. +if [ -d ../build ] ; then + PATH=$PATH:../build + srcdir=.. +else + echo "Error: Could not find $(cd .. && pwd -P)/build/" + exit 1 +fi + +export PATH + +# Release and architecture to install +PLC_DEVEL_FEDORA_RELEASE=4 +PLC_DEVEL_FEDORA_ARCH=i386 + +# Fedora Core mirror from which to install filesystems +PLC_DEVEL_FEDORA_URL=file:///usr/share/mirrors/fedora + +# Build myplc inside myplc-devel +PLC_DEVEL_BOOTSTRAP=true + +# We may be running inside a myplc-devel environment, which can +# override these defaults. Specifically, whether to build myplc inside +# myplc-devel (PLC_DEVEL_BOOTSTRAP). +if [ -f /etc/planetlab/plc_config ] ; then + . /etc/planetlab/plc_config +fi + +usage() +{ + echo "Usage: build.sh [OPTION]..." + echo " -l url Fedora mirror location (default: $PLC_DEVEL_FEDORA_URL)" + echo " -r release Fedora release number (default: $PLC_DEVEL_FEDORA_RELEASE)" + echo " -a arch Fedora architecture (default: $PLC_DEVEL_FEDORA_ARCH)" + echo " -h This message" + exit 1 +} + +# Get options +while getopts "l:r:a:h" opt ; do + case $opt in + l) + PLC_DEVEL_FEDORA_URL=$OPTARG + ;; + r) + PLC_DEVEL_FEDORA_RELEASE=$OPTARG + ;; + a) + PLC_DEVEL_FEDORA_ARCH=$OPTARG + ;; + h|*) + usage + ;; + esac +done + +# Do not tolerate errors +set -e + +# Be verbose +set -x + +# Make a basic chroot at the specified location given the specified +# configuration. +make_chroot() { + root=$1 + config=$2 + + # Get group list + groups= + while read group ; do + groups="$groups -g \"$group\"" + done < <(./plc-config --groups $config) + + # Get package list + packages= + while read package ; do + packages="$packages -p \"$package\"" + done < <(./plc-config --packages $config) + + # Install base system + eval mkfedora -v -l $PLC_DEVEL_FEDORA_URL -r $PLC_DEVEL_FEDORA_RELEASE -a $PLC_DEVEL_FEDORA_ARCH $packages $groups $root + + # Disable all services in reference image + chroot $root sh -c "/sbin/chkconfig --list | awk '{ print \$1 }' | xargs -i /sbin/chkconfig {} off" + + # 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 +} + +# Move specified directories out of the chroot and into a "data" +# directory that will be bind mounted on /data inside the chroot. +move_datadirs() { + root=$1 + data=$2 + shift 2 + + mkdir -p $root/data + for datadir in "$@" ; 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 +} + +# Make loopback filesystem from specified location +make_image() { + root=$1 + image=$2 + + # Leave about 100 MB free space and allow for about 20% inode overhead + bytes=$((($(du -sb $root | cut -f1) + 100000000) * 120 / 100)) + bs=4096 + blocks=$(($bytes / $bs)) + dd bs=$bs count=$blocks if=/dev/zero of=$image + mkfs.ext3 -b $bs -j -F $image + + # Temporarily mount it + tmp=$(mktemp -d tmp.XXXXXX) + mount -o loop $image $tmp + trap "umount $tmp; rmdir $tmp" ERR INT + + # Move files to it + (cd $root && tar cpf - .) | (cd $tmp && tar xpf -) + + # Unmount it + umount $tmp + rmdir $tmp + trap - ERR INT +} diff --git a/build.sh b/build.sh index 6d3733b..35cecab 100755 --- a/build.sh +++ b/build.sh @@ -1,7 +1,15 @@ #!/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) # # Mark Huang # Copyright (C) 2006 The Trustees of Princeton University @@ -9,152 +17,115 @@ # $Id$ # -PATH=/sbin:/bin:/usr/sbin:/usr/bin - -# In both a normal CVS environment and a PlanetLab RPM -# build environment, all of our dependencies are checked out into -# directories at the same level as us. -if [ -d ../build ] ; then - PATH=$PATH:../build - srcdir=.. -else - echo "Error: Could not find $(cd .. && pwd -P)/build/" - exit 1 -fi - -export PATH - -# PLC configuration file -config=plc_config.xml +. build.functions -# Release and architecture to install -releasever=4 -basearch=i386 +# +# Build myplc inside myplc-devel. Infinite recursion is avoided only +# if PLC_DEVEL_BOOTSTRAP is false in the default configuration file. +# -# Initial size of the image -size=1000000000 +if [ "$PLC_DEVEL_BOOTSTRAP" = "true" ] ; then + # So that we don't pollute the actual myplc-devel image, we use + # the directory that was used to build the image instead of the + # image itself, and mount everything by hand. + mount -o bind,rw devel/data devel/root/data + mount -t proc none devel/root/proc + + # If we used a local mirror, bind mount it into the chroot so that + # we can use it again. + if [ "${PLC_DEVEL_FEDORA_URL:0:7}" = "file://" ] ; then + mkdir -p devel/root/usr/share/mirrors/fedora + mount -o bind,ro ${PLC_DEVEL_FEDORA_URL#file://} devel/root/usr/share/mirrors/fedora + fi -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 " -s size Approximate size of the installation (default: $size)" - echo " -h This message" - exit 1 -} + # Clean up before exiting if anything goes wrong + trap "umount $PWD/devel/root/data; + umount $PWD/devel/root/proc; + umount $PWD/devel/root/usr/share/mirrors/fedora" ERR INT + + # Build myplc inside myplc-devel. Make sure PLC_DEVEL_BOOTSTRAP is + # false to avoid infinite recursion. + chroot devel/root sh -s < target: - print (df.f_blocks - (df.f_bavail - target)) * df.f_bsize / 1024 -EOF -) - -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 - echo "* Checking filesystem" - e2fsck -a -f $dev_loop - echo "* Shrinking filesystem" - 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" -fi - -# Write sysconfig -cat >plc.sysconfig <100MB but only take a -# couple of seconds to generate at first boot. -rm -f $data/var/www/html/download/*.{iso,usb} - -./host.init stop -RETVAL=$(($RETVAL+$?)) - -# Restore default configuration -rm -f $data/etc/planetlab/configs/bootstrap.xml -install -D -m 444 $config $data/etc/planetlab/plc_config.xml +# Make image out of directory +echo "* myplc: Building loopback image" +make_image root root.img -exit $RETVAL +exit 0 diff --git a/build_devel.sh b/build_devel.sh new file mode 100755 index 0000000..77893b3 --- /dev/null +++ b/build_devel.sh @@ -0,0 +1,76 @@ +#!/bin/bash +# +# Build a complete MyPLC development environment. Requires PlanetLab +# source code to be exported into directories at the same level as we +# are (i.e., ..). +# +# devel/root.img (loopback image) +# devel/root/ (mount point) +# devel/data/ (various data files) +# devel/data/cvs/ (local CVS repository) +# devel/data/build/ (build area) +# devel/data/etc/planetlab/ (configuration) +# +# Mark Huang +# Copyright (C) 2006 The Trustees of Princeton University +# +# $Id$ +# + +. build.functions + +echo "* myplc-devel: Installing base filesystem" +mkdir -p devel/root +make_chroot devel/root plc_devel_config.xml + +# Import everything (including ourself) into a private CVS tree +echo "* myplc-devel: Building CVS repository" +cvsroot=$PWD/devel/data/cvs +mkdir -p $cvsroot +cvs -d $cvsroot init + +myplc=$(basename $PWD) +pushd .. +for dir in * ; do + if [ ! -d $cvsroot/$dir ] ; then + pushd $dir + if [ "$dir" = "$myplc" ] ; then + # Ignore generated files + ignore="-I ! -I devel -I root -I root.img -I data" + else + ignore="-I !" + fi + date=$(date +%Y-%m-%d) + cvs -d $cvsroot import -m "Initial import" -ko $ignore $dir planetlab planetlab-$date + popd + fi +done +popd + +# Install configuration file +echo "* myplc-devel: Installing configuration file" +install -D -m 444 plc_devel_config.xml devel/data/etc/planetlab/default_config.xml +install -D -m 444 plc_config.dtd devel/data/etc/planetlab/plc_config.dtd + +# Install configuration scripts +echo "* myplc-devel: Installing configuration scripts" +install -D -m 755 plc_config.py devel/root/tmp/plc_config.py +chroot devel/root sh -c 'cd /tmp; python plc_config.py build; python plc_config.py install' +install -D -m 755 plc-config devel/root/usr/bin/plc-config + +# Install initscripts +echo "* myplc-devel: Installing initscripts" +find plc.d/functions | cpio -p -d -u devel/root/etc/ +install -D -m 755 guest.init devel/root/etc/init.d/plc +chroot devel/root sh -c 'chkconfig --add plc; chkconfig plc on' + +# Move "data" directories out of the installation +echo "* myplc-devel: Moving data directories out of the installation" +move_datadirs devel/root devel/data \ + /etc/planetlab /build /cvs + +# Make image out of directory +echo "* myplc-devel: Building loopback image" +make_image devel/root devel/root.img + +exit 0 diff --git a/myplc.spec b/myplc.spec index 0a6a188..29a8960 100644 --- a/myplc.spec +++ b/myplc.spec @@ -6,7 +6,7 @@ URL: http://cvs.planet-lab.org/cvs/myplc Summary: PlanetLab Central (PLC) Portable Installation Name: myplc Version: 0.5 -Release: 1%{?pldistro:.%{pldistro}}%{?date:.%{date}} +Release: 2%{?pldistro:.%{pldistro}}%{?date:.%{date}} License: PlanetLab Group: Applications/Systems Source0: %{name}-%{version}.tar.gz @@ -23,12 +23,24 @@ through a graphical interface. All PLC services are started up and shut down through a single System V init script installed in the host system. +%package devel +Summary: PlanetLab Central (PLC) Development Environment +Group: Development/Tools +AutoReqProv: no + +%description devel +This package install a complete PlanetLab development environment +contained within a chroot jail. The default installation consists of a +local CVS repository bootstrapped with a snapshot of all PlanetLab +source code, and all the tools necessary to compile it. + %prep %setup -q %build pushd myplc -./build.sh +#./build_devel.sh +#./build.sh popd %install @@ -36,6 +48,10 @@ rm -rf $RPM_BUILD_ROOT pushd myplc +# +# myplc +# + # Install host startup script and configuration file install -D -m 755 host.init $RPM_BUILD_ROOT/%{_sysconfdir}/init.d/plc install -D -m 644 plc.sysconfig $RPM_BUILD_ROOT/%{_sysconfdir}/sysconfig/plc @@ -51,6 +67,21 @@ install -D -m 644 root.img $RPM_BUILD_ROOT/plc/root.img # Install data directory find data | cpio -p -d -u $RPM_BUILD_ROOT/plc/ +# +# myplc-devel +# + +# Install host startup script and configuration file +install -D -m 755 host.init $RPM_BUILD_ROOT/%{_sysconfdir}/init.d/plc-devel +install -D -m 644 plc-devel.sysconfig $RPM_BUILD_ROOT/%{_sysconfdir}/sysconfig/plc-devel + +# Install root filesystem +install -d -m 755 $RPM_BUILD_ROOT/plc/devel/root +install -D -m 644 devel/root.img $RPM_BUILD_ROOT/plc/devel/root.img + +# Install data directory +find devel/data | cpio -p -d -u $RPM_BUILD_ROOT/plc/ + popd %clean @@ -69,7 +100,32 @@ fi %pre if [ -x %{_sysconfdir}/init.d/plc ] ; then - service plc stop + %{_sysconfdir}/init.d/plc stop +fi + +# Old versions of myplc used to ship with a bootstrapped database and +# /etc/planetlab directory. Including generated files in the manifest +# was dangerous; if /plc/data/var/lib/pgsql/data/base/1/16676 changed +# names from one RPM build to another, it would be rpmsaved and thus +# effectively deleted. Now we do not include these files in the +# manifest. However, to avoid deleting these files in the process of +# upgrading from one of these old versions of myplc, we must back up +# the database and /etc/planetlab and restore them after the old +# version has been uninstalled in %triggerpostun. + +# 0 = install, 1 = upgrade +if [ $1 -gt 0 ] ; then + for dir in /var/lib/pgsql/data /etc/planetlab ; do + if [ -d /plc/data/$dir ] ; then + mv /plc/data/$dir /plc/data/$dir.rpmsave + fi + done + + # Except for the default configuration file and DTD, which really + # should be considered for upgrade. + mkdir -m 755 -p /plc/data/etc/planetlab + mv /plc/data/etc/planetlab.rpmsave/{default_config.xml,plc_config.dtd} \ + /plc/data/etc/planetlab/ || : fi %post @@ -78,6 +134,22 @@ if [ -x /sbin/chkconfig ] ; then /sbin/chkconfig plc on fi +# Force a regeneration to take into account new variables +touch /plc/data/etc/planetlab/default_config.xml + +%triggerpostun -- %{name} +# 0 = erase, 1 = upgrade +if [ $1 -gt 0 ] ; then + for dir in /var/lib/pgsql/data /etc/planetlab ; do + if [ -d /plc/data/$dir.rpmsave -a -d /plc/data/$dir ] ; then + if tar -C /plc/data/$dir.rpmsave -cpf - . | \ + tar -C /plc/data/$dir -xpf - ; then + rm -rf /plc/data/$dir.rpmsave + fi + fi + done +fi + %preun # 0 = erase, 1 = upgrade if [ $1 -eq 0 ] ; then @@ -88,6 +160,46 @@ if [ $1 -eq 0 ] ; then fi fi +%pre devel +if [ -x %{_sysconfdir}/init.d/plc-devel ] ; then + %{_sysconfdir}/init.d/plc-devel stop +fi + +# 0 = install, 1 = upgrade +if [ $1 -gt 0 ] ; then + # Never overwrite /cvs + if [ -d /plc/devel/data/cvs ] ; then + echo "Preserving /plc/devel/data/cvs" + mv /plc/devel/data/cvs /plc/devel/data/cvs.rpmsave + fi +fi + +%post devel +if [ -x /sbin/chkconfig ] ; then + /sbin/chkconfig --add plc-devel + /sbin/chkconfig plc-devel on +fi + +%triggerpostun -- %{name} +# 0 = erase, 1 = upgrade +if [ $1 -gt 0 ] ; then + if [ -d /plc/devel/data/cvs.rpmsave ] ; then + echo "Restoring /plc/devel/data/cvs" + mv /plc/devel/data/cvs /plc/devel/data/cvs.%{version}-%{release} + mv /plc/devel/data/cvs.rpmsave /plc/devel/data/cvs + fi +fi + +%preun devel +# 0 = erase, 1 = upgrade +if [ $1 -eq 0 ] ; then + %{_sysconfdir}/init.d/plc-devel stop + if [ -x /sbin/chkconfig ] ; then + /sbin/chkconfig plc-devel off + /sbin/chkconfig --del plc-devel + fi +fi + %files %defattr(-,root,root,-) # Host startup script and configuration file @@ -105,7 +217,40 @@ fi %dir /plc/data %config(noreplace) /plc/data/* +%files devel +%defattr(-,root,root,-) +# Host startup script and configuration file +%{_sysconfdir}/init.d/plc-devel +%{_sysconfdir}/sysconfig/plc-devel + +# Root filesystem +/plc/devel/root.img +/plc/devel/root + +# Data directory +%dir /plc/devel/data +%config(noreplace) /plc/devel/data/* + %changelog +* Thu Jul 13 2006 Mark Huang - 0.4-2, 0.5-2 +- MyPLC 0.4 RC2. +- Build development environment (myplc-devel). Add support for + building myplc itself inside myplc-devel. +- Move step-specific initialization to appropriate plc.d scripts +- Fix postgresql startup failure when bootstrapping +- Allow CA to be configured for each SSL certificate set. Stop doing + root CA stuff, this is outside the scope of MyPLC. MyPLC now only + generates self-signed certificates, but supports replacement of the + self-signed certificates with real certifcates signed by another CA, + as long as the CA is specified. +- Self-sign the MA/SA SSL certificate (and by extension, the MA/SA API + certificate). +- pl_mom: Workarounds for when NM queries time out. +- plc_api: Honor PLC_MAIL_ENABLED. + +* Wed Jul 6 2006 Mark Huang - 0.4-1, 0.5-1 +- First stable release of MyPLC 0.4 RC1. + * Wed Apr 5 2006 Mark Huang - 0.2-1 - Basic functionality complete. Consolidate into a single package installed in /plc. diff --git a/plc_devel_config.xml b/plc_devel_config.xml new file mode 100644 index 0000000..e603edd --- /dev/null +++ b/plc_devel_config.xml @@ -0,0 +1,153 @@ + + + + + + + + + + Build Environment + These variables control the behavior of the + PlanetLab build environment. + + + + Fedora Core Release Version + 4 + Version number of Fedora Core upon which to + base the build environment. Warning: Currently, only Fedora + Core 4 is supported. + + + + Fedora Core Base Architecture + i386 + Base architecture of the build + environment. Warning: Currently, only i386 is + supported. + + + + Fedora Core Mirror URL + /usr/share/mirrors/fedora + Fedora Core mirror from which to install + filesystems. + + + + CVS Root + /cvs + CVSROOT to use when checking out code. + + + + Bootstrap Build + false + Controls whether MyPLC should be built inside + of its own development environment. + + + + + + + + development-libs + Development Libraries + true + The packages in this group are core libraries + needed to develop applications. + true + + + + + + + development-tools + Development Tools + true + These tools include core development tools such as + automake, gcc, perl, python, and debuggers. + true + + + + + + + legacy-software-development + Legacy Software Development + These packages provide compatibility support for + previous releases. + true + + + + + + + plc-build + PlanetLab Build Tools + Additional tools required to build PlanetLab + software. + + + kernel-vserver + + + gnupg + diffutils + + + vconfig + iptables + wget + beecrypt-devel + tetex-latex + gcc-c++ + + + libpcap + + + linuxdoc-tools + + + sudo + yum + createrepo + + + gperf + time + + + sharutils + + + nasm + mkisofs + dosfstools + + + rsync + + + + + + -- 2.43.0