aboutsummaryrefslogtreecommitdiffstats
path: root/build/f_isoroot/f_repobuild/select_ubuntu_repo.sh
blob: 7b134e73c76d0dbab96a7d4873a087fd6b0086c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
##############################################################################
# Copyright (c) 2015,2016 Ericsson AB and others.
# mskalski@mirantis.com
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

# Try to choose close ubuntu mirror

# Some Ubuntu mirrors seem less reliable for this type of mirroring -
# as they are discoved they can be added to the blacklist below in order
# for them not to be considered.
BLACKLIST="mirrors.se.eu.kernel.org mirror.its.dal.ca"

for url in $(curl -s http://mirrors.ubuntu.com/mirrors.txt)
do
    host=$(echo $url | cut -d'/' -f3)
    echo ${BLACKLIST} | grep -q ${host} && continue
    if curl -s -o /dev/null --head --fail "$url"; then
      echo $url
      exit 0
    else
      continue
    fi
done

# If no suitable local mirror can be found,
# the default archive is returned instead.
echo "http://archive.ubuntu.com/ubuntu/"