This pattern appears several times in mg-debian-installer-update and
I'm about to add another script which uses it.

The centralised version always does "sort -n -r | head -n" to pick out
only the newest version, which only some of the open coded sites did.

Likewise the centralised version checks that $pkgfile is non-empty,
unlike some of the open coded sites.

Signed-off-by: Ian Campbell <ian.campb...@citrix.com>
Acked-by: Ian Jackson <ian.jack...@eu.citrix.com>

---
v4: Fold into mgi-common instead
v3: New patch
---
 mg-debian-installer-update | 33 ++++++++-------------------------
 mgi-common                 | 19 +++++++++++++++++++
 2 files changed, 27 insertions(+), 25 deletions(-)

diff --git a/mg-debian-installer-update b/mg-debian-installer-update
index 770022c..d188d59 100755
--- a/mg-debian-installer-update
+++ b/mg-debian-installer-update
@@ -59,8 +59,6 @@ case ${suite}_${arch} in
         ;;
 esac
 
-pfile=$sbase/non-free/binary-$arch/Packages.gz
-
 dstroot=`getconfig TftpPath`/`getconfig TftpDiBase`/
 date=`date +%Y-%m-%d`-$suite
 dst=$arch/$date
@@ -85,16 +83,13 @@ if [ "x$dtbs" != "x" ] ; then
     gzip -9nf dtbs.tar
 fi
 
+pfile=$sbase/non-free/binary-$arch/Packages.gz
+
 fetch $pfile >Packages.gz
 
 for p in $packages; do
-        set +e
         echo >&2 "collecting $p"
-        pkgfile=`zcat Packages.gz | grep-dctrl -PX $p -nsFilename`
-        rc=$?
-        set -e
-        if [ $rc != 0 ]; then fail "package $p not found"; fi
-        fetch "$site/$pkgfile" >$p.deb
+        fetch_debian_package "$site" Packages.gz -PX $p >$p.deb
         rm -rf x
         dpkg-deb -x $p.deb x
         cd x; pax -x sv4cpio -s '%lib%/lib%' -w -M norm lib >../cpio; cd ..
@@ -117,30 +112,18 @@ if [ x$bpok != x ]; then
 
     if [ x$need_initramfs = xy ]; then
         # Newer kernel often needs a newer initramfs-tools. Make that
-        # available
+        # is available
         echo >&2 "collecting backports initramfs-tools"
-        pkgfile=`zcat Packages.gz \
-                 | grep-dctrl -PX initramfs-tools -nsFilename \
-                 | sort -n -r | head -n1`
-        rc=$?
-        set -e
-        if [ $rc -ne 0 ] || [ x$pkgfile = x ]; then
-           fail "initramfs-tools package not found";
-       fi
-        fetch "$site/$pkgfile" >initramfs-tools.deb
+        fetch_debian_package $site Packages.gz -PX initramfs-tools \
+                      >initramfs-tools.deb
     fi
 
     set +e
     echo >&2 "collecting backports kernel"
     # Be careful to pickup the actual kernel package from the 'linux'
     # source and not a meta package from 'linux-latest'
-    pkgfile=`zcat Packages.gz | grep-dctrl -S linux \
-             | grep-dctrl -Pe ^linux-image-.*-${bpok}$ -nsFilename \
-             | sort -n -r | head -n1`
-    rc=$?
-    set -e
-    if [ $rc != 0 ]; then fail "backports kernel package not found"; fi
-    fetch "$site/$pkgfile" >backports.deb
+    fetch_debian_package $site Packages.gz -Pe ^linux-image-.*-${bpok}$ \
+                  >backports.deb
     dpkg-deb -x backports.deb x
     cp x/boot/vmlinuz-* linux.backports
     # The full set of modules is pretty large and not that
diff --git a/mgi-common b/mgi-common
index de86e8d..ef3d48a 100644
--- a/mgi-common
+++ b/mgi-common
@@ -24,3 +24,22 @@ fetch () {
        # no-cache due to intercepting proxies messing things up.
        curl -s -H 'Pragma: no-cache' $1
 }
+
+# Arguments: <Base URL> <Packages.gz> <grep-dctrl arguments>
+#
+# nb: -nsFilename argument to grep-dctrl is supplied here
+fetch_debian_package () {
+    local site=$1 ; shift 1
+    local pgz=$1 ; shift 1
+
+    set +e
+    pkgfile=`zcat $pgz | grep-dctrl $@ -nsFilename | sort -n -r | head -n1`
+    rc=$?
+    set -e
+
+    if [ $rc -ne 0 ] || [ x$pkgfile = x ]; then
+       fail "package matching $@ not found";
+    fi
+
+    fetch "$site/$pkgfile"
+}
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

Reply via email to