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 # for pkgs parsing functions
22 export PATH=/sbin:/bin:/usr/sbin:/usr/bin
24 echo "* Entering mkfedora " "$@"
29 # Default yum repositories to try
32 http://localhost/fedora
33 http://build.planet-lab.org/fedora
34 http://coblitz.codeen.org/coblitz.planet-lab.org/pub/fedora
35 ftp://mirror.cs.princeton.edu/pub/mirrors/fedora
36 ftp://mirror.stanford.edu/pub/mirrors/fedora
37 ftp://rpmfind.net/linux/fedora
40 # Release and architecture to install
44 # Yum groups to install
53 # Exclude kernel* (and related) packages from all repositories except bootstrap
56 # PlanetLab development environment
57 if [ -f /etc/planetlab/plc_config ] ; then
58 . /etc/planetlab/plc_config
59 if [ -n "$PLC_DEVEL_FEDORA_URL" ] ; then
60 echo "* mkfedora : setting mirrors from /etc/planetlab/config"
61 mirrors=($PLC_DEVEL_FEDORA_URL)
67 echo "Usage: mkfedora [OPTION]... [basedir]"
68 echo " -l url Fedora mirror location. Defaults to try:"
69 for mirror in "${mirrors[@]}" ; do
72 echo " -r release Fedora release number (default: $releasever)"
73 echo " -a arch Fedora architecture (default: $basearch)"
74 echo " -f pkgsfile use this pkgs file for packages, groups, excludes.."
75 echo " -g group1 -g group2 ..."
76 echo " Yumgroups to install (default: none)"
77 echo " -p package1 -p package2 ..."
78 echo " Additional packages to install (default: none)"
79 echo " -x package1 -x package2 ..."
80 echo " Packages to exclude (default: none)"
81 echo " -k Exclude kernel* packages from all repositories except bootstrap"
83 echo " -h This message"
88 while getopts "l:r:a:g:p:x:kvh" opt ; do
91 if echo $OPTARG | grep -q -i '^\(file\|http[s]*\)://' ; then
94 mirrors=(file://$OPTARG)
104 groups[${#groups[*]}]="$OPTARG"
107 packages[${#packages[*]}]="$OPTARG"
110 exclude[${#exclude[*]}]="$OPTARG"
116 exclude_kernel="exclude=kernel* ulogd iptables"
128 shift $(($OPTIND - 1))
129 if [ ! -d "$1" ] ; then
133 vroot=$(cd $1 && pwd -P)
135 if [ $UID -ne 0 ] ; then
136 echo "Error: You must run this script as root."
142 curl --fail --silent --max-time 60 "$1"
145 # hard to find two mirrors with a similar layout
146 # set list of attempted locations according to releasever
147 if [ $releasever -ge 7 ] ; then
149 linux/releases/$releasever/Everything/$basearch/os
150 $releasever/Everything/$basearch/os
151 core/$releasever/Everything/$basearch/os
152 linux/core/$releasever/$basearch/os
156 linux/core/$releasever/$basearch/os
157 core/$releasever/$basearch/os
158 $releasever/$basearch/os
162 echo "$0: candidate mirrors"
163 for mirror in "${mirrors[@]}" ; do
164 echo "* candidate mirror $mirror"
167 for mirror in "${mirrors[@]}" ; do
168 for attempt in $attempts; do
169 attempturl=$mirror/$attempt
170 if fetch $attempturl/repodata/repomd.xml >/dev/null ; then
177 if [ -z "$baseurl" ] ; then
178 echo "Error: $releasever/$basearch/os/repodata/repomd.xml"
179 echo " could not be found in any of the following locations:"
181 for mirror in ${mirrors[@]} ; do
182 for attempt in $attempts ; do
183 echo $mirror/$attempt
192 if [ $verbose -eq 0 ] ; then
197 # Do not tolerate errors
200 ## make rpms ignore installing stuff to special fs entries like /proc
201 # Because of https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=52725
202 # you have to use at least one language beside 'C'
203 # Prevent all locales from being installed in reference image
204 mkdir -p $vroot/etc/rpm
205 cat > $vroot/etc/rpm/macros <<EOF
206 %_install_langs C:en_US:en
207 %_netsharedpath /proc:/dev/pts
209 %__file_context_path /dev/null
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 ### Checking whether this is really needed
221 ### # copy to the vserver's rpm macros
222 ### # xxx fixme - this must be reviewed once we get the stuff running
223 ### cp $vroot/etc/rpm/macros /etc/rpm/macros
225 # Mount in reference image
226 mount -t devpts none $vroot/dev/pts
227 mount -t tmpfs none $vroot/dev/shm
229 mount -t proc none $vroot/proc
233 umount -l $vroot/proc
234 umount -l $vroot/dev/shm
235 umount -l $vroot/dev/pts
238 # Clean up before exiting if anything goes wrong
239 trap "cleanup" ERR INT
241 # Create a /var/lib dirs for yum & rpm
242 mkdir -p $vroot/var/lib/yum
243 mkdir -p $vroot/var/lib/rpm
244 mkdir -p $vroot/usr/share/info
246 # Create a dummy /etc/fstab in reference image
248 cat >$vroot/etc/fstab <<EOF
249 # This fake fstab exists only to please df and linuxconf.
250 /dev/hdv1 / ext2 defaults 1 1
252 cp $vroot/etc/fstab $vroot/etc/mtab
254 # Necessary for some scripts
255 mkdir -p $vroot/etc/sysconfig
256 echo "NETWORKING=yes" > $vroot/etc/sysconfig/network
258 # Initialize RPM database in reference image
259 mkdir -p $vroot/var/lib/rpm
260 rpm --root $vroot --initdb
261 rpm --root $vroot --import $baseurl/RPM-GPG-KEY-fedora
263 # Initialize yum in reference image
264 mkdir -p $vroot/var/cache/yum $vroot/var/log
265 if [ $releasever -lt 7 ] ; then
271 cat >$vroot/etc/yum.conf <<EOF
273 cachedir=/var/cache/yum
275 logfile=/var/log/yum.log
277 distroverpkg=redhat-release
283 # Prevent yum-2.4 from loading additional repository definitions
284 # (e.g., from /etc/yum.repos.d/)
288 name=Fedora ${corename}${releasever} - $basearch - base
293 for optional in updates extras ; do
295 $mirror/linux/core/$optional/$releasever/$basearch \
296 $mirror/core/$optional/$releasever/$basearch \
297 $mirror/linux/$optional/$releasever/$basearch \
298 $mirror/$optional/$releasever/$basearch ; do
299 if fetch $optionalurl/repodata/repomd.xml ; then
300 cat >>$vroot/etc/yum.conf <<EOF
302 [$(basename $optional)]
303 name=Fedora ${corename}${releasever} - $basearch - $(basename $optional)
304 baseurl=$optionalurl/
312 # If we are being built as part of an automated RPM build, solve the
313 # bootstrap problem by including any just built packages in the yum
314 # configuration. This cooperates with the PlanetLab build system.
315 if [ -n "$RPM_BUILD_DIR" ] ; then
316 RPM_RPMS_DIR=$(cd $(dirname $RPM_BUILD_DIR)/RPMS && pwd -P)
318 if [ -x /usr/bin/yum-arch ] ; then
319 yum-arch -q $RPM_RPMS_DIR
322 if [ -x /usr/bin/createrepo ] ; then
323 if [ -f $RPM_RPMS_DIR/yumgroups.xml ] ; then
324 groupfile="-g yumgroups.xml"
326 createrepo --quiet $groupfile $RPM_RPMS_DIR
328 # If run under sudo, allow user to delete the headers/ and
329 # repodata/ directories.
330 if [ -n "$SUDO_USER" ] ; then
331 chown -R $SUDO_USER $RPM_RPMS_DIR
333 cat >>$vroot/etc/yum.conf <<EOF
336 name=Bootstrap - $basearch - $RPM_RPMS_DIR/
337 baseurl=file://$RPM_RPMS_DIR/
342 if [ -n "$pkgsfile" ] ; then
343 # parse pkgsfile and add to local vars
344 fcdistro=$(pl_getReleaseName "Fedora" $releasever)
345 for i in $(pl_parsePkgs package $fcdistro $pkgsfile) ; do
346 packages[${#packages[*]}]="$i"
348 for i in $(pl_parsePkgs group $fcdistro $pkgsfile) ; do
349 groups[${#groups[*]}]="$i"
351 for i in $(pl_parsePkgs exclude $fcdistro $pkgsfile) ; do
352 exclude[${#exclude[*]}]="$i"
354 junk=$(pl_parsePkgs junk $fcdistro $pkgsfile)
355 precious=$(pl_parsePkgs precious $fcdistro $pkgsfile)
359 for package in "${exclude[@]}" ; do
360 excludes="$excludes --exclude=$package"
363 # glibc must be specified explicitly for the correct arch to be
365 echo "* Installing glibc" >&3
366 yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes install glibc
369 if [ ${#packages[*]} -gt 0 ] ; then
370 echo "* Installing optional packages" "${packages[@]}" >&3
371 yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes \
372 install "${packages[@]}"
373 if ! rpm --root $vroot -q "${packages[@]}" >/dev/null ; then
374 echo "* Warning: Missing packages"
375 rpm --root $vroot -q "${packages[@]}" | grep "not installed"
379 if [ ${#groups[*]} -gt 0 ] ; then
380 ## call yum sequentially to get finer-grained info on dependencies
381 for grp in "${groups[@]}" ; do
382 echo "* Installing optional group $grp" >&3
383 yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes \
388 # FC2 dev %preinstall checks /proc/mounts to make sure that /dev is
389 # not currently mounted as devfs. If it thinks it is, it will refuse
390 # to install the package. On a modern system running udev that mounts
391 # /dev as tmpfs, this check fails. Since we are installing into a
392 # chroot, whether /dev is mounted on the host system or not doesn't
393 # matter. If dev was explicitly mentioned in the packages list, force
395 if [ "$releasever" = "2" ] ; then
396 for package in "${packages[@]}" ; do
397 if [ "$package" = "dev" ] && ! rpm --root $vroot -q dev >/dev/null 2>&1 ; then
398 rpm --root $vroot -Uvh --noscripts $baseurl/Fedora/RPMS/dev-3.3.13-1.i386.rpm
405 echo "* Cleaning up" >&3
406 yum -c $vroot/etc/yum.conf --installroot=$vroot -y \
410 rm -f $vroot/var/lib/rpm/__db*
412 # Set time zone to UTC
413 if [ -f $vroot/usr/share/zoneinfo/UTC -a -f $vroot/etc/localtime ] ; then
414 rm -f $vroot/etc/localtime
415 ln -s /usr/share/zoneinfo/UTC $vroot/etc/localtime
418 # formerly in bootcd/prep.sh : to optimize footprint
419 echo "* Removing unnecessary junk" >&3
423 # Save precious files
424 tar --ignore-failed-read -cpf precious.tar $precious
426 # Remove unnecessary junk
429 # Restore precious files
430 tar -xpf precious.tar
435 # remove trap handler, as we are about to call it directly.