+ if [ $UID -ne 0 ] ; then
+ echo "Error: You must run this script as root."
+ exit 1
+ fi
+
+# Verbosity
+ verbose=0
+
+# Release and architecture to install : defaults to current vm settings or previously parsed fedora_options
+ releasever=$pl_DISTRO_RELEASE
+ basearch=$pl_DISTRO_ARCH
+
+# Get options
+ while getopts "vh" opt ; do
+ case $opt in
+ v) verbose=1; set -x ;;
+ h|*) pl_root_mkfedora_usage ;;
+ esac
+ done
+
+ shift $(($OPTIND - 1))
+ [[ "$#" -lt 3 ]] && pl_root_mkfedora_usage
+ vroot=$1 ; shift
+ pldistro=$1 ; shift
+ pkgsfile="$@"
+ vroot=$(cd $vroot && pwd -P)
+ [ -d $vroot ] || pl_root_mkfedora_usage
+
+
+ # parse pkgsfile and add to local vars
+ fcdistro=${pl_DISTRO_NAME}
+ pkgs_packages=$(pkgs.py -a $pl_DISTRO_ARCH -f $fcdistro -d $pldistro package $pkgsfile)
+ pkgs_groups=$(pkgs.py -a $pl_DISTRO_ARCH -f $fcdistro -d $pldistro group $pkgsfile)
+ # what can get trashed to save space
+ pkgs_junk=$(pkgs.py -a $pl_DISTRO_ARCH -f $fcdistro -d $pldistro junk $pkgsfile)
+ # but not this
+ pkgs_precious=$(pkgs.py -a $pl_DISTRO_ARCH -f $fcdistro -d $pldistro precious $pkgsfile)
+ # formerly related to mkfedora -k : packages to take from our own build
+ # and thus need be excluded frem the stock repos
+ # locate builddir by looking for pkgs.py
+ builddir=$(dirname $(type -p pkgs.py))
+ SUBST_NODEYUMEXCLUDE=$(pl_nodeyumexclude $fcdistro $pldistro $builddir)
+ pkgs_yumexclude=$(pkgs.py -a $pl_DISTRO_ARCH -f $fcdistro -d $pldistro yumexclude $pkgsfile | sed -e s,@NODEYUMEXCLUDE@,"$SUBST_NODEYUMEXCLUDE",)
+ # get mirrors if not specified with -l
+ if [ -z "$mirrors" ] ; then
+ mirrorsfile=$(pl_locateDistroFile ../build/ $pldistro "$pldistro.mirrors")
+ # do not sort mirrors, keep order from input
+ mirrors=$(pkgs.py -u -a $pl_DISTRO_ARCH -f $fcdistro -d $pldistro mirror $mirrorsfile)
+ fi
+
+ yumexclude_line=""
+ [ -n "$pkgs_yumexclude" ] && yumexclude_line="exclude=$pkgs_yumexclude"
+
+ echo "$0: candidate mirrors"
+ for mirror in $mirrors ; do
+ echo "* candidate mirror $mirror"
+ done
+
+ # the repo part of the final yum.conf
+ yum_conf_repos=$vroot/xxxmkfedora-repos.confxxx
+ if ! yumconf_mirrors $yum_conf_repos ../build/ $fcdistro "$yumexclude_line" $mirrors ; then
+ echo xxx -- error ; return 1
+ fi
+
+ # Do not tolerate errors
+ set -e
+
+ public_gpg_key=$(yumconf_gpgkey $yum_conf_repos)
+
+ ## make rpms ignore installing stuff to special fs entries like /proc
+ # Because of https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=52725
+ # you have to use at least one language beside 'C'
+ # Prevent all locales from being installed in reference image
+ mkdir -p $vroot/etc/rpm
+ pl_root_rpm_macros > $vroot/etc/rpm/macros
+
+ # Trick rpm and yum, who read the real root /etc/rpm/macros file
+ # rather than the one installed in the reference image, despite what
+ # you might expect the --root and --installroot options to mean. Both
+ # programs always read $HOME/.rpmmacros.
+ export HOME=$vroot/tmp
+ mkdir -p $vroot/tmp
+ pl_root_rpm_macros > $vroot/tmp/.rpmmacros
+
+ function mkfedora_cleanup () {
+ umount -l $vroot/proc
+ umount -l $vroot/dev/shm
+ umount -l $vroot/dev/pts
+ }
+
+ # Clean up before exiting if anything goes wrong
+ trap "mkfedora_cleanup" ERR INT
+
+ # Mount in reference image
+ mount -t devpts none $vroot/dev/pts
+ mount -t tmpfs none $vroot/dev/shm
+ mkdir -p $vroot/proc
+ mount -t proc none $vroot/proc
+
+ # Create a /var/lib dirs for yum & rpm
+ mkdir -p $vroot/var/lib/yum
+ mkdir -p $vroot/var/lib/rpm
+ mkdir -p $vroot/usr/share/info
+
+ # Create a dummy /etc/fstab in reference image
+ mkdir -p $vroot/etc
+ cat >$vroot/etc/fstab <<EOF
+# This fake fstab exists only to please df and linuxconf.
+/dev/hdv1 / ext2 defaults 1 1
+EOF
+ cp $vroot/etc/fstab $vroot/etc/mtab
+
+ # Necessary for some scripts
+ mkdir -p $vroot/etc/sysconfig
+ echo "NETWORKING=yes" > $vroot/etc/sysconfig/network
+
+ # Initialize RPM database in reference image
+ mkdir -p $vroot/var/lib/rpm
+ rpm --root $vroot --initdb
+ rpm --root $vroot --import $public_gpg_key
+
+ # Initialize yum in reference image
+ mkdir -p $vroot/var/cache/yum $vroot/var/log
+
+# yum.conf is for building only - store in different location than /etc/yum.conf
+ yum_conf=$vroot/etc/mkfedora-yum.conf
+ cat > $yum_conf <<EOF
+[main]
+cachedir=/var/cache/yum
+debuglevel=2
+logfile=/var/log/yum.log
+pkgpolicy=newest
+multilib_policy=best
+distroverpkg=redhat-release
+tolerant=1
+exactarch=1
+retries=20
+obsoletes=1
+gpgcheck=0
+# Prevent yum-2.4 from loading additional repository definitions
+# (e.g., from /etc/yum.repos.d/)
+reposdir=/dev/null
+EOF
+
+ cat $yum_conf_repos >> $yum_conf
+
+ # If we are being built as part of an automated RPM build, solve the
+ # bootstrap problem by including any just built packages in the yum
+ # configuration. This cooperates with the PlanetLab build system.
+ if [ -n "$RPM_BUILD_DIR" ] ; then
+ RPM_RPMS_DIR=$(cd $(dirname $RPM_BUILD_DIR)/RPMS && pwd -P)
+ # If run under sudo, allow user to delete the headers/ and
+ # repodata/ directories.
+ if [ -n "$SUDO_USER" ] ; then
+ chown -R $SUDO_USER $RPM_RPMS_DIR
+ fi
+ cat >> $yum_conf <<EOF
+
+[building]
+name=Building - $basearch - $RPM_RPMS_DIR/
+baseurl=file://$RPM_RPMS_DIR/
+EOF
+fi
+
+ echo "========== Dumping $yum_conf"
+ cat $yum_conf
+ echo "========== EndDump $yum_conf"
+
+ yum_options=""
+# yum --help | grep verbose &> /dev/null && yum_options="$yum_options --verbose"
+ yum_options="$yum_options -y"
+ yum_options="$yum_options -c $yum_conf"
+ yum_options="$yum_options --installroot=$vroot"
+ yum_options="$yum_options --releasever=$releasever"
+
+ # glibc must be specified explicitly for the correct arch to be
+ # chosen.
+ echo "* Installing glibc"
+ # ignore yum's return code that is basically undefined
+ yum $yum_options install glibc || :
+
+ # Go, baby, go
+ if [ -n "$pkgs_packages" ] ; then
+ echo "* Installing optional packages" $pkgs_packages
+ # ignore yum's return code that is basically undefined
+ echo "* Install options" $vroot $yum_options
+ yum $yum_options install $pkgs_packages || :
+ if ! rpm --root $vroot -q $pkgs_packages >/dev/null ; then
+ echo "* Warning: Missing packages"
+ rpm --root $vroot -q $pkgs_packages | grep "not installed"
+ fi
+ fi
+
+ if [ -n "$pkgs_groups" ] ; then
+ ## call yum sequentially to get finer-grained info on dependencies
+ for group_plus in $pkgs_groups ; do
+ group=$(echo $group_plus | sed -e "s,+++, ,g")
+ echo "* Installing optional group $group"
+ # ignore yum's return code that is basically undefined
+ yum $yum_options groupinstall "$group" || :
+ done
+ fi
+
+ # formerly in bootcd/prep.sh : to optimize footprint
+ if [ -n "$pkgs_junk" ] ; then
+ echo "* Removing unnecessary junk"
+ pushd $vroot
+ # Save precious files
+ [ -n "$pkgs_precious" ] && tar --ignore-failed-read -cpf precious.tar $pkgs_precious
+ # Remove unnecessary junk
+ [ -n "$pkgs_junk" ] && rm -rf $pkgs_junk
+ # Restore precious files
+ [ -n "$pkgs_precious" ] && tar -xpf precious.tar && rm -f precious.tar
+ popd
+ fi
+
+ # Clean yum cache
+ echo "* Cleaning up"
+
+ # NOTE: this hack is for Fedora >= 12.
+ # if kernel-debug is installed, clean it up
+ # we link to our version of kernel/initrd and clean up
+ # kernel-debug manually
+ if rpm --root $vroot --quiet -q kernel-debug ; then
+ echo "* Cleaning up kernel-debug - (workaround for f12)"
+ pushd $vroot/boot/
+ rm -rf kernel-boot kernel-bootsmp initrd-boot initrd-bootsmp
+ ln -s vmlinuz-*${pldistro}* kernel-boot
+ ln -s vmlinuz-*${pldistro}* kernel-bootsmp
+ ln -s initrd-*${pldistro}* initrd-boot
+ ln -s initrd-*${pldistro}* initrd-bootsmp
+ rpm --root $vroot --nodeps -e kernel-debug || :
+ popd
+ fi