Merge "Small updates to build-requirements for docker stuff. fixed whitespace x2...
[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 return_url=0
15
16 while [ "$1" != "" ]; do
17     case $1 in
18         -u | --url )   shift
19                        return_url=1
20                        ;;
21     # Shift all the parameters down by one
22     esac
23     shift
24 done
25
26
27 cnt=0
28 while [ $cnt -lt 4 ]
29 do
30     for url in $(curl -s http://mirrors.ubuntu.com/mirrors.txt)
31     do
32         host=$(echo $url | cut -d'/' -f3)
33         if $RSYNC "${host}::ubuntu/." &> /dev/null
34         then
35             if ! $RSYNC "${host}::ubuntu/Archive-Update-in-Progress*" &> /dev/null
36             then
37                 if [ "$return_url" = "1" ]; then
38                     echo "$url"
39                     exit 0
40                 else
41                     echo "$host"
42                     exit 0
43                 fi
44             fi
45         fi
46     done
47     cnt=$[cnt + 1]
48     sleep 15
49 done
50
51 if [ "$return_url" = "1" ]; then
52     echo "http://archive.ubuntu.com/ubuntu/"
53 else
54     echo "archive.ubuntu.com"
55 fi