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
21 echo "* Entering mkfedora " "$@"
26 # Default yum repositories to try
29 http://localhost/fedora
30 http://build.planet-lab.org/fedora
31 http://coblitz.codeen.org/coblitz.planet-lab.org/pub/fedora
32 ftp://mirror.cs.princeton.edu/pub/mirrors/fedora
33 ftp://mirror.stanford.edu/pub/mirrors/fedora
34 ftp://rpmfind.net/linux/fedora
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 echo "* mkfedora : setting mirrors from /etc/planetlab/config"
58 mirrors=($PLC_DEVEL_FEDORA_URL)
64 echo "Usage: mkfedora [OPTION]... [basedir]"
65 echo " -l url Fedora mirror location. Defaults to try:"
66 for mirror in "${mirrors[@]}" ; do
69 echo " -r release Fedora release number (default: $releasever)"
70 echo " -a arch Fedora architecture (default: $basearch)"
71 echo " -g group1 -g group2 ..."
72 echo " Yumgroups to install (default: none)"
73 echo " -p package1 -p package2 ..."
74 echo " Additional packages to install (default: none)"
75 echo " -x package1 -x package2 ..."
76 echo " Packages to exclude (default: none)"
77 echo " -k Exclude kernel* packages from all repositories except bootstrap"
79 echo " -h This message"
84 while getopts "l:r:a:g:p:x:kvh" opt ; do
87 if echo $OPTARG | grep -q -i '^\(file\|http[s]*\)://' ; then
90 mirrors=(file://$OPTARG)
100 groups[${#groups[*]}]="$OPTARG"
103 packages[${#packages[*]}]="$OPTARG"
106 exclude[${#exclude[*]}]="$OPTARG"
109 exclude_kernel="exclude=kernel* ulogd iptables"
121 shift $(($OPTIND - 1))
122 if [ ! -d "$1" ] ; then
126 vroot=$(cd $1 && pwd -P)
128 if [ $UID -ne 0 ] ; then
129 echo "Error: You must run this script as root."
135 curl --fail --silent --max-time 60 "$1"
138 # hard to find two mirrors with a similar layout
139 # set list of attempted locations according to releasever
140 if [ $releasever -ge 7 ] ; then
142 $releasever/Everything/$basearch/os
143 core/$releasever/Everything/$basearch/os \
144 linux/core/$releasever/$basearch/os
148 linux/core/$releasever/$basearch/os
149 core/$releasever/$basearch/os
150 $releasever/$basearch/os
154 echo "$0: candidate mirrors"
155 for mirror in "${mirrors[@]}" ; do
156 echo "* candidate mirror $mirror"
159 for mirror in "${mirrors[@]}" ; do
160 for attempt in $attempts; do
161 attempturl=$mirror/$attempt
162 if fetch $attempturl/repodata/repomd.xml >/dev/null ; then
169 if [ -z "$baseurl" ] ; then
170 echo "Error: $releasever/$basearch/os/repodata/repomd.xml"
171 echo " could not be found in any of the following locations:"
173 for mirror in ${mirrors[@]} ; do
174 for attempt in $attempts ; do
175 echo $mirror/$attempt
184 if [ $verbose -eq 0 ] ; then
189 # Do not tolerate errors
192 # Mount /dev/pts and /dev/shm in reference image
193 mount -t devpts none $vroot/dev/pts
194 mount -t tmpfs none $vroot/dev/shm
196 ## make rpms ignore installing stuff to /proc
197 mkdir -p $vroot/etc/rpm
198 # Because of https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=52725
199 # you have to use at least one language beside 'C'
200 echo "%_install_langs C:de:en:es:fr" > $vroot/etc/rpm/macros
201 echo "%_netsharedpath /proc:/dev/pts" >> $vroot/etc/rpm/macros
202 # append to the vserver's rpm macros
203 echo "%_install_langs C:de:en:es:fr" > /etc/rpm/macros
204 echo "%_netsharedpath /proc:/dev/pts" >> /etc/rpm/macros
205 # Mount /proc in reference image
207 mount -t proc none $vroot/proc
211 umount -l $vroot/proc
212 umount -l $vroot/dev/shm
213 umount -l $vroot/dev/pts
216 # Clean up before exiting if anything goes wrong
217 trap "cleanup" ERR INT
219 # Create a /var/lib dirs for yum & rpm
220 mkdir -p $vroot/var/lib/yum
221 mkdir -p $vroot/var/lib/rpm
222 mkdir -p $vroot/usr/share/info
224 # Create a dummy /etc/fstab in reference image
226 cat >$vroot/etc/fstab <<EOF
227 # This fake fstab exists only to please df and linuxconf.
228 /dev/hdv1 / ext2 defaults 1 1
230 cp $vroot/etc/fstab $vroot/etc/mtab
232 # Prevent all locales from being installed in reference image
233 mkdir -p $vroot/etc/rpm
234 cat >$vroot/etc/rpm/macros <<EOF
235 %_install_langs en_US:en
237 %__file_context_path /dev/null
240 # Necessary for some scripts
241 mkdir -p $vroot/etc/sysconfig
242 echo "NETWORKING=yes" > $vroot/etc/sysconfig/network
244 # Trick rpm and yum, who read the real root /etc/rpm/macros file
245 # rather than the one installed in the reference image, despite what
246 # you might expect the --root and --installroot options to mean. Both
247 # programs always read $HOME/.rpmmacros.
248 export HOME=$vroot/tmp
250 cp $vroot/etc/rpm/macros $vroot/tmp/.rpmmacros
252 # Initialize RPM database in reference image
253 mkdir -p $vroot/var/lib/rpm
254 rpm --root $vroot --initdb
255 rpm --root $vroot --import $baseurl/RPM-GPG-KEY-fedora
257 # Initialize yum in reference image
258 mkdir -p $vroot/var/cache/yum $vroot/var/log
259 if [ $releasever -lt 7 ] ; then
265 cat >$vroot/etc/yum.conf <<EOF
267 cachedir=/var/cache/yum
269 logfile=/var/log/yum.log
271 distroverpkg=redhat-release
277 # Prevent yum-2.4 from loading additional repository definitions
278 # (e.g., from /etc/yum.repos.d/)
282 name=Fedora ${corename}${releasever} - $basearch - base
287 for optional in updates extras ; do
289 $mirror/linux/core/$optional/$releasever/$basearch \
290 $mirror/core/$optional/$releasever/$basearch \
291 $mirror/linux/$optional/$releasever/$basearch \
292 $mirror/$optional/$releasever/$basearch ; do
293 if fetch $optionalurl/repodata/repomd.xml ; then
294 cat >>$vroot/etc/yum.conf <<EOF
296 [$(basename $optional)]
297 name=Fedora ${corename}${releasever} - $basearch - $(basename $optional)
298 baseurl=$optionalurl/
306 # If we are being built as part of an automated RPM build, solve the
307 # bootstrap problem by including any just built packages in the yum
308 # configuration. This cooperates with the PlanetLab build system.
309 if [ -n "$RPM_BUILD_DIR" ] ; then
310 RPM_RPMS_DIR=$(cd $(dirname $RPM_BUILD_DIR)/RPMS && pwd -P)
312 if [ -x /usr/bin/yum-arch ] ; then
313 yum-arch -q $RPM_RPMS_DIR
316 if [ -x /usr/bin/createrepo ] ; then
317 if [ -f $RPM_RPMS_DIR/yumgroups.xml ] ; then
318 groupfile="-g yumgroups.xml"
320 createrepo --quiet $groupfile $RPM_RPMS_DIR
322 # If run under sudo, allow user to delete the headers/ and
323 # repodata/ directories.
324 if [ -n "$SUDO_USER" ] ; then
325 chown -R $SUDO_USER $RPM_RPMS_DIR
327 cat >>$vroot/etc/yum.conf <<EOF
330 name=Bootstrap - $basearch - $RPM_RPMS_DIR/
331 baseurl=file://$RPM_RPMS_DIR/
336 for package in "${exclude[@]}" ; do
337 excludes="$excludes --exclude=$package"
340 # glibc must be specified explicitly for the correct arch to be
342 echo "* Installing glibc" >&3
343 yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes install glibc
346 if [ ${#packages[*]} -gt 0 ] ; then
347 echo "* Installing optional packages" "${packages[@]}" >&3
348 yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes \
349 install "${packages[@]}"
350 if ! rpm --root $vroot -q "${packages[@]}" >/dev/null ; then
351 echo "* Warning: Missing packages"
352 rpm --root $vroot -q "${packages[@]}" | grep "not installed"
356 if [ ${#groups[*]} -gt 0 ] ; then
357 ## call yum sequentially to get finer-grained info on dependencies
358 for grp in "${groups[@]}" ; do
359 echo "* Installing optional group $grp" >&3
360 yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes \
365 # FC2 dev %preinstall checks /proc/mounts to make sure that /dev is
366 # not currently mounted as devfs. If it thinks it is, it will refuse
367 # to install the package. On a modern system running udev that mounts
368 # /dev as tmpfs, this check fails. Since we are installing into a
369 # chroot, whether /dev is mounted on the host system or not doesn't
370 # matter. If dev was explicitly mentioned in the packages list, force
372 if [ "$releasever" = "2" ] ; then
373 for package in "${packages[@]}" ; do
374 if [ "$package" = "dev" ] && ! rpm --root $vroot -q dev >/dev/null 2>&1 ; then
375 rpm --root $vroot -Uvh --noscripts $baseurl/Fedora/RPMS/dev-3.3.13-1.i386.rpm
382 echo "* Cleaning up" >&3
383 yum -c $vroot/etc/yum.conf --installroot=$vroot -y \
387 rm -f $vroot/var/lib/rpm/__db*
389 # Set time zone to UTC
390 if [ -f $vroot/usr/share/zoneinfo/UTC -a -f $vroot/etc/localtime ] ; then
391 rm -f $vroot/etc/localtime
392 ln -s /usr/share/zoneinfo/UTC $vroot/etc/localtime
396 # remove trap handler, as we are about to call it directly.