X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=build.sh;h=63755032d8eceac6746e09671f92473d0fe35bc9;hb=refs%2Fheads%2F4.3;hp=c869ec5ca700db49f123424c53d919d1c5501355;hpb=0af7d4a2b4da6e949b7c2fd1554f6196d3ba0f76;p=myplc.git diff --git a/build.sh b/build.sh index c869ec5..6375503 100755 --- a/build.sh +++ b/build.sh @@ -1,281 +1,72 @@ #!/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 environment with the appropriate development packages +# installed). # -# Mark Huang -# Copyright (C) 2006 The Trustees of Princeton University +# Marc E. Fiuczynski +# Copyright (C) 2007 The Trustees of Princeton University # # $Id$ # -PATH=/sbin:/bin:/usr/sbin:/usr/bin +. build.functions -# 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 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 -# +# XXX .spec file needs to have the appropriate set of requires statements # Install configuration scripts -echo "* 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 api-config $root/usr/bin/api-config - -# Install init script -echo "* Installing initscript" -install -D -m 755 guest.init $root/etc/init.d/plc -chroot $root sh -c 'chkconfig --add plc; chkconfig plc on' - -# Install DB schema and API code -echo "* Installing DB schema and API code" -mkdir -p $root/usr/share -rsync -a $srcdir/pl_db $srcdir/plc_api $root/usr/share/ - -# Install web scripts -echo "* 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/ - -# Install web pages -echo "* Installing web pages" -mkdir -p $root/var/www/html -# Exclude old cruft, unrelated GENI pages, and official documents -rsync -a \ - --exclude='*2002' --exclude='*2003' \ - --exclude=geni --exclude=PDN --exclude=Talks \ - $srcdir/plc_www/ $root/var/www/html/ - -# XXX Build imprintable BootCD and BootManager images. +echo "* myplc-native: Installing configuration scripts" +pldistro=$1; shift +RPM_BUILD_ROOT=$1 ; shift +PYTHON_SITEARCH=`python -c 'from distutils.sysconfig import get_python_lib; print get_python_lib(1)'` +rm -rf ${RPM_BUILD_ROOT} +mkdir -p ${RPM_BUILD_ROOT} +echo "* myplc-native: installing plc_config.py in " ${PYTHON_SITEARCH} +install -D -m 755 plc_config.py ${RPM_BUILD_ROOT}/${PYTHON_SITEARCH}/plc_config.py +install -D -m 644 bashrc ${RPM_BUILD_ROOT}/usr/share/myplc/bashrc +echo "* myplc-native: installing scripts in /usr/bin" +install -D -m 755 plc-config ${RPM_BUILD_ROOT}/usr/bin/plc-config +install -D -m 755 plc-config-tty ${RPM_BUILD_ROOT}/usr/bin/plc-config-tty +install -D -m 755 db-config ${RPM_BUILD_ROOT}/usr/bin/db-config +install -D -m 755 dns-config ${RPM_BUILD_ROOT}/usr/bin/dns-config +install -D -m 755 plc-map.py ${RPM_BUILD_ROOT}/usr/bin/plc-map.py +install -D -m 755 plc-kml.py ${RPM_BUILD_ROOT}/usr/bin/plc-kml.py +install -D -m 755 refresh-peer.py ${RPM_BUILD_ROOT}/usr/bin/refresh-peer.py +install -D -m 755 clean-empty-dirs.py ${RPM_BUILD_ROOT}/usr/bin/clean-empty-dirs.py +install -D -m 755 mtail.py ${RPM_BUILD_ROOT}/usr/bin/mtail.py +install -D -m 755 plc-check-ssl-peering.py ${RPM_BUILD_ROOT}/usr/bin/plc-check-ssl-peering.py +install -D -m 755 plc-orphan-accounts.py ${RPM_BUILD_ROOT}/usr/bin/plc-orphan-accounts.py + +# Extra scripts (mostly for mail and dns) not installed by myplc by default. Used in production +echo "* myplc-native: installing scripts in /etc/support-scripts" +mkdir -p ${RPM_BUILD_ROOT}/etc/support-scripts +cp support-scripts/* ${RPM_BUILD_ROOT}/etc/support-scripts +chmod 444 ${RPM_BUILD_ROOT}/etc/support-scripts/* + +# copy initscripts to etc/plc_sliceinitscripts +mkdir -p ${RPM_BUILD_ROOT}/etc/plc_sliceinitscripts +cp plc_sliceinitscripts/* ${RPM_BUILD_ROOT}/etc/plc_sliceinitscripts +chmod 444 ${RPM_BUILD_ROOT}/etc/plc_sliceinitscripts/* + +# Install initscripts +echo "* myplc-native: Installing initscripts" +install -D -m 755 plc.init ${RPM_BUILD_ROOT}/etc/init.d/plc +find plc.d | cpio -p -d -u ${RPM_BUILD_ROOT}/etc/ +chmod 755 ${RPM_BUILD_ROOT}/etc/plc.d/* # Install configuration file -echo "* Installing configuration file" -install -D -m 644 $config $data/etc/planetlab/plc_config.xml - -# Move "data" directories out of the installation -datadirs=( -/etc/planetlab -/var/lib/pgsql -/var/www/html/alpina-logs -/var/www/html/boot -/var/www/html/download -/var/www/html/generated -/var/www/html/install-rpms -/var/www/html/xml -) - -echo "* Moving data directories out of the installation" -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 - -# Shrink to 100 MB free space -kb=$(python < 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 <