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: mkfedora,v 1.2 2006/03/29 17:10:21 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
46 echo "Usage: mkfedora [OPTION]... [basedir]"
47 echo " -l url Fedora mirror location. Defaults to try:"
48 for mirror in "${mirrors[@]}" ; do
51 echo " -r release Fedora release number (default: $releasever)"
52 echo " -a arch Fedora architecture (default: $basearch)"
53 echo " -g group1 -g group2 ..."
54 echo " Yumgroups to install (default: none)"
55 echo " -p package1 -p package2 ..."
56 echo " Additional packages to install (default: none)"
58 echo " -h This message"
63 while getopts "l:r:a:g:p:vh" opt ; do
66 if echo $OPTARG | grep -q -i '^\(file\|http[s]*\)://' ; then
69 mirrors=(file://$OPTARG)
79 groups[${#groups[*]}]="$OPTARG"
82 packages[${#packages[*]}]="$OPTARG"
94 shift $(($OPTIND - 1))
95 if [ ! -d "$1" ] ; then
99 vroot=$(cd $1 && pwd -P)
101 if [ $UID -ne 0 ] ; then
102 echo "Error: You must run this script as root."
106 # Old versions of curl don't understand file:// URLs
110 if curl --fail --silent --max-time 60 $url ; then
113 if [ -f ${url#file://} ] ; then
121 for mirror in "${mirrors[@]}" ; do
122 baseurl=$mirror/linux/core/$releasever/$basearch/os
123 if fetch $baseurl/repodata/repomd.xml >/dev/null ; then
129 if [ -z "$baseurl" ] ; then
130 echo "Error: linux/core/$releasever/$basearch/os/repodata/repomd.xml"
131 echo " could not be found in any of the following locations:"
133 for mirror in ${mirrors[@]} ; do
142 if [ $verbose -eq 0 ] ; then
148 tmp=$(mktemp -d /tmp/mkfedora.XXXXXX)
150 # Initialize /dev in reference image
152 mknod -m 666 $vroot/dev/null c 1 3
153 mknod -m 666 $vroot/dev/zero c 1 5
154 mknod -m 666 $vroot/dev/full c 1 7
155 mknod -m 644 $vroot/dev/random c 1 8
156 mknod -m 644 $vroot/dev/urandom c 1 9
157 mknod -m 666 $vroot/dev/tty c 5 0
158 mknod -m 666 $vroot/dev/ptmx c 5 2
159 # For bash command substitution
160 ln -nsf ../proc/self/fd $vroot/dev/fd
161 # For df and linuxconf
162 touch $vroot/dev/hdv1
164 # Mount /dev/pts in reference image
165 mkdir -p $vroot/dev/pts
166 mount -t devpts none $vroot/dev/pts
168 # Mount /dev/shm in reference image
169 mkdir -p $vroot/dev/shm
170 mount -t tmpfs none $vroot/dev/shm
172 # Mount /proc in reference image
174 mount -t proc none $vroot/proc
179 umount $vroot/dev/shm
180 umount $vroot/dev/pts
184 # Clean up before exiting if anything goes wrong
185 trap "cleanup; exit 1" ERR
187 # Create a dummy /etc/fstab in reference image
189 cat >$vroot/etc/fstab <<EOF
190 # This fake fstab exists only to please df and linuxconf.
191 /dev/hdv1 / ext2 defaults 1 1
193 cp $vroot/etc/fstab $vroot/etc/mtab
195 # Prevent all locales from being installed in reference image
196 mkdir -p $vroot/etc/rpm
197 cat >$vroot/etc/rpm/macros <<EOF
198 %_install_langs en_US:en
200 %__file_context_path /dev/null
203 # Necessary for some scripts
204 mkdir -p $vroot/etc/sysconfig
205 echo "NETWORKING=yes" > $vroot/etc/sysconfig/network
207 # Trick rpm and yum, who read the real root /etc/rpm/macros file
208 # rather than the one installed in the reference image, despite what
209 # you might expect the --root and --installroot options to mean. Both
210 # programs always read $HOME/.rpmmacros.
211 export HOME=$vroot/tmp
213 cp $vroot/etc/rpm/macros $vroot/tmp/.rpmmacros
215 # Initialize RPM database in reference image
216 mkdir -p $vroot/var/lib/rpm
217 rpm --root $vroot --initdb
218 rpm --root $vroot --import $baseurl/RPM-GPG-KEY-fedora
220 # Initialize yum in reference image
221 mkdir -p $vroot/var/cache/yum $vroot/var/log
222 cat >$vroot/etc/yum.conf <<EOF
224 cachedir=/var/cache/yum
226 logfile=/var/log/yum.log
228 distroverpkg=redhat-release
234 # Prevent yum-2.4 from loading additional repository definitions
235 # (e.g., from /etc/yum.repos.d/)
239 name=Fedora Core $releasever - $basearch - base
243 for optional in core/updates extras ; do
244 if fetch $mirror/linux/$optional/$releasever/$basearch/repodata/repomd.xml ; then
245 cat >>$vroot/etc/yum.conf <<EOF
247 [$(basename $optional)]
248 name=Fedora Core $releasever - $basearch - $(basename $optional)
249 baseurl=$mirror/linux/$optional/$releasever/$basearch/
254 # If we are being built as part of an automated RPM build, solve the
255 # bootstrap problem by including any just built packages in the yum
256 # configuration. This cooperates with the PlanetLab build system.
257 if [ -n "$RPM_BUILD_DIR" ] ; then
258 RPM_RPMS_DIR=$(cd $(dirname $RPM_BUILD_DIR)/RPMS && pwd -P)
260 if [ -x /usr/bin/yum-arch ] ; then
261 yum-arch $RPM_RPMS_DIR
264 if [ -x /usr/bin/createrepo ] ; then
265 if [ -f $RPM_RPMS_DIR/yumgroups.xml ] ; then
266 groupfile="-g yumgroups.xml"
268 createrepo $groupfile $RPM_RPMS_DIR
270 # If run under sudo, allow user to delete the headers/ and
271 # repodata/ directories.
272 if [ -n "$SUDO_USER" ] ; then
273 chown -R $SUDO_USER $RPM_RPMS_DIR
275 cat >>$vroot/etc/yum.conf <<EOF
278 name=Bootstrap - $basearch - $RPM_RPMS_DIR/
279 baseurl=file://$RPM_RPMS_DIR/
283 echo -n "* Installing base system..." >&3
285 # glibc must be specified explicitly for the correct arch to be chosen.
286 yum -c $vroot/etc/yum.conf --installroot=$vroot -y install glibc
289 if [ ${#groups[*]} -gt 0 ] ; then
290 echo -n "* Installing optional groups..." >&3
291 yum -c $vroot/etc/yum.conf --installroot=$vroot -y \
292 groupinstall "${groups[@]}"
296 if [ ${#packages[*]} -gt 0 ] ; then
297 echo -n "* Installing optional packages..." >&3
298 yum -c $vroot/etc/yum.conf --installroot=$vroot -y \
299 install "${packages[@]}"
304 echo -n "* Cleaning up..." >&3
305 yum -c $vroot/etc/yum.conf --installroot=$vroot -y \
310 rm -f $vroot/var/lib/rpm/__db*
312 # Disable all services in reference image
313 chroot $vroot /bin/sh -c "/sbin/chkconfig --list | awk '{ print \$1 }' | xargs -i /sbin/chkconfig {} off"