cleaning up the root creation functions and build.common - untested
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Fri, 7 Dec 2007 12:31:14 +0000 (12:31 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Fri, 7 Dec 2007 12:31:14 +0000 (12:31 +0000)
Makefile
build.common
config.planetlab/bootstrapfs-production.pkgs
getrpmmacros.sh [new file with mode: 0755]

index 3e8f6ea..0043117 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -204,6 +204,8 @@ myplc-release:
        (echo    "Build trelease: $(RELEASE)") >> $@
        echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx modules versions info" >> $@
        $(MAKE) --no-print-directory versions >> $@
+       echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx rpms list" >> $@
+       $(MAKE) --no-print-directory version-rpms >> $@
 
 ### yumgroups.xml
 # the source
@@ -296,9 +298,7 @@ endif
        rm -f $@ 
        echo "%_topdir $(HOME)" >> $@
        echo "%_tmppath $(HOME)/tmp" >> $@
-       echo "%_netsharedpath /proc:/dev/pts" >> $@
-       echo "%_install_langs C:de:en:es:fr" >> $@
-       echo "%_excludedocs yes" >> $@
+       getrpmmacros.sh >> $@
 
 ### this utility allows to extract various info from a spec file
 ### and to define them in makefiles
@@ -601,6 +601,15 @@ $(foreach module,$(ALL-MODULES), $(eval $(call print_version,$(module))))
 
 versions: $(foreach module, $(ALL-MODULES), $(module)-version)
 
+RFORMAT="%20s :: %s\n"
+define print_rpms
+$(1)-version-rpms:
+       @$(foreach rpm,$($(1).rpms),printf $(RFORMAT) $(1) $(notdir $(rpm));)
+version-rpms: $(1)-version-rpms
+endef
+
+$(foreach package,$(sort $(ALL)), $(eval $(call print_rpms,$(package))))
+
 #################### include install Makefile
 # the default is to use the distro-dependent install file
 # however the main distro file can redefine PLDISTROINSTALL
index 6c5b199..97193b2 100644 (file)
@@ -125,7 +125,16 @@ function pl_process_fedora_options () {
 }
 
 ######################################## handling a root image
-function pl_makedevs() {
+function pl_root_rpm_macros () {
+    cat <<EOF
+%_install_langs C:en_US:en
+%_netsharedpath /proc:/dev/pts
+%_excludedocs 1
+%__file_context_path /dev/null
+EOF
+}
+
+function pl_root_makedevs() {
     vroot=$1
     # Clean ${vroot}/dev, but only when ${vroot}!=""
     [ -n $vroot ] && rm -rf $vroot/dev
@@ -163,8 +172,18 @@ function pl_makedevs() {
     done
 }
 
-function mkfedora_usage()
-{
+# Default yum repositories to try
+mirrors=(
+    file:///data/fedora
+    http://localhost/fedora
+    http://build.planet-lab.org/fedora
+    http://coblitz.codeen.org/coblitz.planet-lab.org/pub/fedora
+    ftp://mirror.cs.princeton.edu/pub/mirrors/fedora
+    ftp://mirror.stanford.edu/pub/mirrors/fedora
+    ftp://rpmfind.net/linux/fedora
+    )
+
+function mkfedora_usage() {
     echo "Usage: mkfedora [OPTION]... [basedir]"
     echo "     -l url          Fedora mirror location. Defaults to try:"
     for mirror in "${mirrors[@]}" ; do
@@ -187,236 +206,199 @@ function mkfedora_usage()
     exit 1
 }
 
-function mkfedora () {
+function pl_root_mkfedora () {
 
-echo "* Entering mkfedora " "$@"
+    echo "* Entering pl_root_mkfedora " "$@"
 
 # Verbosity
-verbose=0
+    verbose=0
 
-# Default yum repositories to try
-mirrors=(
-file:///data/fedora
-http://localhost/fedora
-http://build.planet-lab.org/fedora
-http://coblitz.codeen.org/coblitz.planet-lab.org/pub/fedora
-ftp://mirror.cs.princeton.edu/pub/mirrors/fedora
-ftp://mirror.stanford.edu/pub/mirrors/fedora
-ftp://rpmfind.net/linux/fedora
-)
-
-# Release and architecture to install
-releasever=7
-basearch=i386
+# Release and architecture to install : defaults to current vserver's settings or previously parsed fedora_options
+    releasever=$pl_DISTRO_RELEASE
+    basearch=$pl_DISTRO_ARCH
+    [ -n "$pl_DISTRO_URL" ] && mirrors=($pl_DISTRO_URL)
 
 # Yum groups to install
-groups=()
+    groups=()
 
 # Packages to install
-packages=()
+    packages=()
 
 # Packages to exclude
-exclude=()
+    exclude=()
 
 # Exclude kernel* (and related) packages from all repositories except bootstrap
-exclude_kernel=
-
-# PlanetLab development environment
-if [ -f /etc/planetlab/plc_config ] ; then
-    . /etc/planetlab/plc_config
-    if [ -n "$PLC_DEVEL_FEDORA_URL" ] ; then
-       echo "* mkfedora : setting mirrors from /etc/planetlab/config"
-       mirrors=($PLC_DEVEL_FEDORA_URL)
-    fi
-fi
+    exclude_kernel=
 
 # Get options
-while getopts "l:r:a:g:p:x:f:kvh" opt ; do
-    case $opt in
-       l)
-           if echo $OPTARG | grep -q -i '^\(file\|http[s]*\)://' ; then
-               mirrors=($OPTARG)
-           else
-               mirrors=(file://$OPTARG)
-           fi
-           ;;
-       r)
-           releasever=$OPTARG
-           ;;
-       a)
-           basearch=$OPTARG
-           ;;
-       g)
-           groups[${#groups[*]}]="$OPTARG"
-           ;;
-       p)
-           packages[${#packages[*]}]="$OPTARG"
-           ;;
-       x)
-           exclude[${#exclude[*]}]="$OPTARG"
-           ;;
-       f)
-           pkgsfile=$OPTARG
-           ;;
-       k)
-           exclude_kernel="exclude=kernel* ulogd iptables"
-           ;;
-       v)
-           verbose=1
-           set -x
-           ;;
-       h|*)
-           mkfedora_usage
-           ;;
-    esac
-done
+    while getopts "l:r:a:g:p:x:f:kvh" opt ; do
+       case $opt in
+           l)
+               if echo $OPTARG | grep -q -i '^\(file\|http[s]*\)://' ; then
+                   mirrors=($OPTARG)
+               else
+                   # xxx rather use this as a .mirrors file, searched in config.pldistro/
+                   # that would use the pkgs syntax with mirror:
+                   #mirrors=($(pl_parsePkgs mirror <fcdistro> $(pl_locateDistroFile ../build/ <pldistro> $OPTARG.mirrors)))
+                   mirrors=(file://$OPTARG)
+               fi
+               ;;
+           r)
+               releasever=$OPTARG
+               ;;
+           a)
+               basearch=$OPTARG
+               ;;
+           g)
+               groups[${#groups[*]}]="$OPTARG"
+               ;;
+           p)
+               packages[${#packages[*]}]="$OPTARG"
+               ;;
+           x)
+               exclude[${#exclude[*]}]="$OPTARG"
+               ;;
+           f)
+               pkgsfile=$OPTARG
+               ;;
+           k)
+               exclude_kernel="exclude=kernel* ulogd iptables"
+               ;;
+           v)
+               verbose=1
+               set -x
+               ;;
+           h|*)
+               mkfedora_usage
+               ;;
+       esac
+    done
 
-shift $(($OPTIND - 1))
-if [ ! -d "$1" ] ; then
-    mkfedora_usage
-fi
+    shift $(($OPTIND - 1))
+    if [ ! -d "$1" ] ; then
+       mkfedora_usage
+    fi
 
-vroot=$(cd $1 && pwd -P)
+    vroot=$(cd $1 && pwd -P)
 
-if [ $UID -ne 0 ] ; then
-    echo "Error: You must run this script as root."
-    exit 1
-fi
+    if [ $UID -ne 0 ] ; then
+       echo "Error: You must run this script as root."
+       exit 1
+    fi
 
-function mkfedora_fetch ()
-{
-    curl --fail --silent --max-time 60 "$1"
-}
+    function mkfedora_fetch ()
+    {
+       curl --fail --silent --max-time 60 "$1"
+    }
 
-# hard to find two mirrors with a similar layout
-# set list of attempted locations according to releasever
-if [ $releasever -ge 7 ] ; then
-    attempts="
+    # set list of attempted locations according to releasever
+    if [ $releasever -ge 7 ] ; then
+       attempts="
 linux/releases/$releasever/Everything/$basearch/os
 $releasever/Everything/$basearch/os
 core/$releasever/Everything/$basearch/os
 linux/core/$releasever/$basearch/os
 "
-else
-    attempts="
-linux/core/$releasever/$basearch/os 
-core/$releasever/$basearch/os 
-$releasever/$basearch/os
-"
-fi
+    else
+       attempts="
+       linux/core/$releasever/$basearch/os 
+       core/$releasever/$basearch/os 
+       $releasever/$basearch/os
+       "
+    fi
 
-echo "$0: candidate mirrors"
-for mirror in "${mirrors[@]}" ; do
-    echo "* candidate mirror $mirror"
-done
-baseurl=""
-for mirror in "${mirrors[@]}" ; do
-    for attempt in $attempts; do 
-       attempturl=$mirror/$attempt
-       if mkfedora_fetch $attempturl/repodata/repomd.xml >/dev/null ; then
-           baseurl=$attempturl
-           break 2
-       fi
+    echo "$0: candidate mirrors"
+    for mirror in "${mirrors[@]}" ; do
+       echo "* candidate mirror $mirror"
     done
-done
-
-if [ -z "$baseurl" ] ; then
-    echo "Error: $releasever/$basearch/os/repodata/repomd.xml"
-    echo "       could not be found in any of the following locations:"
-    echo
-    for mirror in ${mirrors[@]} ; do
-       for attempt in $attempts ; do
-           echo $mirror/$attempt
+    baseurl=""
+    for mirror in "${mirrors[@]}" ; do
+       for attempt in $attempts; do 
+           attempturl=$mirror/$attempt
+           if mkfedora_fetch $attempturl/repodata/repomd.xml >/dev/null ; then
+               baseurl=$attempturl
+               break 2
+           fi
        done
     done
-    echo
-    mkfedora_usage
-fi
 
-# this used to be for when mkfedora was called within myplc 
-# that is, when the bootcd was recomputed from scratch
-### exec 3>&1
-### exec 4>&2
-### if [ $verbose -eq 0 ] ; then
-###     exec 1>/dev/null
-###     exec 2>/dev/null
-### fi
-
-# Do not tolerate errors
-set -e
-
-## make rpms ignore installing stuff to special fs entries like /proc
-# Because of https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=52725
-# you have to use at least one language beside 'C'
-# Prevent all locales from being installed in reference image
-mkdir -p $vroot/etc/rpm
-cat > $vroot/etc/rpm/macros <<EOF
-%_install_langs C:en_US:en
-%_netsharedpath /proc:/dev/pts
-%_excludedocs 1
-%__file_context_path /dev/null
-EOF
-
-# Trick rpm and yum, who read the real root /etc/rpm/macros file
-# rather than the one installed in the reference image, despite what
-# you might expect the --root and --installroot options to mean. Both
-# programs always read $HOME/.rpmmacros.
-export HOME=$vroot/tmp
-mkdir -p $vroot/tmp
-cp $vroot/etc/rpm/macros $vroot/tmp/.rpmmacros
-
-### Checking whether this is really needed
-### # copy to the vserver's rpm macros
-### # xxx fixme - this must be reviewed once we get the stuff running
-### cp $vroot/etc/rpm/macros /etc/rpm/macros 
-
-# Mount in reference image
-mount -t devpts none $vroot/dev/pts
-mount -t tmpfs none $vroot/dev/shm
-mkdir -p $vroot/proc
-mount -t proc none $vroot/proc
-
-function mkfedora_cleanup ()
-{
-    umount -l $vroot/proc
-    umount -l $vroot/dev/shm
-    umount -l $vroot/dev/pts
-}
-
-# Clean up before exiting if anything goes wrong
-trap "mkfedora_cleanup" ERR INT
-
-# Create a /var/lib dirs for yum & rpm
-mkdir -p $vroot/var/lib/yum
-mkdir -p $vroot/var/lib/rpm
-mkdir -p $vroot/usr/share/info
+    if [ -z "$baseurl" ] ; then
+       echo "Error: $releasever/$basearch/os/repodata/repomd.xml"
+       echo "       could not be found in any of the following locations:"
+       echo
+       for mirror in ${mirrors[@]} ; do
+           for attempt in $attempts ; do
+               echo $mirror/$attempt
+           done
+       done
+       echo
+       mkfedora_usage
+    fi
 
-# Create a dummy /etc/fstab in reference image
-mkdir -p $vroot/etc
-cat >$vroot/etc/fstab <<EOF
+    # Do not tolerate errors
+    set -e
+
+    ## make rpms ignore installing stuff to special fs entries like /proc
+    # Because of https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=52725
+    # you have to use at least one language beside 'C'
+    # Prevent all locales from being installed in reference image
+    mkdir -p $vroot/etc/rpm
+    pl_root_rpm_macros > $vroot/etc/rpm/macros 
+
+    # Trick rpm and yum, who read the real root /etc/rpm/macros file
+    # rather than the one installed in the reference image, despite what
+    # you might expect the --root and --installroot options to mean. Both
+    # programs always read $HOME/.rpmmacros.
+    export HOME=$vroot/tmp
+    mkdir -p $vroot/tmp
+    pl_root_rpm_macros > $vroot/tmp/.rpmmacros
+
+    function mkfedora_cleanup () {
+       umount -l $vroot/proc
+       umount -l $vroot/dev/shm
+       umount -l $vroot/dev/pts
+    }
+
+    # Clean up before exiting if anything goes wrong
+    trap "mkfedora_cleanup" ERR INT
+
+    # Mount in reference image
+    mount -t devpts none $vroot/dev/pts
+    mount -t tmpfs none $vroot/dev/shm
+    mkdir -p $vroot/proc
+    mount -t proc none $vroot/proc
+    
+    # Create a /var/lib dirs for yum & rpm
+    mkdir -p $vroot/var/lib/yum
+    mkdir -p $vroot/var/lib/rpm
+    mkdir -p $vroot/usr/share/info
+
+    # Create a dummy /etc/fstab in reference image
+    mkdir -p $vroot/etc
+    cat >$vroot/etc/fstab <<EOF
 # This fake fstab exists only to please df and linuxconf.
 /dev/hdv1      /       ext2    defaults        1 1
 EOF
-cp $vroot/etc/fstab $vroot/etc/mtab
+    cp $vroot/etc/fstab $vroot/etc/mtab
 
-# Necessary for some scripts
-mkdir -p $vroot/etc/sysconfig
-echo "NETWORKING=yes" > $vroot/etc/sysconfig/network
+    # Necessary for some scripts
+    mkdir -p $vroot/etc/sysconfig
+    echo "NETWORKING=yes" > $vroot/etc/sysconfig/network
 
-# Initialize RPM database in reference image
-mkdir -p $vroot/var/lib/rpm
-rpm --root $vroot --initdb
-rpm --root $vroot --import $baseurl/RPM-GPG-KEY-fedora
+    # Initialize RPM database in reference image
+    mkdir -p $vroot/var/lib/rpm
+    rpm --root $vroot --initdb
+    rpm --root $vroot --import $baseurl/RPM-GPG-KEY-fedora
 
-# Initialize yum in reference image
-mkdir -p $vroot/var/cache/yum $vroot/var/log
-if [ $releasever -lt 7 ] ; then
+    # Initialize yum in reference image
+    mkdir -p $vroot/var/cache/yum $vroot/var/log
+    if [ $releasever -lt 7 ] ; then
        corename="Core "
-else
+    else
        corename=""
-fi
+    fi
 
-cat >$vroot/etc/yum.conf <<EOF
+    cat >$vroot/etc/yum.conf <<EOF
 [main]
 cachedir=/var/cache/yum
 debuglevel=2
@@ -438,47 +420,48 @@ baseurl=$baseurl/
 $exclude_kernel
 EOF
 
-for optional in updates extras ; do
-    for optionalurl in \
-       $mirror/linux/core/$optional/$releasever/$basearch \
-       $mirror/core/$optional/$releasever/$basearch \
-       $mirror/linux/$optional/$releasever/$basearch \
-       $mirror/$optional/$releasever/$basearch ; do
-        if mkfedora_fetch $optionalurl/repodata/repomd.xml ; then
-           cat >>$vroot/etc/yum.conf <<EOF
+    for optional in updates extras ; do
+       for optionalurl in \
+           $mirror/linux/core/$optional/$releasever/$basearch \
+           $mirror/core/$optional/$releasever/$basearch \
+           $mirror/linux/$optional/$releasever/$basearch \
+           $mirror/$optional/$releasever/$basearch ; do
+            if mkfedora_fetch $optionalurl/repodata/repomd.xml ; then
+               cat >>$vroot/etc/yum.conf <<EOF
 
 [$(basename $optional)]
 name=Fedora ${corename}${releasever} - $basearch - $(basename $optional)
 baseurl=$optionalurl/
 $exclude_kernel
 EOF
-           break
-       fi
+                break
+           fi
+       done
     done
-done
-
-# If we are being built as part of an automated RPM build, solve the
-# bootstrap problem by including any just built packages in the yum
-# configuration. This cooperates with the PlanetLab build system.
-if [ -n "$RPM_BUILD_DIR" ] ; then
-    RPM_RPMS_DIR=$(cd $(dirname $RPM_BUILD_DIR)/RPMS && pwd -P)
-    # yum-2.0.x
-    if [ -x /usr/bin/yum-arch ] ; then
-       yum-arch -q $RPM_RPMS_DIR
-    fi
-    # yum-2.4.x
-    if [ -x /usr/bin/createrepo ] ; then
-       if [ -f $RPM_RPMS_DIR/yumgroups.xml ] ; then
-           groupfile="-g yumgroups.xml"
+
+    # If we are being built as part of an automated RPM build, solve the
+    # bootstrap problem by including any just built packages in the yum
+    # configuration. This cooperates with the PlanetLab build system.
+### make takes care of that
+    if [ -n "$RPM_BUILD_DIR" ] ; then
+       RPM_RPMS_DIR=$(cd $(dirname $RPM_BUILD_DIR)/RPMS && pwd -P)
+###        # yum-2.0.x
+###    if [ -x /usr/bin/yum-arch ] ; then
+###        yum-arch -q $RPM_RPMS_DIR
+###    fi
+###        # yum-2.4.x
+###    if [ -x /usr/bin/createrepo ] ; then
+###        if [ -f $RPM_RPMS_DIR/yumgroups.xml ] ; then
+###            groupfile="-g yumgroups.xml"
+###        fi
+###        createrepo --quiet $groupfile $RPM_RPMS_DIR
+###    fi
+        # If run under sudo, allow user to delete the headers/ and
+        # repodata/ directories.
+       if [ -n "$SUDO_USER" ] ; then
+           chown -R $SUDO_USER $RPM_RPMS_DIR
        fi
-       createrepo --quiet $groupfile $RPM_RPMS_DIR
-    fi
-    # If run under sudo, allow user to delete the headers/ and
-    # repodata/ directories.
-    if [ -n "$SUDO_USER" ] ; then
-       chown -R $SUDO_USER $RPM_RPMS_DIR
-    fi
-    cat >>$vroot/etc/yum.conf <<EOF
+       cat >>$vroot/etc/yum.conf <<EOF
 
 [bootstrap]
 name=Bootstrap - $basearch - $RPM_RPMS_DIR/
@@ -486,126 +469,113 @@ baseurl=file://$RPM_RPMS_DIR/
 EOF
 fi
 
-# pkgs file
-if [ -n "$pkgsfile" ] ; then
-    # parse pkgsfile and add to local vars
-    fcdistro=$(pl_getReleaseName "Fedora" $releasever)
-    for i in $(pl_parsePkgs package $fcdistro $pkgsfile)  ; do
-       packages[${#packages[*]}]="$i"
-    done
-    for i in $(pl_parsePkgs group $fcdistro $pkgsfile) ; do
-       groups[${#groups[*]}]="$i"
-    done
-    for i in $(pl_parsePkgs exclude $fcdistro $pkgsfile) ; do
-       exclude[${#exclude[*]}]="$i"
-    done
-    junk=$(pl_parsePkgs junk $fcdistro $pkgsfile)
-    precious=$(pl_parsePkgs precious $fcdistro $pkgsfile)
-fi
-
-excludes=
-for package in "${exclude[@]}" ; do
-    excludes="$excludes --exclude=$package"
-done
-
-# glibc must be specified explicitly for the correct arch to be
-# chosen.
-echo "* Installing glibc"
-yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes install glibc
-
-# Go, baby, go
-if [ ${#packages[*]} -gt 0 ] ; then
-   echo "* Installing optional packages" "${packages[@]}" 
-   yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes \
-         install "${packages[@]}"
-   if ! rpm --root $vroot -q "${packages[@]}" >/dev/null ; then
-       echo "* Warning: Missing packages"
-       rpm --root $vroot -q "${packages[@]}" | grep "not installed"
-   fi
-fi
-
-if [ ${#groups[*]} -gt 0 ] ; then
-   ## call yum sequentially to get finer-grained info on dependencies
-   for grp in "${groups[@]}" ; do
-      echo "* Installing optional group $grp" 
-      yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes \
-       groupinstall "$grp"
-   done
-fi
+    # pkgs file
+    if [ -n "$pkgsfile" ] ; then
+        # parse pkgsfile and add to local vars
+       fcdistro=$(pl_getReleaseName "Fedora" $releasever)
+       for i in $(pl_parsePkgs package $fcdistro $pkgsfile)  ; do
+           packages[${#packages[*]}]="$i"
+       done
+       for i in $(pl_parsePkgs group $fcdistro $pkgsfile) ; do
+           groups[${#groups[*]}]="$i"
+       done
+       for i in $(pl_parsePkgs exclude $fcdistro $pkgsfile) ; do
+           exclude[${#exclude[*]}]="$i"
+       done
+       junk=$(pl_parsePkgs junk $fcdistro $pkgsfile)
+       precious=$(pl_parsePkgs precious $fcdistro $pkgsfile)
+    fi
 
-# FC2 dev %preinstall checks /proc/mounts to make sure that /dev is
-# not currently mounted as devfs. If it thinks it is, it will refuse
-# to install the package. On a modern system running udev that mounts
-# /dev as tmpfs, this check fails. Since we are installing into a
-# chroot, whether /dev is mounted on the host system or not doesn't
-# matter. If dev was explicitly mentioned in the packages list, force
-# its installation.
-if [ "$releasever" = "2" ] ; then
-    for package in "${packages[@]}" ; do
-       if [ "$package" = "dev" ] && ! rpm --root $vroot -q dev >/dev/null 2>&1 ; then
-           rpm --root $vroot -Uvh --noscripts $baseurl/Fedora/RPMS/dev-3.3.13-1.i386.rpm
-           break
-       fi
+    excludes=
+    for package in "${exclude[@]}" ; do
+       excludes="$excludes --exclude=$package"
     done
-fi
-
-# Clean yum cache
-echo "* Cleaning up"
-yum -c $vroot/etc/yum.conf --installroot=$vroot -y clean all
-
-# Clean RPM state
-rm -f $vroot/var/lib/rpm/__db*
-
-# Set time zone to UTC
-if [ -f $vroot/usr/share/zoneinfo/UTC -a -f $vroot/etc/localtime ] ; then
-    rm -f $vroot/etc/localtime
-    ln -s /usr/share/zoneinfo/UTC $vroot/etc/localtime
-fi
-
-# formerly in bootcd/prep.sh : to optimize footprint
-echo "* Removing unnecessary junk"
 
-pushd $vroot
-
-# Save precious files
-[ -n "$precious" ] && tar --ignore-failed-read -cpf precious.tar $precious
-
-# Remove unnecessary junk
-[ -n "$junk" ] && rm -rf $junk
-
-# Restore precious files
-[ -n "$precious" ] && tar -xpf precious.tar && rm -f precious.tar
-
-popd
-
-# remove trap handler, as we are about to call it directly.
-trap - ERR INT
+    # glibc must be specified explicitly for the correct arch to be
+    # chosen.
+    echo "* Installing glibc"
+    yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes install glibc
+
+    # Go, baby, go
+    if [ ${#packages[*]} -gt 0 ] ; then
+       echo "* Installing optional packages" "${packages[@]}" 
+       yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes \
+           install "${packages[@]}"
+       if ! rpm --root $vroot -q "${packages[@]}" >/dev/null ; then
+           echo "* Warning: Missing packages"
+           rpm --root $vroot -q "${packages[@]}" | grep "not installed"
+       fi
+    fi
 
-# Clean up
-mkfedora_cleanup
+    if [ ${#groups[*]} -gt 0 ] ; then
+       ## call yum sequentially to get finer-grained info on dependencies
+       for grp in "${groups[@]}" ; do
+           echo "* Installing optional group $grp" 
+           yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes \
+               groupinstall "$grp"
+       done
+    fi
 
-return 0
-}
+    # formerly in bootcd/prep.sh : to optimize footprint
+    echo "* Removing unnecessary junk"
+
+    pushd $vroot
+
+    # Save precious files
+    [ -n "$precious" ] && tar --ignore-failed-read -cpf precious.tar $precious
+
+    # Remove unnecessary junk
+    [ -n "$junk" ] && rm -rf $junk
+
+    # Restore precious files
+    [ -n "$precious" ] && tar -xpf precious.tar && rm -f precious.tar
+
+    popd
+
+###    # FC2 dev %preinstall checks /proc/mounts to make sure that /dev is
+###    # not currently mounted as devfs. If it thinks it is, it will refuse
+###    # to install the package. On a modern system running udev that mounts
+###    # /dev as tmpfs, this check fails. Since we are installing into a
+###    # chroot, whether /dev is mounted on the host system or not doesn't
+###    # matter. If dev was explicitly mentioned in the packages list, force
+###    # its installation.
+###    if [ "$releasever" = "2" ] ; then
+###    for package in "${packages[@]}" ; do
+###        if [ "$package" = "dev" ] && ! rpm --root $vroot -q dev >/dev/null 2>&1 ; then
+###            rpm --root $vroot -Uvh --noscripts $baseurl/Fedora/RPMS/dev-3.3.13-1.i386.rpm
+###            break
+###        fi
+###    done
+###    fi
+
+    # Clean yum cache
+    echo "* Cleaning up"
+    yum -c $vroot/etc/yum.conf --installroot=$vroot -y clean all
+
+    # Clean RPM state
+    rm -f $vroot/var/lib/rpm/__db*
+
+    # Set time zone to UTC
+    if [ -f $vroot/usr/share/zoneinfo/UTC -a -f $vroot/etc/localtime ] ; then
+       rm -f $vroot/etc/localtime
+       ln -s /usr/share/zoneinfo/UTC $vroot/etc/localtime
+    fi
 
-function pl_mkfedora() {
-    root=$1
-    shift
-    options=$@
+    # remove trap handler, as we are about to call it directly.
+    trap - ERR INT
 
-    pl_makedevs $root
+    # Clean up
+    mkfedora_cleanup
 
-    [ -n "$pl_DISTRO_URL" ] && options="$options -l $pl_DISTRO_URL"
-    [ -n "$pl_DISTRO_ARCH" ] && options="$options -a $pl_DISTRO_ARCH"
-    [ -n "$pl_DISTRO_RELEASE" ] && options="$options -r $pl_DISTRO_RELEASE"
-    # echo "mkfedora -v $options $root"
-    mkfedora -v $options $root
+    return 0
 }
 
-function pl_setup_chroot() {
+function pl_root_setup_chroot() {
     root=$1; shift
     options="$@"
 
-    pl_mkfedora $root $options
+    pl_root_makedevs $root
+    pl_root_mkfedora $root $options
 
     # Disable all services in reference image
     chroot $root sh -c "/sbin/chkconfig --list | awk '{ print \$1 }' | xargs -i /sbin/chkconfig {} off"
index 114d87b..df0ed88 100644 (file)
@@ -1,13 +1,13 @@
-# Install the "PlanetLab" group. This requires that the PlanetLab
-# build system install the appropriate yumgroups.xml file (currently
-# build/groups/v4_yumgroups.xml) in $RPM_BUILD_DIR/../RPMS/ and that
-# mkfedora runs either yum-arch or createrepo on that directory. dev
-# is specified explicitly because of a stupid bug in its %post script
-# that causes its installation to fail; see the mkfedora script for a
+# Install the "PlanetLab" group. This requires that the 
+# build system install the appropriate yumgroups.xml file 
+# -- currently build/groups/<pldistro>.xml --
+# <build>/RPMS/ and that the build runs createrepo on that directory. 
+# dev is specified explicitly because of a stupid bug in its %post script
+# that causes its installation to fail; see pl_root_mkfedora for a
 # full explanation. coreutils and python are specified explicitly
 # because groupinstall does not honor Requires(pre) dependencies
 # properly, most %pre scripts require coreutils to be installed first,
 # and some of our %post scripts require python.
 
-package: python
-group: PlanetLab
\ No newline at end of file
+package: python dev coreutils
+group: PlanetLab
diff --git a/getrpmmacros.sh b/getrpmmacros.sh
new file mode 100755 (executable)
index 0000000..e5f0fa7
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+. build.common
+
+pl_root_rpm_macros