Merge "Do not use rsync for choosing mirror server"
[fuel.git] / build / f_isoroot / f_repobuild / select_ubuntu_repo.sh
1 #!/bin/bash
2 ##############################################################################
3 # Copyright (c) 2015,2016 Ericsson AB and others.
4 # mskalski@mirantis.com
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 # Try to choose close ubuntu mirror
12
13 # Some Ubuntu mirrors seem less reliable for this type of mirroring -
14 # as they are discoved they can be added to the blacklist below in order
15 # for them not to be considered.
16 BLACKLIST="mirrors.se.eu.kernel.org mirror.its.dal.ca"
17
18 for url in $(curl -s http://mirrors.ubuntu.com/mirrors.txt)
19 do
20     host=$(echo $url | cut -d'/' -f3)
21     echo ${BLACKLIST} | grep -q ${host} && continue
22     if curl -s -o /dev/null --head --fail "$url"; then
23       echo $url
24       exit 0
25     else
26       continue
27     fi
28 done
29
30 # If no suitable local mirror can be found,
31 # the default archive is returned instead.
32 echo "http://archive.ubuntu.com/ubuntu/"