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
19 export PATH=/sbin:/bin:/usr/sbin:/usr/bin
24 # Default yum repositories to try
27 http://localhost/fedora
28 http://build.planet-lab.org/fedora
29 http://coblitz.codeen.org/coblitz.planet-lab.org/pub/fedora
30 ftp://mirror.cs.princeton.edu/pub/mirrors/fedora
31 ftp://mirror.stanford.edu/pub/mirrors/fedora
32 ftp://rpmfind.net/linux/fedora
35 # Release and architecture to install
39 # Yum groups to install
48 # Exclude kernel* (and related) packages from all repositories except bootstrap
51 # PlanetLab development environment
52 if [ -f /etc/planetlab/plc_config ] ; then
53 . /etc/planetlab/plc_config
54 if [ -n "$PLC_DEVEL_FEDORA_URL" ] ; then
55 mirrors=($PLC_DEVEL_FEDORA_URL)
61 echo "Usage: mkfedora [OPTION]... [basedir]"
62 echo " -l url Fedora mirror location. Defaults to try:"
63 for mirror in "${mirrors[@]}" ; do
66 echo " -r release Fedora release number (default: $releasever)"
67 echo " -a arch Fedora architecture (default: $basearch)"
68 echo " -g group1 -g group2 ..."
69 echo " Yumgroups to install (default: none)"
70 echo " -p package1 -p package2 ..."
71 echo " Additional packages to install (default: none)"
72 echo " -x package1 -x package2 ..."
73 echo " Packages to exclude (default: none)"
74 echo " -k Exclude kernel* packages from all repositories except bootstrap"
76 echo " -h This message"
81 while getopts "l:r:a:g:p:x:kvh" opt ; do
84 if echo $OPTARG | grep -q -i '^\(file\|http[s]*\)://' ; then
87 mirrors=(file://$OPTARG)
97 groups[${#groups[*]}]="$OPTARG"
100 packages[${#packages[*]}]="$OPTARG"
103 exclude[${#exclude[*]}]="$OPTARG"
106 exclude_kernel="exclude=kernel* ulogd iptables"
118 shift $(($OPTIND - 1))
119 if [ ! -d "$1" ] ; then
123 vroot=$(cd $1 && pwd -P)
125 if [ $UID -ne 0 ] ; then
126 echo "Error: You must run this script as root."
132 curl --fail --silent --max-time 60 "$1"
135 # hard to find two mirrors with a similar layout
136 # set list of attempted locations according to releasever
137 if [ $releasever -ge 7 ] ; then
139 $releasever/Everything/$basearch/os
140 core/$releasever/Everything/$basearch/os \
141 linux/core/$releasever/$basearch/os
145 linux/core/$releasever/$basearch/os
146 core/$releasever/$basearch/os
147 $releasever/$basearch/os
151 for mirror in "${mirrors[@]}" ; do
152 for attempt in $attempts; do
153 baseurl=$mirror/$attempt
154 if fetch $baseurl/repodata/repomd.xml >/dev/null ; then
159 if [ -n "$baseurl" ] ; then
165 if [ -z "$baseurl" ] ; then
166 echo "Error: $releasever/$basearch/os/repodata/repomd.xml"
167 echo " could not be found in any of the following locations:"
169 for mirror in ${mirrors[@]} ; do
170 for attempt in $attempts ; do
171 echo $mirror/$attempt
180 if [ $verbose -eq 0 ] ; then
185 # Do not tolerate errors
188 # Mount /dev/pts and /dev/shm in reference image
189 mount -t devpts none $vroot/dev/pts
190 mount -t tmpfs none $vroot/dev/shm
192 # make rpms ignore installing stuff to /proc
193 mkdir -p $vroot/etc/rpm
194 # Because of https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=52725
195 # you have to use at least one language beside 'C'
196 echo "%_install_langs C:de:en:es:fr" > $vroot/etc/rpm/macros
197 echo "%_netsharedpath /proc" >> $vroot/etc/rpm/macros
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 /var/lib dirs for yum & rpm
213 mkdir -p $vroot/var/lib/yum
214 mkdir -p $vroot/var/lib/rpm
215 mkdir -p $vroot/usr/share/info
217 # Create a dummy /etc/fstab in reference image
219 cat >$vroot/etc/fstab <<EOF
220 # This fake fstab exists only to please df and linuxconf.
221 /dev/hdv1 / ext2 defaults 1 1
223 cp $vroot/etc/fstab $vroot/etc/mtab
225 # Prevent all locales from being installed in reference image
226 mkdir -p $vroot/etc/rpm
227 cat >$vroot/etc/rpm/macros <<EOF
228 %_install_langs en_US:en
230 %__file_context_path /dev/null
233 # Necessary for some scripts
234 mkdir -p $vroot/etc/sysconfig
235 echo "NETWORKING=yes" > $vroot/etc/sysconfig/network
237 # Trick rpm and yum, who read the real root /etc/rpm/macros file
238 # rather than the one installed in the reference image, despite what
239 # you might expect the --root and --installroot options to mean. Both
240 # programs always read $HOME/.rpmmacros.
241 export HOME=$vroot/tmp
243 cp $vroot/etc/rpm/macros $vroot/tmp/.rpmmacros
245 # Initialize RPM database in reference image
246 mkdir -p $vroot/var/lib/rpm
247 rpm --root $vroot --initdb
248 rpm --root $vroot --import $baseurl/RPM-GPG-KEY-fedora
250 # Initialize yum in reference image
251 mkdir -p $vroot/var/cache/yum $vroot/var/log
252 if [ $releasever -lt 7 ] ; then
258 cat >$vroot/etc/yum.conf <<EOF
260 cachedir=/var/cache/yum
262 logfile=/var/log/yum.log
264 distroverpkg=redhat-release
270 # Prevent yum-2.4 from loading additional repository definitions
271 # (e.g., from /etc/yum.repos.d/)
275 name=Fedora ${corename}${releasever} - $basearch - base
280 for optional in updates extras ; do
282 $mirror/linux/core/$optional/$releasever/$basearch \
283 $mirror/core/$optional/$releasever/$basearch \
284 $mirror/linux/$optional/$releasever/$basearch \
285 $mirror/$optional/$releasever/$basearch ; do
286 if fetch $optionalurl/repodata/repomd.xml ; then
287 cat >>$vroot/etc/yum.conf <<EOF
289 [$(basename $optional)]
290 name=Fedora ${corename}${releasever} - $basearch - $(basename $optional)
291 baseurl=$optionalurl/
299 # If we are being built as part of an automated RPM build, solve the
300 # bootstrap problem by including any just built packages in the yum
301 # configuration. This cooperates with the PlanetLab build system.
302 if [ -n "$RPM_BUILD_DIR" ] ; then
303 RPM_RPMS_DIR=$(cd $(dirname $RPM_BUILD_DIR)/RPMS && pwd -P)
305 if [ -x /usr/bin/yum-arch ] ; then
306 yum-arch -q $RPM_RPMS_DIR
309 if [ -x /usr/bin/createrepo ] ; then
310 if [ -f $RPM_RPMS_DIR/yumgroups.xml ] ; then
311 groupfile="-g yumgroups.xml"
313 createrepo --quiet $groupfile $RPM_RPMS_DIR
315 # If run under sudo, allow user to delete the headers/ and
316 # repodata/ directories.
317 if [ -n "$SUDO_USER" ] ; then
318 chown -R $SUDO_USER $RPM_RPMS_DIR
320 cat >>$vroot/etc/yum.conf <<EOF
323 name=Bootstrap - $basearch - $RPM_RPMS_DIR/
324 baseurl=file://$RPM_RPMS_DIR/
329 for package in "${exclude[@]}" ; do
330 excludes="$excludes --exclude=$package"
333 # glibc must be specified explicitly for the correct arch to be
335 echo "* Installing glibc" >&3
336 yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes install glibc
339 if [ ${#packages[*]} -gt 0 ] ; then
340 echo "* Installing optional packages" "${packages[@]}" >&3
341 yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes \
342 install "${packages[@]}"
343 if ! rpm --root $vroot -q "${packages[@]}" >/dev/null ; then
344 echo "* Warning: Missing packages"
345 rpm --root $vroot -q "${packages[@]}" | grep "not installed"
349 if [ ${#groups[*]} -gt 0 ] ; then
350 ## call yum sequentially to get finer-grained info on dependencies
351 for grp in "${groups[@]}" ; do
352 echo "* Installing optional group $grp" >&3
353 yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes \
358 # FC2 dev %preinstall checks /proc/mounts to make sure that /dev is
359 # not currently mounted as devfs. If it thinks it is, it will refuse
360 # to install the package. On a modern system running udev that mounts
361 # /dev as tmpfs, this check fails. Since we are installing into a
362 # chroot, whether /dev is mounted on the host system or not doesn't
363 # matter. If dev was explicitly mentioned in the packages list, force
365 if [ "$releasever" = "2" ] ; then
366 for package in "${packages[@]}" ; do
367 if [ "$package" = "dev" ] && ! rpm --root $vroot -q dev >/dev/null 2>&1 ; then
368 rpm --root $vroot -Uvh --noscripts $baseurl/Fedora/RPMS/dev-3.3.13-1.i386.rpm
375 echo "* Cleaning up" >&3
376 yum -c $vroot/etc/yum.conf --installroot=$vroot -y \
380 rm -f $vroot/var/lib/rpm/__db*
382 # Set time zone to UTC
383 if [ -f $vroot/usr/share/zoneinfo/UTC -a -f $vroot/etc/localtime ] ; then
384 rm -f $vroot/etc/localtime
385 ln -s /usr/share/zoneinfo/UTC $vroot/etc/localtime
389 # remove trap handler, as we are about to call it directly.