3 # Builds a Fedora Core 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: build.sh,v 1.2 2005/10/01 18:20:08 mlhuang Exp $
19 export PATH=/sbin:/bin:/usr/sbin:/usr/bin
24 # Default yum repositories to try
26 file:///usr/share/mirrors/fedora
27 file:///var/www/html/mirrors/fedora
28 ftp://smoke.cs.princeton.edu/pub/mirrors/fedora
29 ftp://128.112.137.30/pub/mirrors/fedora
30 http://coblitz.planet-lab.org/pub/fedora
31 ftp://mirror.cs.princeton.edu/pub/mirrors/fedora
34 # Release and architecture to install
38 # Yum groups to install
48 echo "Usage: mkfedora [OPTION]... [basedir]"
49 echo " -l url Fedora mirror location. Defaults to try:"
50 for mirror in "${mirrors[@]}" ; do
53 echo " -r release Fedora release number (default: $releasever)"
54 echo " -a arch Fedora architecture (default: $basearch)"
55 echo " -g group1 -g group2 ..."
56 echo " Additional yumgroups to install. Defaults:"
57 for group in "${groups[@]}" ; do
60 echo " -p package1 -p package2 ..."
61 echo " Additional packages to install (default: none)"
63 echo " -h This message"
68 while getopts "l:r:a:g:p:vh" opt ; do
71 if echo $OPTARG | grep -q -i '^\(file\|http[s]*\)://' ; then
74 mirrors=(file://$OPTARG)
84 groups[${#groups[*]}]="$OPTARG"
87 packages[${#packages[*]}]="$OPTARG"
99 shift $(($OPTIND - 1))
100 if [ ! -d "$1" ] ; then
104 vroot=$(cd $1 && pwd -P)
106 if [ $UID -ne 0 ] ; then
107 echo "Error: You must run this script as root."
111 # Old versions of curl don't understand file:// URLs
115 if curl --fail --silent --max-time 60 $url ; then
118 if [ -f ${url#file://} ] ; then
126 for mirror in "${mirrors[@]}" ; do
127 baseurl=$mirror/linux/core/$releasever/$basearch/os
128 if fetch $baseurl/repodata/repomd.xml >/dev/null ; then
134 if [ -z "$baseurl" ] ; then
135 echo "Error: linux/core/$releasever/$basearch/os/repodata/repomd.xml"
136 echo " could not be found in any of the following locations:"
138 for mirror in ${mirrors[@]} ; do
147 if [ $verbose -eq 0 ] ; then
153 tmp=$(mktemp -d /tmp/mkfedora.XXXXXX)
155 # Initialize /dev in reference image
157 mknod -m 666 $vroot/dev/null c 1 3
158 mknod -m 666 $vroot/dev/zero c 1 5
159 mknod -m 666 $vroot/dev/full c 1 7
160 mknod -m 644 $vroot/dev/random c 1 8
161 mknod -m 644 $vroot/dev/urandom c 1 9
162 mknod -m 666 $vroot/dev/tty c 5 0
163 mknod -m 666 $vroot/dev/ptmx c 5 2
164 # For bash command substitution
165 ln -nsf ../proc/self/fd $vroot/dev/fd
166 # For df and linuxconf
167 touch $vroot/dev/hdv1
169 # Mount /dev/pts in reference image
170 mkdir -p $vroot/dev/pts
171 mount -t devpts none $vroot/dev/pts
173 # Mount /dev/shm in reference image
174 mkdir -p $vroot/dev/shm
175 mount -t tmpfs none $vroot/dev/shm
177 # Mount /proc in reference image
179 mount -t proc none $vroot/proc
184 umount $vroot/dev/shm
185 umount $vroot/dev/pts
189 # Clean up before exiting if anything goes wrong
190 trap "cleanup; exit 1" ERR
192 # Create a dummy /etc/fstab in reference image
194 cat >$vroot/etc/fstab <<EOF
195 # This fake fstab exists only to please df and linuxconf.
196 /dev/hdv1 / ext2 defaults 1 1
198 cp $vroot/etc/fstab $vroot/etc/mtab
200 # Prevent all locales from being installed in reference image
201 mkdir -p $vroot/etc/rpm
202 cat >$vroot/etc/rpm/macros <<EOF
203 %_install_langs en_US:en
205 %__file_context_path /dev/null
208 # Necessary for some scripts
209 mkdir -p $vroot/etc/sysconfig
210 echo "NETWORKING=yes" > $vroot/etc/sysconfig/network
212 # Trick rpm and yum, who read the real root /etc/rpm/macros file
213 # rather than the one installed in the reference image, despite what
214 # you might expect the --root and --installroot options to mean. Both
215 # programs always read $HOME/.rpmmacros.
216 export HOME=$vroot/tmp
218 cp $vroot/etc/rpm/macros $vroot/tmp/.rpmmacros
220 # Initialize RPM database in reference image
221 mkdir -p $vroot/var/lib/rpm
222 rpm --root $vroot --initdb
223 rpm --root $vroot --import $baseurl/RPM-GPG-KEY-fedora
225 # Initialize yum in reference image
226 mkdir -p $vroot/var/cache/yum $vroot/var/log
227 cat >$vroot/etc/yum.conf <<EOF
229 cachedir=/var/cache/yum
231 logfile=/var/log/yum.log
233 distroverpkg=redhat-release
239 # Prevent yum-2.4 from loading additional repository definitions
240 # (e.g., from /etc/yum.repos.d/)
244 name=Fedora Core $releasever - $basearch - base
248 for optional in core/updates extras ; do
249 if fetch $mirror/linux/$optional/$releasever/$basearch/repodata/repomd.xml ; then
250 cat >>$vroot/etc/yum.conf <<EOF
252 [$(basename $optional)]
253 name=Fedora Core $releasever - $basearch - $(basename $optional)
254 baseurl=$mirror/linux/$optional/$releasever/$basearch/
259 # If we are being built as part of an automated RPM build, solve the
260 # bootstrap problem by including any just built packages in the yum
261 # configuration. This cooperates with the PlanetLab build system.
262 if [ -n "$RPM_BUILD_DIR" ] ; then
263 RPM_RPMS_DIR=$(cd $(dirname $RPM_BUILD_DIR)/RPMS && pwd -P)
264 yum-arch $RPM_RPMS_DIR || :
265 createrepo $RPM_RPMS_DIR || :
266 # If run under sudo, allow user to delete the headers/ and
267 # repodata/ directories.
268 if [ -n "$SUDO_USER" ] ; then
269 chown -R $SUDO_USER $RPM_RPMS_DIR
271 cat >>$vroot/etc/yum.conf <<EOF
274 name=Bootstrap - $basearch - $RPM_RPMS_DIR/
275 baseurl=file://$RPM_RPMS_DIR/
278 # XXX Build system should generate yumgroups.xml automatically
281 # The "Core" and "Base" groups are not uservisible by default in
282 # comps.xml, and old (Fedora Core 2) versions of yum will refuse to
283 # recognize them explicitly.
284 mkdir -p $tmp/corebase
285 cat >$tmp/corebase/yumgroups.xml <<EOF
286 <?xml version="1.0"?>
287 <!DOCTYPE comps PUBLIC "-//Red Hat, Inc.//DTD Comps info//EN" "comps.dtd">
291 <name>Core and Base</name>
292 <default>true</default>
293 <description>Core and Base Packages</description>
294 <uservisible>true</uservisible>
296 <groupreq>core</groupreq>
297 <groupreq>base</groupreq>
304 yum-arch $tmp/corebase || :
306 createrepo -g yumgroups.xml $tmp/corebase || :
308 cat >>$vroot/etc/yum.conf <<EOF
312 baseurl=file://$tmp/corebase/
315 echo -n "* Installing base system..." >&3
317 # glibc must be specified explicitly for the correct arch to be chosen.
318 yum -c $vroot/etc/yum.conf --installroot=$vroot -y install glibc
321 yum -c $vroot/etc/yum.conf --installroot=$vroot -y \
322 groupinstall "${groups[@]}"
326 if [ ${#packages[*]} -gt 0 ] ; then
327 echo -n "* Installing optional packages..."
328 yum -c $vroot/etc/yum.conf --installroot=$vroot -y \
329 install "${packages[@]}"
334 echo -n "* Cleaning up..." >&3
335 yum -c $vroot/etc/yum.conf --installroot=$vroot -y \
340 rm -f $vroot/var/lib/rpm/__db*
342 # Disable all services in reference image
343 chroot $vroot /bin/sh -c "/sbin/chkconfig --list | awk '{ print \$1 }' | xargs -i /sbin/chkconfig {} off"