Merge "Smaller non-HA virtual deployment template"
[fuel.git] / build / f_isoroot / f_repobuild / select_ubuntu_repo.sh
1 #!/bin/bash
2
3 RSYNC="rsync -4 --contimeout 5 --no-motd --list-only"
4
5 # try to choose close ubuntu mirror which support rsync protocol
6 # https://bugs.launchpad.net/fuel/+bug/1459252
7
8 # A minor modificiation of Michal Skalski's original Makefile version
9 # to only consider repos where no repo updates are in progress (as
10 # that may have us hanging quite a while otherwise). If no suitable
11 # local mirror can be found after four attempts, the default archive
12 # is returned instead.
13
14 cnt=0
15 while [ $cnt -lt 4 ]
16 do
17     for url in $(curl -s http://mirrors.ubuntu.com/mirrors.txt)
18     do
19         host=$(echo $url | cut -d'/' -f3)
20         if $RSYNC "${host}::ubuntu/." &> /dev/null
21         then
22             if ! $RSYNC "${host}::ubuntu/Archive-Update-in-Progress*" &> /dev/null
23             then
24                 echo "$host"
25                 exit 0
26             fi
27         fi
28     done
29     cnt=$[cnt + 1]
30     sleep 15
31 done
32 echo "archive.ubuntu.com"
33