X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=mkfedora;h=6f01478cbcbe68c4558edd788c53b3b7276edf32;hb=b59769dcfe9e3b9de48b0ab05a1e5098db70af68;hp=d403caf792e9ce6400f1c00c59c38b8e11a49cbb;hpb=c05c9dffad85d51aad7caace1d2f037d45a8fe6c;p=build.git diff --git a/mkfedora b/mkfedora index d403caf7..6f01478c 100755 --- a/mkfedora +++ b/mkfedora @@ -1,6 +1,6 @@ #!/bin/bash # -# Builds a Fedora Core reference image. Requires the build server to +# Builds a Fedora reference image. Requires the build server to # host a local yum repository in one of: # # /usr/share/mirrors/fedora @@ -13,26 +13,29 @@ # Mark Huang # Copyright (C) 2004-2006 The Trustees of Princeton University # -# $Id: mkfedora,v 1.3 2006/03/29 19:19:19 mlhuang Exp $ +# $Id$ # export PATH=/sbin:/bin:/usr/sbin:/usr/bin +echo "* Entering mkfedora " "$@" + # Verbosity verbose=0 # Default yum repositories to try mirrors=( -file:///usr/share/mirrors/fedora -file:///var/www/html/mirrors/fedora -ftp://smoke.cs.princeton.edu/pub/mirrors/fedora -ftp://128.112.137.30/pub/mirrors/fedora -http://coblitz.planet-lab.org/pub/fedora +file:///data/fedora +http://localhost/fedora +http://build.planet-lab.org/fedora +http://coblitz.codeen.org/coblitz.planet-lab.org/pub/fedora ftp://mirror.cs.princeton.edu/pub/mirrors/fedora +ftp://mirror.stanford.edu/pub/mirrors/fedora +ftp://rpmfind.net/linux/fedora ) # Release and architecture to install -releasever=2 +releasever=4 basearch=i386 # Yum groups to install @@ -41,6 +44,21 @@ groups=() # Packages to install packages=() +# Packages to exclude +exclude=() + +# Exclude kernel* (and related) packages from all repositories except bootstrap +exclude_kernel= + +# PlanetLab development environment +if [ -f /etc/planetlab/plc_config ] ; then + . /etc/planetlab/plc_config + if [ -n "$PLC_DEVEL_FEDORA_URL" ] ; then + echo "* mkfedora : setting mirrors from /etc/planetlab/config" + mirrors=($PLC_DEVEL_FEDORA_URL) + fi +fi + usage() { echo "Usage: mkfedora [OPTION]... [basedir]" @@ -54,13 +72,16 @@ usage() echo " Yumgroups to install (default: none)" echo " -p package1 -p package2 ..." echo " Additional packages to install (default: none)" + echo " -x package1 -x package2 ..." + echo " Packages to exclude (default: none)" + echo " -k Exclude kernel* packages from all repositories except bootstrap" echo " -v Be verbose" echo " -h This message" exit 1 } # Get options -while getopts "l:r:a:g:p:vh" opt ; do +while getopts "l:r:a:g:p:x:kvh" opt ; do case $opt in l) if echo $OPTARG | grep -q -i '^\(file\|http[s]*\)://' ; then @@ -81,6 +102,12 @@ while getopts "l:r:a:g:p:vh" opt ; do p) packages[${#packages[*]}]="$OPTARG" ;; + x) + exclude[${#exclude[*]}]="$OPTARG" + ;; + k) + exclude_kernel="exclude=kernel* ulogd iptables" + ;; v) verbose=1 set -x @@ -103,35 +130,51 @@ if [ $UID -ne 0 ] ; then exit 1 fi -# Old versions of curl don't understand file:// URLs fetch () { - url=$1 - if curl --fail --silent --max-time 60 $url ; then - return 0 - else - if [ -f ${url#file://} ] ; then - cat ${url#file://} - return 0 - fi - fi - return 1 + curl --fail --silent --max-time 60 "$1" } +# hard to find two mirrors with a similar layout +# set list of attempted locations according to releasever +if [ $releasever -ge 7 ] ; then + attempts=" +linux/releases/$releasever/Everything/$basearch/os +$releasever/Everything/$basearch/os +core/$releasever/Everything/$basearch/os +linux/core/$releasever/$basearch/os +" +else + attempts=" +linux/core/$releasever/$basearch/os +core/$releasever/$basearch/os +$releasever/$basearch/os +" +fi + +echo "$0: candidate mirrors" for mirror in "${mirrors[@]}" ; do - baseurl=$mirror/linux/core/$releasever/$basearch/os - if fetch $baseurl/repodata/repomd.xml >/dev/null ; then - break - fi - unset baseurl + echo "* candidate mirror $mirror" +done +baseurl="" +for mirror in "${mirrors[@]}" ; do + for attempt in $attempts; do + attempturl=$mirror/$attempt + if fetch $attempturl/repodata/repomd.xml >/dev/null ; then + baseurl=$attempturl + break 2 + fi + done done if [ -z "$baseurl" ] ; then - echo "Error: linux/core/$releasever/$basearch/os/repodata/repomd.xml" + echo "Error: $releasever/$basearch/os/repodata/repomd.xml" echo " could not be found in any of the following locations:" echo for mirror in ${mirrors[@]} ; do - echo $mirror + for attempt in $attempts ; do + echo $mirror/$attempt + done done echo usage @@ -144,46 +187,42 @@ if [ $verbose -eq 0 ] ; then exec 2>/dev/null fi -# Scratch space -tmp=$(mktemp -d /tmp/mkfedora.XXXXXX) - -# Minimally initialize /dev in reference image. If installed, the dev -# or udev RPMs will fill in the rest. -mkdir -p $vroot/dev -mknod -m 666 $vroot/dev/null c 1 3 -mknod -m 666 $vroot/dev/zero c 1 5 -mknod -m 666 $vroot/dev/full c 1 7 -mknod -m 644 $vroot/dev/random c 1 8 -mknod -m 644 $vroot/dev/urandom c 1 9 -mknod -m 666 $vroot/dev/tty c 5 0 -mknod -m 666 $vroot/dev/ptmx c 5 2 -# For bash command substitution -ln -nsf ../proc/self/fd $vroot/dev/fd -# For df and linuxconf -touch $vroot/dev/hdv1 - -# Mount /dev/pts in reference image -mkdir -p $vroot/dev/pts -mount -t devpts none $vroot/dev/pts +# Do not tolerate errors +set -e + +## 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' +# xxx fixme - this must be reviewed once we get the stuff running +cat > /etc/rpm/macros <$vroot/etc/yum.conf <>$vroot/etc/yum.conf <>$vroot/etc/yum.conf <&3 -yum -c $vroot/etc/yum.conf --installroot=$vroot -y install glibc +yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes install glibc # Go, baby, go -if [ ${#groups[*]} -gt 0 ] ; then - echo "* Installing optional groups" >&3 - yum -c $vroot/etc/yum.conf --installroot=$vroot -y \ - groupinstall "${groups[@]}" +if [ ${#packages[*]} -gt 0 ] ; then + echo "* Installing optional packages" "${packages[@]}" >&3 + yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes \ + install "${packages[@]}" + if ! rpm --root $vroot -q "${packages[@]}" >/dev/null ; then + echo "* Warning: Missing packages" + rpm --root $vroot -q "${packages[@]}" | grep "not installed" + fi fi -if [ ${#packages[*]} -gt 0 ] ; then - echo "* Installing optional packages" >&3 - yum -c $vroot/etc/yum.conf --installroot=$vroot -y \ - install "${packages[@]}" +if [ ${#groups[*]} -gt 0 ] ; then + ## call yum sequentially to get finer-grained info on dependencies + for grp in "${groups[@]}" ; do + echo "* Installing optional group $grp" >&3 + yum -c $vroot/etc/yum.conf --installroot=$vroot -y $excludes \ + groupinstall "$grp" + done fi # FC2 dev %preinstall checks /proc/mounts to make sure that /dev is @@ -322,8 +389,15 @@ yum -c $vroot/etc/yum.conf --installroot=$vroot -y \ # Clean RPM state rm -f $vroot/var/lib/rpm/__db* -# Disable all services in reference image -chroot $vroot /bin/sh -c "/sbin/chkconfig --list | awk '{ print \$1 }' | xargs -i /sbin/chkconfig {} off" +# Set time zone to UTC +if [ -f $vroot/usr/share/zoneinfo/UTC -a -f $vroot/etc/localtime ] ; then + rm -f $vroot/etc/localtime + ln -s /usr/share/zoneinfo/UTC $vroot/etc/localtime +fi + + +# remove trap handler, as we are about to call it directly. +trap - ERR INT # Clean up cleanup