Updated logic for selecting Ubuntu repo for mirroring 65/2365/5
authorStefan K. Berg <stefan.k.berg@ericsson.com>
Thu, 8 Oct 2015 16:06:00 +0000 (18:06 +0200)
committerStefan K. Berg <stefan.k.berg@ericsson.com>
Fri, 9 Oct 2015 05:15:06 +0000 (07:15 +0200)
A slight improvement to Michal Skalski's original concept just
to filter out repos where updates are in progress (which would
leave us hanging).

Change-Id: Id641b3aa82b991c23b5742d1f64ff79cfbbd708c
Signed-off-by: Stefan K. Berg <stefan.k.berg@ericsson.com>
fuel/build/f_isoroot/f_repobuild/Makefile
fuel/build/f_isoroot/f_repobuild/select_ubuntu_repo.sh [new file with mode: 0755]

index 6bfbd35..03e4cae 100644 (file)
@@ -13,11 +13,7 @@ TOP := $(shell pwd)
 DOCKNAME = fuelrepo
 DOCKVERSION = 1.0
 
-# try to choose close ubuntu mirror which support rsync protocol
-# https://bugs.launchpad.net/fuel/+bug/1459252
-MIRROR_URLS := $(shell curl -s http://mirrors.ubuntu.com/mirrors.txt)
-MIRROR_HOSTS := $(shell for url in ${MIRROR_URLS}; do echo $$url | cut -d'/' -f3; done)
-RSYNC_HOST := $(shell for host in ${MIRROR_HOSTS}; do rsync -4 --contimeout 5 --no-motd --list-only "$${host}::ubuntu/." &> /dev/null && echo $$host && break; done)
+RSYNC_HOST := $(shell ./select_ubuntu_repo.sh)
 
 .PHONY: all
 all: .nailgun
diff --git a/fuel/build/f_isoroot/f_repobuild/select_ubuntu_repo.sh b/fuel/build/f_isoroot/f_repobuild/select_ubuntu_repo.sh
new file mode 100755 (executable)
index 0000000..cb05fe1
--- /dev/null
@@ -0,0 +1,33 @@
+#!/bin/bash
+
+RSYNC="rsync -4 --contimeout 5 --no-motd --list-only"
+
+# try to choose close ubuntu mirror which support rsync protocol
+# https://bugs.launchpad.net/fuel/+bug/1459252
+
+# A minor modificiation of Michal Skalski's original Makefile version
+# to only consider repos where no repo updates are in progress (as
+# that may have us hanging quite a while otherwise). If no suitable
+# local mirror can be found after four attempts, the default archive
+# is returned instead.
+
+cnt=0
+while [ $cnt -lt 4 ]
+do
+    for url in $(curl -s http://mirrors.ubuntu.com/mirrors.txt)
+    do
+        host=$(echo $url | cut -d'/' -f3)
+        if $RSYNC "${host}::ubuntu/." &> /dev/null
+        then
+            if ! $RSYNC "${host}::ubuntu/Archive-Update-in-Progress*" &> /dev/null
+            then
+                echo "$host"
+                exit 0
+            fi
+        fi
+    done
+    cnt=$[cnt + 1]
+    sleep 15
+done
+echo "archive.ubuntu.com"
+