# Mark Huang <mlhuang@cs.princeton.edu>
# Copyright (C) 2004-2006 The Trustees of Princeton University
#
-# $Id: mkfedora,v 1.5 2006/03/31 21:17:49 mlhuang Exp $
+# $Id: mkfedora,v 1.13 2006/04/26 01:59:59 mlhuang Exp $
#
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
)
# Release and architecture to install
-releasever=2
+releasever=4
basearch=i386
# Yum groups to install
# Packages to install
packages=()
+# Packages to exclude
+exclude=()
+
+# Exclude kernel* (and related) packages from all repositories except bootstrap
+exclude_kernel=
+
usage()
{
echo "Usage: mkfedora [OPTION]... [basedir]"
echo " Yumgroups to install (default: none)"
echo " -p package1 -p package2 ..."
echo " Additional packages to install (default: none)"
+ echo " -x package1 -x package2 ..."
+ echo " Packages to exclude (default: none)"
+ echo " -k Exclude kernel* packages from all repositories except bootstrap"
echo " -v Be verbose"
echo " -h This message"
exit 1
}
# Get options
-while getopts "l:r:a:g:p:vh" opt ; do
+while getopts "l:r:a:g:p:x:kvh" opt ; do
case $opt in
l)
if echo $OPTARG | grep -q -i '^\(file\|http[s]*\)://' ; then
p)
packages[${#packages[*]}]="$OPTARG"
;;
+ x)
+ exclude[${#exclude[*]}]="$OPTARG"
+ ;;
+ k)
+ exclude_kernel="exclude=kernel* ulogd iptables"
+ ;;
v)
verbose=1
set -x
exit 1
fi
-# Old versions of curl don't understand file:// URLs
fetch ()
{
- url=$1
- if curl --fail --silent --max-time 60 $url ; then
- return 0
- else
- if [ -f ${url#file://} ] ; then
- cat ${url#file://}
- return 0
- fi
- fi
- return 1
+ curl --fail --silent --max-time 60 "$1"
}
for mirror in "${mirrors[@]}" ; do
- baseurl=$mirror/linux/core/$releasever/$basearch/os
- if fetch $baseurl/repodata/repomd.xml >/dev/null ; then
+ 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 [ -n "$baseurl" ] ; then
break
fi
unset baseurl
done
if [ -z "$baseurl" ] ; then
- echo "Error: linux/core/$releasever/$basearch/os/repodata/repomd.xml"
+ 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
echo
exec 2>/dev/null
fi
-# Scratch space
-tmp=$(mktemp -d /tmp/mkfedora.XXXXXX)
-
# Minimally initialize /dev in reference image. If installed, the dev
# or udev RPMs will fill in the rest.
mkdir -p $vroot/dev
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
umount $vroot/proc
umount $vroot/dev/shm
umount $vroot/dev/pts
- rm -rf $tmp
}
# Clean up before exiting if anything goes wrong
-trap "cleanup; exit 1" ERR
+trap "cleanup" ERR
# Create a dummy /etc/fstab in reference image
mkdir -p $vroot/etc
[base]
name=Fedora Core $releasever - $basearch - base
baseurl=$baseurl/
+$exclude_kernel
EOF
-for optional in core/updates extras ; do
- if fetch $mirror/linux/$optional/$releasever/$basearch/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/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)
-baseurl=$mirror/linux/$optional/$releasever/$basearch/
+baseurl=$optionalurl/
+$exclude_kernel
EOF
- fi
+ break
+ fi
+ done
done
# If we are being built as part of an automated RPM build, solve the
EOF
fi
-# glibc must be specified explicitly for the correct arch to be chosen.
+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" >&3
-yum -c $vroot/etc/yum.conf --installroot=$vroot -y install glibc
+yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes install glibc
# Go, baby, go
-if [ ${#groups[*]} -gt 0 ] ; then
- echo "* Installing optional groups" >&3
- yum -c $vroot/etc/yum.conf --installroot=$vroot -y \
- groupinstall "${groups[@]}"
-fi
-
if [ ${#packages[*]} -gt 0 ] ; then
echo "* Installing optional packages" >&3
- yum -c $vroot/etc/yum.conf --installroot=$vroot -y \
+ yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes \
install "${packages[@]}"
fi
+if [ ${#groups[*]} -gt 0 ] ; then
+ echo "* Installing optional groups" >&3
+ yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes \
+ groupinstall "${groups[@]}"
+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
rm -f $vroot/var/lib/rpm/__db*
# Set time zone to UTC
-if [ -f /usr/share/zoneinfo/UTC -a -f /etc/localtime ] ; then
- rm -f /etc/localtime
- ln -s /usr/share/zoneinfo/UTC /etc/localtime
+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
# Clean up