- create new package vserver-system-packages that contain the packages
authorMark Huang <mlhuang@cs.princeton.edu>
Wed, 5 Apr 2006 20:32:28 +0000 (20:32 +0000)
committerMark Huang <mlhuang@cs.princeton.edu>
Wed, 5 Apr 2006 20:32:28 +0000 (20:32 +0000)
  necessary to bootstrap pl_conf and pl_netflow

system-packages.sh [new file with mode: 0755]
vserver-reference.spec

diff --git a/system-packages.sh b/system-packages.sh
new file mode 100755 (executable)
index 0000000..3147f54
--- /dev/null
@@ -0,0 +1,166 @@
+#!/bin/bash
+#
+# Download dependencies that would be necessary to build the
+# pl_netflow and pl_conf root slices from the vserver-reference image.
+#
+# Mark Huang <mlhuang@cs.princeton.edu>
+# Copyright (C) 2004-2006 The Trustees of Princeton University
+#
+# $Id$
+#
+
+export PATH=/sbin:/bin:/usr/sbin:/usr/bin
+
+vroot=$PWD/vservers/vserver-reference
+rpms=$PWD/vservers/system-packages
+install -d -m 755 $rpms
+
+# curl can't list file:// URLs
+list ()
+{
+    url=$1
+    if [ -e ${url#file://} ] ; then
+       /bin/ls ${url#file://}
+    else
+       curl --fail --silent --max-time 60 $url
+    fi
+}
+
+# pl_netflow requires third party MySQL RPMs
+mysql_mirrors=(
+file:///usr/share/mirrors/mysql
+http://boot.planet-lab.org/install-rpms/3rdparty
+)
+
+for mirror in "${mysql_mirrors[@]}" ; do
+    baseurl=$mirror/
+    if list $baseurl | grep -q "MySQL-server.*rpm" ; then
+       break
+    fi
+    unset baseurl
+done
+
+if [ -z "$baseurl" ] ; then
+    echo "Error: MySQL-server RPM package"
+    echo "       could not be found in any of the following locations:"
+    echo
+    for mirror in ${mysql_mirrors[@]} ; do
+       echo $mirror
+    done
+    echo
+    exit 1
+fi
+
+# Add MySQL mirror to yum.conf
+if ! grep -q mysql $vroot/etc/yum.conf ; then
+    cat >>$vroot/etc/yum.conf <<EOF
+
+[mysql]
+name=MySQL
+baseurl=$baseurl
+EOF
+fi
+
+# Space separated list of required packages
+pl_netflow="netflow"
+pl_conf="sidewinder-PlanetLab-SCS sidewinder-common"
+
+for slice in pl_netflow pl_conf ; do
+    packages=${!slice}
+    dependencies=()
+
+    if yum --help | grep -q shell ; then
+       while read -a words ; do
+           if [ ${#words[*]} -lt 5 ] ; then
+               continue
+           fi
+
+           # netflow i386 3.1-23.planetlab.2006.04.04 bootstrap 61 k
+           package=${words[0]}
+           arch=${words[1]}
+           version=${words[2]}
+           # Remove the epoch from the version
+           version=${version##*:}
+           repository=${words[3]}
+
+           if [ -f $rpms/$package-$version.$arch.rpm ] ; then
+               break
+           fi
+
+           baseurl=
+           while read line ; do
+               if grep -q "^\[$repository\]" <<<$line ; then
+                   baseurl=$repository
+               elif [ "$baseurl" = "$repository" ] && grep -q "^baseurl=" <<<$line ; then
+                   eval $line
+
+                   # We could parse headers/header.info and/or
+                   # repodata/primary.xml.gz to figure out where the
+                   # package actually is within the repository, but
+                   # it would be too much trouble. Just try
+                   # downloading it from one of the common
+                   # subdirectories.
+                   echo "* $slice: $repository $package-$version.$arch.rpm"
+                   for subdirectory in "" Fedora/RPMS $arch ; do
+                       if curl --fail --silent --max-time 60 $baseurl/$subdirectory/$package-$version.$arch.rpm \
+                           >$rpms/$package-$version.$arch.rpm ; then
+                           break
+                       fi
+                       rm -f $rpms/$package-$version.$arch.rpm
+                   done
+
+                   # Assert that we got it successfully
+                   if [ ! -f $rpms/$package-$version.$arch.rpm ] ; then
+                       echo "Failed to fetch $package-$version.$arch.rpm from $repository" >&2
+                       false
+                   fi
+
+                   dependencies[${#dependencies[*]}]=$package-$version.$arch.rpm
+                   break
+               fi
+           done <$vroot/etc/yum.conf
+       done < <(yum -c $vroot/etc/yum.conf --installroot=$vroot shell <<EOF
+install $packages
+transaction solve
+transaction list
+EOF
+       )
+    else
+        # This is pretty fucked up. Turn on verbose debugging and the
+        # --download-only option, which, contrary to what you might
+        # think the option means, downloads the headers, not the
+        # packages themselves. In any case, verbose debugging prints
+        # out the baseURL and path of each RPM that it would download
+        # if --download-only were not specified.
+       baseURL=
+       path=
+       while read line ; do
+           if [ -z "$baseURL" ] ; then
+               baseURL=$(sed -ne 's/failover: baseURL = \(.*\)/\1/p' <<<$line)
+           elif [ -z "$path" ] ; then
+               path=$(sed -ne 's/failover: path = \(.*\)/\1/p' <<<$line)
+           else
+               if [ "${path##*.}" = "rpm" ] ; then
+                   echo "* $slice: $(basename $path)"
+                   curl --fail --silent --max-time 60 $baseURL/$path >$rpms/$(basename $path)
+                   dependencies[${#dependencies[*]}]=$(basename $path)
+               fi
+               baseURL=
+               path=
+           fi
+       done < <(yum -d 3 -c $vroot/etc/yum.conf --installroot=$vroot -y --download-only install $packages 2>&1)
+    fi
+
+    for dependency in "${dependencies[@]}" ; do
+       echo $dependency
+    done >$rpms/$slice.lst
+done
+
+# Clean yum cache
+yum -c $vroot/etc/yum.conf --installroot=$vroot -y \
+    clean all
+
+# Clean RPM state
+rm -f $vroot/var/lib/rpm/__db*
+
+exit 0
index 5170870..7774384 100644 (file)
@@ -1,4 +1,4 @@
-%define name vserver-reference
+%define name vserver
 %define version 3.1
 %define release 3%{?pldistro:.%{pldistro}}%{?date:.%{date}}
 
 %define version 3.1
 %define release 3%{?pldistro:.%{pldistro}}%{?date:.%{date}}
 
@@ -17,13 +17,30 @@ Group: Applications/System
 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
 Requires: util-vserver, e2fsprogs, yum
 
 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
 Requires: util-vserver, e2fsprogs, yum
 
-AutoReqProv: no
 %define debug_package %{nil}
 
 %description
 %define debug_package %{nil}
 
 %description
+This package does not really exist.
+
+%package reference
+Summary: VServer reference image
+Group: Applications/System
+AutoReqProv: no
+
+%description reference
 This package creates the virtual server (VServer) reference image used
 as the installation base for new PlanetLab slivers.
 
 This package creates the virtual server (VServer) reference image used
 as the installation base for new PlanetLab slivers.
 
+%package system-packages
+Summary: System slice packages
+Group: Applications/System
+Requires: vserver-reference = %{version}-%{release}
+AutoReqProv: no
+
+%description system-packages
+This package installs the RPMS necessary to create system ("root
+ resource") slices from the virtual server (VServer) reference image.
+
 %prep
 %setup -q
 
 %prep
 %setup -q
 
@@ -33,14 +50,15 @@ pushd vserver-reference
 # Not until we can get the build server to run Fedora Core 4 or an
 # updated version of yum.
 #./build.sh -r 4
 # Not until we can get the build server to run Fedora Core 4 or an
 # updated version of yum.
 #./build.sh -r 4
+./system-packages.sh
 popd
 
 %install
 rm -rf $RPM_BUILD_ROOT
 
 pushd vserver-reference
 popd
 
 %install
 rm -rf $RPM_BUILD_ROOT
 
 pushd vserver-reference
-install -D -m 755 %{name}.init $RPM_BUILD_ROOT/%{_initrddir}/%{name}
-find vservers/vserver-reference | cpio -p -d -u $RPM_BUILD_ROOT/
+install -D -m 755 vserver-reference.init $RPM_BUILD_ROOT/%{_initrddir}/vserver-reference
+find vservers | cpio -p -d -u $RPM_BUILD_ROOT/
 popd
 
 %clean
 popd
 
 %clean
@@ -57,14 +75,18 @@ if [ -n "$SUDO_USER" ] ; then
     chown -R $SUDO_USER %{_rpmdir}/%{_arch}
 fi
 
     chown -R $SUDO_USER %{_rpmdir}/%{_arch}
 fi
 
-%files
+%files reference
 %defattr(-,root,root)
 %defattr(-,root,root)
-%{_initrddir}/%{name}
+%{_initrddir}/vserver-reference
 /vservers/vserver-reference
 
 /vservers/vserver-reference
 
+%files system-packages
+%defattr(-,root,root)
+/vservers/system-packages
+
 %define vcached_pid /var/run/vcached.pid
 
 %define vcached_pid /var/run/vcached.pid
 
-%pre
+%pre reference
 # Stop vcached
 if [ -r %{vcached_pid} ] ; then
     kill $(cat %{vcached_pid})
 # Stop vcached
 if [ -r %{vcached_pid} ] ; then
     kill $(cat %{vcached_pid})
@@ -83,9 +105,9 @@ fi
 # Allow vcached to run again
 rm -f %{vcached_pid}
 
 # Allow vcached to run again
 rm -f %{vcached_pid}
 
-%post
-chkconfig --add %{name}
-chkconfig %{name} on
+%post reference
+chkconfig --add vserver-reference
+chkconfig vserver-reference on
 [ "$PL_BOOTCD" = "1" ] || service vserver-reference start
 
 %changelog
 [ "$PL_BOOTCD" = "1" ] || service vserver-reference start
 
 %changelog