From: Bengt Thuree Date: Thu, 18 Mar 2021 11:24:37 +0000 (+1100) Subject: Fixing netselect in install-python X-Git-Tag: v0.7.7~1 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F37%2F67137%2F9;p=releng%2Fcommon-packer.git Fixing netselect in install-python Actually use the result from netselect Issue-ID: CIMAN-30 Signed-off-by: Bengt Thuree Change-Id: I31b5858dc4b348f383f3b801b17c1aa8547296bd --- diff --git a/provision/install-python.sh b/provision/install-python.sh index 1875db5..c5e9e6e 100755 --- a/provision/install-python.sh +++ b/provision/install-python.sh @@ -10,7 +10,6 @@ ############################################################################## # vi: ts=4 sw=4 sts=4 et : - set -eu -o pipefail -o noglob echo "----> install-python.sh" @@ -67,16 +66,27 @@ if is_ubuntu; then wget http://ftp.au.debian.org/debian/pool/main/n/netselect/${NETSELECT_DEB} dpkg -i ${NETSELECT_DEB} apt install netselect -y - if ! netselect -s 20 -t 40 "$(wget -qO - mirrors.ubuntu.com/mirrors.txt)"; then - echo "NOTE: Unable to refresh 'sources.list'" + + available_mirrors=$(wget -qO - mirrors.ubuntu.com/mirrors.txt) + using_mirror=$(grep deb /etc/apt/sources.list | grep -v \# |head -1 | awk '{print $2}') +## SC2086 -- Double quote to prevent globbing +## I can not have double quote around ${available_mirrors} since that breaks functionality +# shellcheck disable=SC2086 + fastest_mirror=$(sudo netselect -s 1 -t 40 ${available_mirrors} 2> /dev/null | awk '{print $2}') + RESULT=$? + if [ $RESULT -eq 0 ]; then + sed -i "s#${using_mirror}#${fastest_mirror}#" /etc/apt/sources.list + echo "Old mirror : ${using_mirror}" + echo "New mirror : ${fastest_mirror}" + else + echo "NOTE: Unable to select fastest mirror" fi - sed -i 's#http://us.archive.ubuntu.com/ubuntu#http://ubuntu.uberglobalmirror.com/archive#' \ - /etc/apt/sources.list - echo "Installing Python..." + echo "Update and Remove unwanted packages..." apt clean all -y apt -y update + echo "Installing Python..." # Ubuntu 20.04 and newer can default to Python 3 if apt-cache show python-is-python3; then apt-get install -y python-is-python3