#!/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
# Mark Huang <mlhuang@cs.princeton.edu>
# Copyright (C) 2004-2006 The Trustees of Princeton University
#
-# $Id: mkfedora,v 1.29 2007/08/24 04:47:00 mef Exp $
+# $Id: mkfedora 1073 2007-11-15 09:56:03Z thierry $
#
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
# Default yum repositories to try
mirrors=(
file:///data/fedora
+http://localhost/fedora
ftp://smoke.cs.princeton.edu/pub/mirrors/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
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="
+$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
+
for mirror in "${mirrors[@]}" ; do
- 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
+ for attempt in $attempts; do
+ baseurl=$mirror/$attempt
+ if fetch $baseurl/repodata/repomd.xml >/dev/null ; then
+ break
+ fi
+ unset baseurl
+ done
if [ -n "$baseurl" ] ; then
break
fi
done
if [ -z "$baseurl" ] ; then
- 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 "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
usage
fi
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
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 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
+
# Create a dummy /etc/fstab in reference image
mkdir -p $vroot/etc
cat >$vroot/etc/fstab <<EOF
# 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
reposdir=/dev/null
[base]
-name=Fedora Core $releasever - $basearch - base
+name=Fedora ${corename}${releasever} - $basearch - base
baseurl=$baseurl/
$exclude_kernel
EOF
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
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