# Mark Huang <mlhuang@cs.princeton.edu>
# Copyright (C) 2006 The Trustees of Princeton University
#
-# $Id: build.functions,v 1.6 2007/08/16 21:42:02 mef Exp $
+# $Id$
#
PATH=/sbin:/bin:/usr/sbin:/usr/bin
export PATH
-# Release and architecture to install
-PLC_DEVEL_FEDORA_RELEASE=$([ -f "/etc/fedora-release" ] && awk ' { if ($3=="Core") print $4; else print $3 } ' /etc/fedora-release || echo 4)
-PLC_DEVEL_FEDORA_ARCH=$(uname -i)
-# Fedora Core mirror from which to install filesystems
-PLC_DEVEL_FEDORA_URL=file:///data/fedora
+. build.common
+pl_process_fedora_options $@
+shiftcount=$?
+shift $shiftcount
+
+# XXX Backwards compatibility with old myplc-devel environment
# We may be running inside a myplc-devel environment, which can
# override these defaults.
if [ -f /etc/planetlab/plc_config ] ; then
. /etc/planetlab/plc_config
+ [ ! -z "$PLC_DEVEL_FEDORA_RELEASE" ] && pl_FEDORA_RELEASE=$PLC_DEVEL_FEDORA_RELEASE
+ [ ! -z "$PLC_DEVEL_FEDORA_ARCH" ] && pl_FEDORA_ARCH=$PLC_DEVEL_FEDORA_ARCH
+ [ ! -z "$PLC_DEVEL_FEDORA_URL" ] && pl_FEDORA_URL=$PLC_DEVEL_FEDORA_URL
fi
-usage()
-{
- echo "Usage: $0 [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
# 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
+make_chroot_from_lst() {
+ root=$1; shift
+ fcdistro=$1; shift
+
+ packages=$(pl_getPackagesOptions2 $fcdistro "$@")
+ groups=$(pl_getGroupsOptions2 $fcdistro "$@")
+
+ pl_setup_chroot $root $packages $groups
}
# 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
-}
+#move_datadirs() {
+# root=$1
+# data=$2
+# shift 2
+# pl_move_dirs $root $data /data "$@"
+#}
# 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
+#make_image() {
+# root=$1
+# image=$2
+# pl_make_image $root $image 100000000
+#}
+
+function yum_conf_to_build_host () {
+ BUILD_HOST=$(hostname)
+ cat <<EOF
+[main]
+cachedir=/var/cache/yum
+debuglevel=2
+logfile=/var/log/yum.log
+pkgpolicy=newest
+distroverpkg=redhat-release
+tolerant=1
+exactarch=1
+retries=10
+obsoletes=1
+gpgcheck=0
+# Prevent yum-2.4 from loading additional repository definitions
+# (e.g., from /etc/yum.repos.d/)
+reposdir=/dev/null
+
+[base]
+name=Fedora Core 4 - i386 - base
+baseurl=http://${BUILD_HOST}/fedora/linux/core/${pl_DISTRO_RELEASE}/${pl_DISTRO_ARCH}/os/
+
+
+[updates]
+name=Fedora Core 4 - i386 - updates
+baseurl=http://${BUILD_HOST}/fedora/linux/core/updates/${pl_DISTRO_RELEASE}/${pl_DISTRO_ARCH}/
+
+$(if [ "${pl_DISTRO_RELEASE}" -le 6 ] ; then cat << EXTRAS
+[extras]
+name=Fedora Core 4 - i386 - extras
+baseurl=http://${BUILD_HOST}/fedora/linux/extras/${pl_DISTRO_RELEASE}/${pl_DISTRO_ARCH}/
+EXTRAS
+fi)
+EOF
+
}
+
+function sudoers_bootcustom_apache () {
+ cat <<EOF
+User_Alias WWW = %apache,%root
+Cmnd_Alias BOOTCUSTOM = /usr/share/bootcd/bootcustom.sh
+WWW ALL = NOPASSWD: BOOTCUSTOM
+EOF
+}
+
+# quick and dirty - might break anytime if docbook html output changes
+function docbook_html_to_drupal () {
+ title=$1; shift
+ html=$1; shift
+ php=$1; shift
+
+ mkdir -p $(dirname $php)
+ if [ ! -f $html ] ; then
+ cat << __header_no_doc__ > $php
+<?php
+require_once 'plc_drupal.php';
+drupal_set_title("$title - unavailable");
+?>
+<p class='plc-warning'> Build-time error - could not locate documentation $html</p>
+__header_no_doc__
+ else
+ # insert header, makes sure we have a trailing eol
+ (cat << __header_doc__ ; cat $html ) > $php
+<?php
+require_once 'plc_drupal.php';
+drupal_set_title("$title");
+?>
+__header_doc__
+ # ignore ed return status
+ set +e
+ # cuts off around the <body> </body>
+ # preserves the 4 first lines that we just added as a header
+ ed -s $php << __ed_script__
+/BODY/
+/>/
+s,><,<,
+5,-d
+$
+?/BODY?
+s,><.*,>,
++
+;d
+w
+q
+__ed_script__
+ set -e
+ fi
+}