renamed new_plc_api to PLCAPI.
[build.git] / mkfedora
index a942e57..c3ba05f 100755 (executable)
--- a/mkfedora
+++ b/mkfedora
@@ -1,6 +1,6 @@
 #!/bin/bash
 #
-# Builds a Fedora Core reference image. Requires the build server to
+# Builds a Fedora reference image. Requires the build server to
 # host a local yum repository in one of:
 #
 # /usr/share/mirrors/fedora
@@ -13,7 +13,7 @@
 # Mark Huang <mlhuang@cs.princeton.edu>
 # Copyright (C) 2004-2006 The Trustees of Princeton University
 #
-# $Id: mkfedora,v 1.15 2006/07/06 02:44:22 mlhuang Exp $
+# $Id: mkfedora,v 1.33 2007/08/31 02:23:08 mef Exp $
 #
 
 export PATH=/sbin:/bin:/usr/sbin:/usr/bin
@@ -23,12 +23,14 @@ verbose=0
 
 # Default yum repositories to try
 mirrors=(
-file:///usr/share/mirrors/fedora
-file:///var/www/html/mirrors/fedora
+file:///data/fedora
 ftp://smoke.cs.princeton.edu/pub/mirrors/fedora
-ftp://128.112.137.30/pub/mirrors/fedora
-http://coblitz.planet-lab.org/pub/fedora
+http://coblitz.codeen.org/coblitz.planet-lab.org/pub/fedora
 ftp://mirror.cs.princeton.edu/pub/mirrors/fedora
+http://coblitz.planet-lab.org/pub/fedora
+ftp://mirror.stanford.edu/pub/mirrors/fedora
+ftp://rpmfind.net/linux/fedora
+http://fedora.laptop.org/fedora-linux-releases
 )
 
 # Release and architecture to install
@@ -47,9 +49,12 @@ exclude=()
 # Exclude kernel* (and related) packages from all repositories except bootstrap
 exclude_kernel=
 
-# Local overrides (usually a better set of mirrors to choose from)
-if [ -f /etc/planetlab/mkfedora.conf ] ; then
-    . /etc/planetlab/mkfedora.conf
+# PlanetLab development environment
+if [ -f /etc/planetlab/plc_config ] ; then
+    . /etc/planetlab/plc_config
+    if [ -n "$PLC_DEVEL_FEDORA_URL" ] ; then
+       mirrors=($PLC_DEVEL_FEDORA_URL)
+    fi
 fi
 
 usage()
@@ -129,15 +134,25 @@ fetch ()
 }
 
 for mirror in "${mirrors[@]}" ; do
-    for baseurl in \
-       $mirror/linux/core/$releasever/$basearch/os \
-       $mirror/core/$releasever/$basearch/os \
-       $mirror/$releasever/$basearch/os ; do
-       if fetch $baseurl/repodata/repomd.xml >/dev/null ; then
-           break
-       fi
-       unset baseurl
-    done
+    if [ $releasever -ge 7 ] ; then
+       for baseurl in \
+               $mirror/$releasever/Everything/$basearch/os ; do
+               if fetch $baseurl/repodata/repomd.xml >/dev/null ; then
+                   break
+               fi
+               unset baseurl
+        done
+    else
+       for baseurl in \
+               $mirror/linux/core/$releasever/$basearch/os \
+               $mirror/core/$releasever/$basearch/os \
+               $mirror/$releasever/$basearch/os ; do
+               if fetch $baseurl/repodata/repomd.xml >/dev/null ; then
+                       break
+               fi
+               unset baseurl
+       done
+    fi
     if [ -n "$baseurl" ] ; then
        break
     fi
@@ -145,14 +160,23 @@ for mirror in "${mirrors[@]}" ; do
 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
-       echo $mirror/linux/core
-       echo $mirror/core
-       echo $mirror
-    done
+    if [ $releasever -ge 7 ] ; then
+       echo "Error: $releasever/Everything/$basearch/os/repodata/repomd.xml"
+       echo "       could not be found in any of the following locations:"
+       echo
+       for mirror in ${mirrors[@]} ; do
+               echo $mirror/linux
+       done
+    else
+       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
+               echo $mirror/linux/core
+               echo $mirror/core
+               echo $mirror
+       done
+    fi
     echo
     usage
 fi
@@ -164,34 +188,11 @@ if [ $verbose -eq 0 ] ; then
     exec 2>/dev/null
 fi
 
-# Minimally initialize /dev in reference image. If installed, the dev
-# or udev RPMs will fill in the rest.
-mkdir -p $vroot/dev
-mknod -m 666 $vroot/dev/null c 1 3
-mknod -m 666 $vroot/dev/zero c 1 5
-mknod -m 666 $vroot/dev/full c 1 7
-mknod -m 644 $vroot/dev/random c 1 8
-mknod -m 644 $vroot/dev/urandom c 1 9
-mknod -m 666 $vroot/dev/tty c 5 0
-mknod -m 666 $vroot/dev/ptmx c 5 2
-# For bash command substitution
-ln -nsf ../proc/self/fd $vroot/dev/fd
-# For df and linuxconf
-touch $vroot/dev/hdv1
-# For mkinitrd (in case a kernel is being installed)
-for i in $(seq 0 7) ; do
-    mknod -m 640 $vroot/dev/loop$i b 7 $i
-done
-
 # Do not tolerate errors
 set -e
 
-# Mount /dev/pts in reference image
-mkdir -p $vroot/dev/pts
+# Mount /dev/pts and /dev/shm in reference image
 mount -t devpts none $vroot/dev/pts
-
-# Mount /dev/shm in reference image
-mkdir -p $vroot/dev/shm
 mount -t tmpfs none $vroot/dev/shm
 
 # Mount /proc in reference image
@@ -200,13 +201,13 @@ mount -t proc none $vroot/proc
 
 cleanup ()
 {
-    umount $vroot/proc
-    umount $vroot/dev/shm
-    umount $vroot/dev/pts
+    umount -l $vroot/proc
+    umount -l $vroot/dev/shm
+    umount -l $vroot/dev/pts
 }
 
 # Clean up before exiting if anything goes wrong
-trap "cleanup" ERR
+trap "cleanup" ERR INT
 
 # Create a dummy /etc/fstab in reference image
 mkdir -p $vroot/etc
@@ -243,6 +244,12 @@ 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
+       corename="Core "
+else
+       corename=""
+fi
+
 cat >$vroot/etc/yum.conf <<EOF
 [main]
 cachedir=/var/cache/yum
@@ -260,7 +267,7 @@ gpgcheck=0
 reposdir=/dev/null
 
 [base]
-name=Fedora Core $releasever - $basearch - base
+name=Fedora ${corename}${releasever} - $basearch - base
 baseurl=$baseurl/
 $exclude_kernel
 EOF
@@ -269,12 +276,13 @@ 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 fetch $optionalurl/repodata/repomd.xml ; then
            cat >>$vroot/etc/yum.conf <<EOF
 
 [$(basename $optional)]
-name=Fedora Core $releasever - $basearch - $(basename $optional)
+name=Fedora ${corename}${releasever} - $basearch - $(basename $optional)
 baseurl=$optionalurl/
 $exclude_kernel
 EOF
@@ -290,14 +298,14 @@ 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 $RPM_RPMS_DIR
+       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 $groupfile $RPM_RPMS_DIR
+       createrepo --quiet $groupfile $RPM_RPMS_DIR
     fi
     # If run under sudo, allow user to delete the headers/ and
     # repodata/ directories.
@@ -324,15 +332,22 @@ yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes install glibc
 
 # Go, baby, go
 if [ ${#packages[*]} -gt 0 ] ; then
-    echo "* Installing optional packages" >&3
-    yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes \
-       install "${packages[@]}"
+   echo "* Installing optional packages" "${packages[@]}" >&3
+   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
-    echo "* Installing optional groups" >&3
-    yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes \
-       groupinstall "${groups[@]}"
+   ## call yum sequentially to get finer-grained info on dependencies
+   for grp in "${groups[@]}" ; do
+      echo "* Installing optional group $grp" >&3
+      yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes \
+       groupinstall "$grp"
+   done
 fi
 
 # FC2 dev %preinstall checks /proc/mounts to make sure that /dev is
@@ -365,6 +380,10 @@ if [ -f $vroot/usr/share/zoneinfo/UTC -a -f $vroot/etc/localtime ] ; then
     ln -s /usr/share/zoneinfo/UTC $vroot/etc/localtime
 fi
 
+
+# remove trap handler, as we are about to call it directly.
+trap - ERR INT
+
 # Clean up
 cleanup