From f932d2d1296ebec8d69e2a33fd485f6d675d56c0 Mon Sep 17 00:00:00 2001 From: Xicheng Chang Date: Thu, 6 Nov 2014 21:34:07 -0800 Subject: [PATCH] Add automatic source/mirror selection.(bug #1389425) Remove region selection. Change-Id: Ic59d28d9cb710ab79f81cdacf93125f2567238d3 --- install/cobbler.sh | 33 ++++++++++++++++++++------------- install/compass_web.sh | 10 ++++++---- install/install.conf | 7 ++++--- install/install.sh | 12 +++++++++--- install/install_func.sh | 18 ++++++++++++++++++ install/prepare.sh | 41 ++++++++++++++++++++++++++++------------- install/setup_env.sh | 1 - 7 files changed, 85 insertions(+), 37 deletions(-) diff --git a/install/cobbler.sh b/install/cobbler.sh index c3041d78..038226ca 100755 --- a/install/cobbler.sh +++ b/install/cobbler.sh @@ -218,6 +218,12 @@ fi # download packages cd /var/lib/cobbler/repo_mirror/centos_ppa_repo/ +fastesturl http://mirrors.hustunique.com http://mirror.centos.org +if [[ "$?" != "0" ]]; then + echo "failed to determine the fastest url for downloading centos ppa packages" + exit 1 +fi +read -r PPA_REPO_URL& /dev/null +if [[ "$?" != "0" ]]; then + echo "failed to install bc" + exit 1 +else + echo "bc is installed" +fi + while [ $1 ]; do flags=$1 param=${flags/'--'/''} @@ -158,9 +167,6 @@ loadvars() done fi } -echo -e "\x1b[32mAvailable Regions are asia/america, other REGIONs please use default: america\x1b[37m" -loadvars REGION "america" - loadvars NIC "eth0" sudo ifconfig $NIC diff --git a/install/install_func.sh b/install/install_func.sh index c8852f5b..8f9aac64 100755 --- a/install/install_func.sh +++ b/install/install_func.sh @@ -1,6 +1,24 @@ #!/bin/bash # +fastesturl() +{ + shortest=99999 + fastest_url="" + while [ $1 ]; do + url=$1 + short_url=$(echo $url|cut -d '/' -f3) + time=`curl -o /dev/null -s -w %{time_total} $short_url` + if [ $(echo "$shortest > $time" | bc) -eq 1 ]; then + shortest=$time + echo "$url" > /tmp/url + fastest_url=$url + fi + shift + done + echo "$fastest_url is the fastest source, using it" +} + copy2dir() { repo=$1 diff --git a/install/prepare.sh b/install/prepare.sh index b2ef5a04..83a46cac 100755 --- a/install/prepare.sh +++ b/install/prepare.sh @@ -213,6 +213,12 @@ else fi # download cobbler related packages +fastesturl "http://mirrors.hustunique.com" "http://mirror.centos.org" +if [[ "$?" != "0" ]]; then + echo "failed to determine the fastest source for centos ppa rpms" + exit 1 +fi +read -r CENTOS_PPA_SOURCE