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 ftp://smoke.cs.princeton.edu/pub/mirrors/fedora
29 http://coblitz.codeen.org/coblitz.planet-lab.org/pub/fedora
30 ftp://mirror.cs.princeton.edu/pub/mirrors/fedora
31 http://coblitz.planet-lab.org/pub/fedora
32 ftp://mirror.stanford.edu/pub/mirrors/fedora
33 ftp://rpmfind.net/linux/fedora
34 http://fedora.laptop.org/fedora-linux-releases
37 # Release and architecture to install
41 # Yum groups to install
50 # Exclude kernel* (and related) packages from all repositories except bootstrap
53 # PlanetLab development environment
54 if [ -f /etc/planetlab/plc_config ] ; then
55 . /etc/planetlab/plc_config
56 if [ -n "$PLC_DEVEL_FEDORA_URL" ] ; then
57 mirrors=($PLC_DEVEL_FEDORA_URL)
63 echo "Usage: mkfedora [OPTION]... [basedir]"
64 echo " -l url Fedora mirror location. Defaults to try:"
65 for mirror in "${mirrors[@]}" ; do
68 echo " -r release Fedora release number (default: $releasever)"
69 echo " -a arch Fedora architecture (default: $basearch)"
70 echo " -g group1 -g group2 ..."
71 echo " Yumgroups to install (default: none)"
72 echo " -p package1 -p package2 ..."
73 echo " Additional packages to install (default: none)"
74 echo " -x package1 -x package2 ..."
75 echo " Packages to exclude (default: none)"
76 echo " -k Exclude kernel* packages from all repositories except bootstrap"
78 echo " -h This message"
83 while getopts "l:r:a:g:p:x:kvh" opt ; do
86 if echo $OPTARG | grep -q -i '^\(file\|http[s]*\)://' ; then
89 mirrors=(file://$OPTARG)
99 groups[${#groups[*]}]="$OPTARG"
102 packages[${#packages[*]}]="$OPTARG"
105 exclude[${#exclude[*]}]="$OPTARG"
108 exclude_kernel="exclude=kernel* ulogd iptables"
120 shift $(($OPTIND - 1))
121 if [ ! -d "$1" ] ; then
125 vroot=$(cd $1 && pwd -P)
127 if [ $UID -ne 0 ] ; then
128 echo "Error: You must run this script as root."
134 curl --fail --silent --max-time 60 "$1"
137 # hard to find two mirrors with a similar layout
138 # set list of attempted locations according to releasever
139 if [ $releasever -ge 7 ] ; then
141 $releasever/Everything/$basearch/os
142 core/$releasever/Everything/$basearch/os \
143 linux/core/$releasever/$basearch/os
147 linux/core/$releasever/$basearch/os
148 core/$releasever/$basearch/os
149 $releasever/$basearch/os
153 for mirror in "${mirrors[@]}" ; do
154 for attempt in $attempts; do
155 baseurl=$mirror/$attempt
156 if fetch $baseurl/repodata/repomd.xml >/dev/null ; then
161 if [ -n "$baseurl" ] ; then
167 if [ -z "$baseurl" ] ; then
168 echo "Error: $releasever/$basearch/os/repodata/repomd.xml"
169 echo " could not be found in any of the following locations:"
171 for mirror in ${mirrors[@]} ; do
172 for attempt in $attempts ; do
173 echo $mirror/$attempt
182 if [ $verbose -eq 0 ] ; then
187 # Do not tolerate errors
190 # Mount /dev/pts and /dev/shm in reference image
191 mount -t devpts none $vroot/dev/pts
192 mount -t tmpfs none $vroot/dev/shm
194 # Mount /proc in reference image
196 mount -t proc none $vroot/proc
200 umount -l $vroot/proc
201 umount -l $vroot/dev/shm
202 umount -l $vroot/dev/pts
205 # Clean up before exiting if anything goes wrong
206 trap "cleanup" ERR INT
208 # Create a /var/lib dirs for yum & rpm
209 mkdir -p $vroot/var/lib/yum
210 mkdir -p $vroot/var/lib/rpm
211 mkdir -p $vroot/usr/share/info
213 # Create a dummy /etc/fstab in reference image
215 cat >$vroot/etc/fstab <<EOF
216 # This fake fstab exists only to please df and linuxconf.
217 /dev/hdv1 / ext2 defaults 1 1
219 cp $vroot/etc/fstab $vroot/etc/mtab
221 # Prevent all locales from being installed in reference image
222 mkdir -p $vroot/etc/rpm
223 cat >$vroot/etc/rpm/macros <<EOF
224 %_install_langs en_US:en
226 %__file_context_path /dev/null
229 # Necessary for some scripts
230 mkdir -p $vroot/etc/sysconfig
231 echo "NETWORKING=yes" > $vroot/etc/sysconfig/network
233 # Trick rpm and yum, who read the real root /etc/rpm/macros file
234 # rather than the one installed in the reference image, despite what
235 # you might expect the --root and --installroot options to mean. Both
236 # programs always read $HOME/.rpmmacros.
237 export HOME=$vroot/tmp
239 cp $vroot/etc/rpm/macros $vroot/tmp/.rpmmacros
241 # Initialize RPM database in reference image
242 mkdir -p $vroot/var/lib/rpm
243 rpm --root $vroot --initdb
244 rpm --root $vroot --import $baseurl/RPM-GPG-KEY-fedora
246 # Initialize yum in reference image
247 mkdir -p $vroot/var/cache/yum $vroot/var/log
248 if [ $releasever -lt 7 ] ; then
254 cat >$vroot/etc/yum.conf <<EOF
256 cachedir=/var/cache/yum
258 logfile=/var/log/yum.log
260 distroverpkg=redhat-release
266 # Prevent yum-2.4 from loading additional repository definitions
267 # (e.g., from /etc/yum.repos.d/)
271 name=Fedora ${corename}${releasever} - $basearch - base
276 for optional in updates extras ; do
278 $mirror/linux/core/$optional/$releasever/$basearch \
279 $mirror/core/$optional/$releasever/$basearch \
280 $mirror/linux/$optional/$releasever/$basearch \
281 $mirror/$optional/$releasever/$basearch ; do
282 if fetch $optionalurl/repodata/repomd.xml ; then
283 cat >>$vroot/etc/yum.conf <<EOF
285 [$(basename $optional)]
286 name=Fedora ${corename}${releasever} - $basearch - $(basename $optional)
287 baseurl=$optionalurl/
295 # If we are being built as part of an automated RPM build, solve the
296 # bootstrap problem by including any just built packages in the yum
297 # configuration. This cooperates with the PlanetLab build system.
298 if [ -n "$RPM_BUILD_DIR" ] ; then
299 RPM_RPMS_DIR=$(cd $(dirname $RPM_BUILD_DIR)/RPMS && pwd -P)
301 if [ -x /usr/bin/yum-arch ] ; then
302 yum-arch -q $RPM_RPMS_DIR
305 if [ -x /usr/bin/createrepo ] ; then
306 if [ -f $RPM_RPMS_DIR/yumgroups.xml ] ; then
307 groupfile="-g yumgroups.xml"
309 createrepo --quiet $groupfile $RPM_RPMS_DIR
311 # If run under sudo, allow user to delete the headers/ and
312 # repodata/ directories.
313 if [ -n "$SUDO_USER" ] ; then
314 chown -R $SUDO_USER $RPM_RPMS_DIR
316 cat >>$vroot/etc/yum.conf <<EOF
319 name=Bootstrap - $basearch - $RPM_RPMS_DIR/
320 baseurl=file://$RPM_RPMS_DIR/
325 for package in "${exclude[@]}" ; do
326 excludes="$excludes --exclude=$package"
329 # glibc must be specified explicitly for the correct arch to be
331 echo "* Installing glibc" >&3
332 yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes install glibc
335 if [ ${#packages[*]} -gt 0 ] ; then
336 echo "* Installing optional packages" "${packages[@]}" >&3
337 yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes \
338 install "${packages[@]}"
339 if ! rpm --root $vroot -q "${packages[@]}" >/dev/null ; then
340 echo "* Warning: Missing packages"
341 rpm --root $vroot -q "${packages[@]}" | grep "not installed"
345 if [ ${#groups[*]} -gt 0 ] ; then
346 ## call yum sequentially to get finer-grained info on dependencies
347 for grp in "${groups[@]}" ; do
348 echo "* Installing optional group $grp" >&3
349 yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes \
354 # FC2 dev %preinstall checks /proc/mounts to make sure that /dev is
355 # not currently mounted as devfs. If it thinks it is, it will refuse
356 # to install the package. On a modern system running udev that mounts
357 # /dev as tmpfs, this check fails. Since we are installing into a
358 # chroot, whether /dev is mounted on the host system or not doesn't
359 # matter. If dev was explicitly mentioned in the packages list, force
361 if [ "$releasever" = "2" ] ; then
362 for package in "${packages[@]}" ; do
363 if [ "$package" = "dev" ] && ! rpm --root $vroot -q dev >/dev/null 2>&1 ; then
364 rpm --root $vroot -Uvh --noscripts $baseurl/Fedora/RPMS/dev-3.3.13-1.i386.rpm
371 echo "* Cleaning up" >&3
372 yum -c $vroot/etc/yum.conf --installroot=$vroot -y \
376 rm -f $vroot/var/lib/rpm/__db*
378 # Set time zone to UTC
379 if [ -f $vroot/usr/share/zoneinfo/UTC -a -f $vroot/etc/localtime ] ; then
380 rm -f $vroot/etc/localtime
381 ln -s /usr/share/zoneinfo/UTC $vroot/etc/localtime
385 # remove trap handler, as we are about to call it directly.