3 # Builds a Fedora reference image. Requires the build server to
4 # host a local yum repository in one of:
6 # /usr/share/mirrors/fedora
7 # /var/www/html/mirrors/fedora
9 # Otherwise, tries using CoBlitz:
11 # http://coblitz.planet-lab.org/pub/fedora
13 # Mark Huang <mlhuang@cs.princeton.edu>
14 # Copyright (C) 2004-2006 The Trustees of Princeton University
16 # $Id: mkfedora,v 1.33 2007/08/31 02:23:08 mef Exp $
19 export PATH=/sbin:/bin:/usr/sbin:/usr/bin
24 # Default yum repositories to try
27 ftp://smoke.cs.princeton.edu/pub/mirrors/fedora
28 http://coblitz.codeen.org/coblitz.planet-lab.org/pub/fedora
29 ftp://mirror.cs.princeton.edu/pub/mirrors/fedora
30 http://coblitz.planet-lab.org/pub/fedora
31 ftp://mirror.stanford.edu/pub/mirrors/fedora
32 ftp://rpmfind.net/linux/fedora
33 http://fedora.laptop.org/fedora-linux-releases
36 # Release and architecture to install
40 # Yum groups to install
49 # Exclude kernel* (and related) packages from all repositories except bootstrap
52 # PlanetLab development environment
53 if [ -f /etc/planetlab/plc_config ] ; then
54 . /etc/planetlab/plc_config
55 if [ -n "$PLC_DEVEL_FEDORA_URL" ] ; then
56 mirrors=($PLC_DEVEL_FEDORA_URL)
62 echo "Usage: mkfedora [OPTION]... [basedir]"
63 echo " -l url Fedora mirror location. Defaults to try:"
64 for mirror in "${mirrors[@]}" ; do
67 echo " -r release Fedora release number (default: $releasever)"
68 echo " -a arch Fedora architecture (default: $basearch)"
69 echo " -g group1 -g group2 ..."
70 echo " Yumgroups to install (default: none)"
71 echo " -p package1 -p package2 ..."
72 echo " Additional packages to install (default: none)"
73 echo " -x package1 -x package2 ..."
74 echo " Packages to exclude (default: none)"
75 echo " -k Exclude kernel* packages from all repositories except bootstrap"
77 echo " -h This message"
82 while getopts "l:r:a:g:p:x:kvh" opt ; do
85 if echo $OPTARG | grep -q -i '^\(file\|http[s]*\)://' ; then
88 mirrors=(file://$OPTARG)
98 groups[${#groups[*]}]="$OPTARG"
101 packages[${#packages[*]}]="$OPTARG"
104 exclude[${#exclude[*]}]="$OPTARG"
107 exclude_kernel="exclude=kernel* ulogd iptables"
119 shift $(($OPTIND - 1))
120 if [ ! -d "$1" ] ; then
124 vroot=$(cd $1 && pwd -P)
126 if [ $UID -ne 0 ] ; then
127 echo "Error: You must run this script as root."
133 curl --fail --silent --max-time 60 "$1"
136 for mirror in "${mirrors[@]}" ; do
137 if [ $releasever -ge 7 ] ; then
139 $mirror/$releasever/Everything/$basearch/os ; do
140 if fetch $baseurl/repodata/repomd.xml >/dev/null ; then
147 $mirror/linux/core/$releasever/$basearch/os \
148 $mirror/core/$releasever/$basearch/os \
149 $mirror/$releasever/$basearch/os ; do
150 if fetch $baseurl/repodata/repomd.xml >/dev/null ; then
156 if [ -n "$baseurl" ] ; then
162 if [ -z "$baseurl" ] ; then
163 if [ $releasever -ge 7 ] ; then
164 echo "Error: $releasever/Everything/$basearch/os/repodata/repomd.xml"
165 echo " could not be found in any of the following locations:"
167 for mirror in ${mirrors[@]} ; do
171 echo "Error: $releasever/$basearch/os/repodata/repomd.xml"
172 echo " could not be found in any of the following locations:"
174 for mirror in ${mirrors[@]} ; do
175 echo $mirror/linux/core
186 if [ $verbose -eq 0 ] ; then
191 # Do not tolerate errors
194 # Mount /dev/pts and /dev/shm in reference image
195 mount -t devpts none $vroot/dev/pts
196 mount -t tmpfs none $vroot/dev/shm
198 # Mount /proc in reference image
200 mount -t proc none $vroot/proc
204 umount -l $vroot/proc
205 umount -l $vroot/dev/shm
206 umount -l $vroot/dev/pts
209 # Clean up before exiting if anything goes wrong
210 trap "cleanup" ERR INT
212 # Create a dummy /etc/fstab in reference image
214 cat >$vroot/etc/fstab <<EOF
215 # This fake fstab exists only to please df and linuxconf.
216 /dev/hdv1 / ext2 defaults 1 1
218 cp $vroot/etc/fstab $vroot/etc/mtab
220 # Prevent all locales from being installed in reference image
221 mkdir -p $vroot/etc/rpm
222 cat >$vroot/etc/rpm/macros <<EOF
223 %_install_langs en_US:en
225 %__file_context_path /dev/null
228 # Necessary for some scripts
229 mkdir -p $vroot/etc/sysconfig
230 echo "NETWORKING=yes" > $vroot/etc/sysconfig/network
232 # Trick rpm and yum, who read the real root /etc/rpm/macros file
233 # rather than the one installed in the reference image, despite what
234 # you might expect the --root and --installroot options to mean. Both
235 # programs always read $HOME/.rpmmacros.
236 export HOME=$vroot/tmp
238 cp $vroot/etc/rpm/macros $vroot/tmp/.rpmmacros
240 # Initialize RPM database in reference image
241 mkdir -p $vroot/var/lib/rpm
242 rpm --root $vroot --initdb
243 rpm --root $vroot --import $baseurl/RPM-GPG-KEY-fedora
245 # Initialize yum in reference image
246 mkdir -p $vroot/var/cache/yum $vroot/var/log
247 if [ $releasever -lt 7 ] ; then
253 cat >$vroot/etc/yum.conf <<EOF
255 cachedir=/var/cache/yum
257 logfile=/var/log/yum.log
259 distroverpkg=redhat-release
265 # Prevent yum-2.4 from loading additional repository definitions
266 # (e.g., from /etc/yum.repos.d/)
270 name=Fedora ${corename}${releasever} - $basearch - base
275 for optional in updates extras ; do
277 $mirror/linux/core/$optional/$releasever/$basearch \
278 $mirror/core/$optional/$releasever/$basearch \
279 $mirror/linux/$optional/$releasever/$basearch \
280 $mirror/$optional/$releasever/$basearch ; do
281 if fetch $optionalurl/repodata/repomd.xml ; then
282 cat >>$vroot/etc/yum.conf <<EOF
284 [$(basename $optional)]
285 name=Fedora ${corename}${releasever} - $basearch - $(basename $optional)
286 baseurl=$optionalurl/
294 # If we are being built as part of an automated RPM build, solve the
295 # bootstrap problem by including any just built packages in the yum
296 # configuration. This cooperates with the PlanetLab build system.
297 if [ -n "$RPM_BUILD_DIR" ] ; then
298 RPM_RPMS_DIR=$(cd $(dirname $RPM_BUILD_DIR)/RPMS && pwd -P)
300 if [ -x /usr/bin/yum-arch ] ; then
301 yum-arch -q $RPM_RPMS_DIR
304 if [ -x /usr/bin/createrepo ] ; then
305 if [ -f $RPM_RPMS_DIR/yumgroups.xml ] ; then
306 groupfile="-g yumgroups.xml"
308 createrepo --quiet $groupfile $RPM_RPMS_DIR
310 # If run under sudo, allow user to delete the headers/ and
311 # repodata/ directories.
312 if [ -n "$SUDO_USER" ] ; then
313 chown -R $SUDO_USER $RPM_RPMS_DIR
315 cat >>$vroot/etc/yum.conf <<EOF
318 name=Bootstrap - $basearch - $RPM_RPMS_DIR/
319 baseurl=file://$RPM_RPMS_DIR/
324 for package in "${exclude[@]}" ; do
325 excludes="$excludes --exclude=$package"
328 # glibc must be specified explicitly for the correct arch to be
330 echo "* Installing glibc" >&3
331 yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes install glibc
334 if [ ${#packages[*]} -gt 0 ] ; then
335 echo "* Installing optional packages" "${packages[@]}" >&3
336 yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes \
337 install "${packages[@]}"
338 if ! rpm --root $vroot -q "${packages[@]}" >/dev/null ; then
339 echo "* Warning: Missing packages"
340 rpm --root $vroot -q "${packages[@]}" | grep "not installed"
344 if [ ${#groups[*]} -gt 0 ] ; then
345 ## call yum sequentially to get finer-grained info on dependencies
346 for grp in "${groups[@]}" ; do
347 echo "* Installing optional group $grp" >&3
348 yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes \
353 # FC2 dev %preinstall checks /proc/mounts to make sure that /dev is
354 # not currently mounted as devfs. If it thinks it is, it will refuse
355 # to install the package. On a modern system running udev that mounts
356 # /dev as tmpfs, this check fails. Since we are installing into a
357 # chroot, whether /dev is mounted on the host system or not doesn't
358 # matter. If dev was explicitly mentioned in the packages list, force
360 if [ "$releasever" = "2" ] ; then
361 for package in "${packages[@]}" ; do
362 if [ "$package" = "dev" ] && ! rpm --root $vroot -q dev >/dev/null 2>&1 ; then
363 rpm --root $vroot -Uvh --noscripts $baseurl/Fedora/RPMS/dev-3.3.13-1.i386.rpm
370 echo "* Cleaning up" >&3
371 yum -c $vroot/etc/yum.conf --installroot=$vroot -y \
375 rm -f $vroot/var/lib/rpm/__db*
377 # Set time zone to UTC
378 if [ -f $vroot/usr/share/zoneinfo/UTC -a -f $vroot/etc/localtime ] ; then
379 rm -f $vroot/etc/localtime
380 ln -s /usr/share/zoneinfo/UTC $vroot/etc/localtime
384 # remove trap handler, as we are about to call it directly.