Add automatic source/mirror selection.(bug #1389425)
Remove region selection. Change-Id: Ic59d28d9cb710ab79f81cdacf93125f2567238d3
This commit is contained in:
parent
00dd364d8f
commit
f932d2d129
@ -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</tmp/url
|
||||
centos_ppa_repo_packages="
|
||||
ntp-4.2.6p5-1.${CENTOS_IMAGE_TYPE_OTHER}${CENTOS_IMAGE_VERSION_MAJOR}.${CENTOS_IMAGE_TYPE,,}.${CENTOS_IMAGE_ARCH}.rpm
|
||||
openssh-clients-5.3p1-94.${CENTOS_IMAGE_TYPE_OTHER}${CENTOS_IMAGE_VERSION_MAJOR}.${CENTOS_IMAGE_ARCH}.rpm
|
||||
@ -227,11 +233,7 @@ wget-1.12-1.8.${CENTOS_IMAGE_TYPE_OTHER}${CENTOS_IMAGE_VERSION_MAJOR}.${CENTOS_I
|
||||
ntpdate-4.2.6p5-1.${CENTOS_IMAGE_TYPE_OTHER}${CENTOS_IMAGE_VERSION_MAJOR}.${CENTOS_IMAGE_TYPE,,}.${CENTOS_IMAGE_ARCH}.rpm
|
||||
yum-plugin-priorities-1.1.30-14.${CENTOS_IMAGE_TYPE_OTHER}${CENTOS_IMAGE_VERSION_MAJOR}.noarch.rpm"
|
||||
for f in $centos_ppa_repo_packages; do
|
||||
if [ "$REGION" == "asia" ]; then
|
||||
download http://mirrors.yun-idc.com/${CENTOS_IMAGE_TYPE,,}/${CENTOS_IMAGE_VERSION}/os/${CENTOS_IMAGE_ARCH}/Packages/$f $f copy /var/lib/cobbler/repo_mirror/centos_ppa_repo/ || exit $?
|
||||
else
|
||||
download http://mirror.centos.org/${CENTOS_IMAGE_TYPE,,}/${CENTOS_IMAGE_VERSION}/os/${CENTOS_IMAGE_ARCH}/Packages/$f $f copy /var/lib/cobbler/repo_mirror/centos_ppa_repo/ || exit $?
|
||||
fi
|
||||
download $PPA_REPO_URL/${CENTOS_IMAGE_TYPE,,}/${CENTOS_IMAGE_VERSION}/os/${CENTOS_IMAGE_ARCH}/Packages/$f $f copy /var/lib/cobbler/repo_mirror/centos_ppa_repo/ || exit $?
|
||||
done
|
||||
|
||||
centos_ppa_repo_rsyslog_packages="
|
||||
@ -320,11 +322,13 @@ fi
|
||||
|
||||
# import cobbler distro
|
||||
sudo mkdir -p /var/lib/cobbler/iso
|
||||
if [ "$REGION" == "asia" ]; then
|
||||
download "$CENTOS_IMAGE_SOURCE_ASIA" ${CENTOS_IMAGE_NAME}-${CENTOS_IMAGE_ARCH}.iso copy /var/lib/cobbler/iso/ || exit $?
|
||||
else
|
||||
download "$CENTOS_IMAGE_SOURCE" ${CENTOS_IMAGE_NAME}-${CENTOS_IMAGE_ARCH}.iso copy /var/lib/cobbler/iso/ || exit $?
|
||||
fastesturl $CENTOS_IMAGE_SOURCE_ASIA $CENTOS_SOURCE_MIRROR
|
||||
if [[ "$?" != "0" ]]; then
|
||||
echo "failed to determine the fastest source for centos iso"
|
||||
exit 1
|
||||
fi
|
||||
read -r CENTOS_SOURCE</tmp/url
|
||||
download "$CENTOS_SOURCE" ${CENTOS_IMAGE_NAME}-${CENTOS_IMAGE_ARCH}.iso copy /var/lib/cobbler/iso/ || exit $?
|
||||
sudo mkdir -p /mnt/${CENTOS_IMAGE_NAME}-${CENTOS_IMAGE_ARCH}
|
||||
if [ $(mount | grep -c "/mnt/${CENTOS_IMAGE_NAME}-${CENTOS_IMAGE_ARCH} ") -eq 0 ]; then
|
||||
sudo mount -o loop /var/lib/cobbler/iso/${CENTOS_IMAGE_NAME}-${CENTOS_IMAGE_ARCH}.iso /mnt/${CENTOS_IMAGE_NAME}-${CENTOS_IMAGE_ARCH}
|
||||
@ -337,11 +341,14 @@ if [ $(mount | grep -c "/mnt/${CENTOS_IMAGE_NAME}-${CENTOS_IMAGE_ARCH} ") -eq 0
|
||||
else
|
||||
echo "/mnt/${CENTOS_IMAGE_NAME}-${CENTOS_IMAGE_ARCH} has already mounted"
|
||||
fi
|
||||
if [ "$REGION" == "asia" ]; then
|
||||
download "$UBUNTU_IMAGE_SOURCE_ASIA" ${UBUNTU_IMAGE_NAME}-${UBUNTU_IMAGE_ARCH}.iso copy /var/lib/cobbler/iso/ || exit $?
|
||||
else
|
||||
download "$UBUNTU_IMAGE_SOURCE" ${UBUNTU_IMAGE_NAME}-${UBUNTU_IMAGE_ARCH}.iso copy /var/lib/cobbler/iso/ || exit $?
|
||||
|
||||
fastesturl $UBUNTU_IMAGE_SOURCE_ASIA $UBUNTU_IMAGE_SOURCE
|
||||
if [[ "$?" != "0" ]]; then
|
||||
echo "failed to determine the fastest source for ubuntu iso"
|
||||
exit 1
|
||||
fi
|
||||
read -r UBUNTU_SOURCE</tmp/url
|
||||
download "$UBUNTU_SOURCE" ${UBUNTU_IMAGE_NAME}-${UBUNTU_IMAGE_ARCH}.iso copy /var/lib/cobbler/iso/ || exit $?
|
||||
sudo mkdir -p /mnt/${UBUNTU_IMAGE_NAME}-${UBUNTU_IMAGE_ARCH}
|
||||
if [ $(mount | grep -c "/mnt/${UBUNTU_IMAGE_NAME}-${UBUNTU_IMAGE_ARCH} ") -eq 0 ]; then
|
||||
sudo mount -o loop /var/lib/cobbler/iso/${UBUNTU_IMAGE_NAME}-${UBUNTU_IMAGE_ARCH}.iso /mnt/${UBUNTU_IMAGE_NAME}-${UBUNTU_IMAGE_ARCH}
|
||||
|
@ -22,11 +22,13 @@ sudo cp -rf $WEB_HOME/v2 /var/www/compass_web/
|
||||
if [[ $LOCAL_REPO = "y" ]]; then
|
||||
echo "setting up local repo"
|
||||
mkdir -p /tmp/repo
|
||||
if [[ "$REGION" == "asia" ]]; then
|
||||
download $LOCAL_REPO_ASIA local_repo.tar.gz unzip /tmp/repo || exit $?
|
||||
else
|
||||
download https://s3-us-west-1.amazonaws.com/compass-local-repo/local_repo.tar.gz local_repo.tar.gz unzip /tmp/repo || exit $?
|
||||
fastesturl $LOCAL_REPO_ASIA $LOCAL_REPO_US
|
||||
if [[ "$?" != "0" ]]; then
|
||||
echo "failed to determine the fastest local repo source"
|
||||
exit 1
|
||||
fi
|
||||
read -r LOCAL_REPO_SOURCE</tmp/url
|
||||
download $LOCAL_REPO_SOURCE local_repo.tar.gz unzip /tmp/repo || exit $?
|
||||
mv -f /tmp/repo/local_repo/* /var/www/compass_web/v2/
|
||||
if [[ "$?" != "0" ]]; then
|
||||
echo "failed to setup local repo"
|
||||
|
@ -48,7 +48,7 @@ export CENTOS_IMAGE_VERSION=${CENTOS_IMAGE_VERSION:-"${CENTOS_IMAGE_VERSION_MAJO
|
||||
export CENTOS_IMAGE_NAME=${CENTOS_IMAGE_NAME:-"${CENTOS_IMAGE_TYPE}-${CENTOS_IMAGE_VERSION}"}
|
||||
export CENTOS_IMAGE_ARCH=${CENTOS_IMAGE_ARCH:-"x86_64"}
|
||||
export CENTOS_IMAGE_SOURCE=${CENTOS_IMAGE_SOURCE:-"http://mirror.rackspace.com/${CENTOS_IMAGE_TYPE,,}/${CENTOS_IMAGE_VERSION}/isos/${CENTOS_IMAGE_ARCH}/${CENTOS_IMAGE_NAME}-${CENTOS_IMAGE_ARCH}-minimal.iso"}
|
||||
export CENTOS_IMAGE_SOURCE_ASIA=${CENTOS_IMAGE_SOURCE_ASIA:-"http://mirrors.yun-idc.com/${CENTOS_IMAGE_TYPE,,}/${CENTOS_IMAGE_VERSION}/isos/${CENTOS_IMAGE_ARCH}/${CENTOS_IMAGE_NAME}-${CENTOS_IMAGE_ARCH}-minimal.iso"}
|
||||
export CENTOS_IMAGE_SOURCE_ASIA=${CENTOS_IMAGE_SOURCE_ASIA:-"http://mirrors.hustunique.com/${CENTOS_IMAGE_TYPE,,}/${CENTOS_IMAGE_VERSION}/isos/${CENTOS_IMAGE_ARCH}/${CENTOS_IMAGE_NAME}-${CENTOS_IMAGE_ARCH}-minimal.iso"}
|
||||
export UBUNTU_IMAGE_TYPE=${UBUNTU_IMAGE_TYPE:-"Ubuntu"}
|
||||
export UBUNTU_IMAGE_VERSION_MAJOR=${UBUNTU_IMAGE_VERSION_MAJOR:-"12"}
|
||||
export UBUNTU_IMAGE_VERSION_MINOR=${UBUNTU_IMAGE_VERSION_MINOR:-"04"}
|
||||
@ -58,7 +58,7 @@ export UBUNTU_IMAGE_NAME=${UBUNTU_IMAGE_NAME:-"${UBUNTU_IMAGE_TYPE}-${UBUNTU_IMA
|
||||
export UBUNTU_IMAGE_ARCH=${UBUNTU_IMAGE_ARCH:-"x86_64"}
|
||||
export UBUNTU_IMAGE_ARCH_OTHER=${UBUNTU_IMAGE_ARCH_OTHER:-"amd64"}
|
||||
export UBUNTU_IMAGE_SOURCE=${UBUNTU_IMAGE_SOURCE:-"http://releases.ubuntu.com/${UBUNTU_IMAGE_VERSION}/${UBUNTU_IMAGE_TYPE,,}-${UBUNTU_IMAGE_VERSION}${UBUNTU_IMAGE_PATCH_VERSION}-server-${UBUNTU_IMAGE_ARCH_OTHER}.iso"}
|
||||
export UBUNTU_IMAGE_SOURCE_ASIA=${UBUNTU_IMAGE_SOURCE_ASIA:-"http://mirros.ustc.edu.cn/ubuntu-releases/${UBUNTU_IMAGE_VERSION}/${UBUNTU_IMAGE_TYPE,,}-${UBUNTU_IMAGE_VERSION}${UBUNTU_IMAGE_PATCH_VERSION}-server-${UBUNTU_IMAGE_ARCH_OTHER}.iso"}
|
||||
export UBUNTU_IMAGE_SOURCE_ASIA=${UBUNTU_IMAGE_SOURCE_ASIA:-"http://mirrors.ustc.edu.cn/ubuntu-releases/${UBUNTU_IMAGE_VERSION}/${UBUNTU_IMAGE_TYPE,,}-${UBUNTU_IMAGE_VERSION}${UBUNTU_IMAGE_PATCH_VERSION}-server-${UBUNTU_IMAGE_ARCH_OTHER}.iso"}
|
||||
|
||||
export COBBLER_PASSWORD=${COBBLER_PASSWORD:-"cobbler"}
|
||||
|
||||
@ -84,5 +84,6 @@ export SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
export COMPASSDIR=${SCRIPT_DIR}/..
|
||||
export TESTMODE=${TESTMODE:-"False"}
|
||||
|
||||
# Set Local Repo source for Asia
|
||||
# Set Local Repo sources
|
||||
export LOCAL_REPO_US=${LOCAL_REPO_US:-"https://s3-us-west-1.amazonaws.com/compass-local-repo/local_repo.tar.gz"}
|
||||
export LOCAL_REPO_ASIA=${LOCAL_REPO_ASIA:-"http://nj.baidupcs.com/file/5aa212b98c6315fd8c22706c56819aad?bkt=p2-nj-424&fid=2147902224-250528-851286049844289&time=1415230560&sign=FDTAXERB-DCb740ccc5511e5e8fedcff06b081203-Q0KR%2FCMM5y%2B3ha0fXamUW32EywA%3D&to=nb&fm=Nan,B,U,ny&newver=1&newfm=1&flow_ver=3&expires=8h&rt=pr&r=451353717&mlogid=587914427&vuk=2147902224&vbdid=441655319&fin=local_repo.tar.gz"}
|
||||
|
@ -119,6 +119,15 @@ else
|
||||
fi
|
||||
figlet -ctf slant Compass Installer
|
||||
|
||||
# Install bc
|
||||
sudo yum -y install bc >& /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
|
||||
|
@ -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
|
||||
|
@ -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</tmp/url
|
||||
centos_ppa_repo_packages="
|
||||
ntp-4.2.6p5-1.${CENTOS_IMAGE_TYPE_OTHER}${CENTOS_IMAGE_VERSION_MAJOR}.${CENTOS_IMAGE_TYPE,,}.${CENTOS_IMAGE_ARCH}.rpm
|
||||
openssh-clients-5.3p1-94.${CENTOS_IMAGE_TYPE_OTHER}${CENTOS_IMAGE_VERSION_MAJOR}.${CENTOS_IMAGE_ARCH}.rpm
|
||||
@ -222,11 +228,7 @@ ntpdate-4.2.6p5-1.${CENTOS_IMAGE_TYPE_OTHER}${CENTOS_IMAGE_VERSION_MAJOR}.${CENT
|
||||
yum-plugin-priorities-1.1.30-14.${CENTOS_IMAGE_TYPE_OTHER}${CENTOS_IMAGE_VERSION_MAJOR}.noarch.rpm"
|
||||
|
||||
for f in $centos_ppa_repo_packages; do
|
||||
if [ "$REGION" == "asia" ]; then
|
||||
download http://mirrors.yun-idc.com/${CENTOS_IMAGE_TYPE,,}/${CENTOS_IMAGE_VERSION}/os/${CENTOS_IMAGE_ARCH}/Packages/$f $f || exit $?
|
||||
else
|
||||
download http://mirror.centos.org/${CENTOS_IMAGE_TYPE,,}/${CENTOS_IMAGE_VERSION}/os/${CENTOS_IMAGE_ARCH}/Packages/$f $f || exit $?
|
||||
fi
|
||||
download $CENTOS_PPA_SOURCE/${CENTOS_IMAGE_TYPE,,}/${CENTOS_IMAGE_VERSION}/os/${CENTOS_IMAGE_ARCH}/Packages/$f $f || exit $?
|
||||
done
|
||||
|
||||
centos_ppa_repo_rsyslog_packages="
|
||||
@ -248,19 +250,32 @@ download $UBUNTU_CHEF_CLIENT `basename $UBUNTU_CHEF_CLIENT` || exit $?
|
||||
download $CHEF_SRV chef-server || exit $?
|
||||
|
||||
# download os images
|
||||
if [ "$REGION" == "asia" ]; then
|
||||
download "$CENTOS_IMAGE_SOURCE_ASIA" ${CENTOS_IMAGE_NAME}-${CENTOS_IMAGE_ARCH}.iso || exit $?
|
||||
download "$UBUNTU_IMAGE_SOURCE_ASIA" ${UBUNTU_IMAGE_NAME}-${UBUNTU_IMAGE_ARCH}.iso || exit $?
|
||||
else
|
||||
download "$CENTOS_IMAGE_SOURCE" ${CENTOS_IMAGE_NAME}-${CENTOS_IMAGE_ARCH}.iso || exit $?
|
||||
download "$UBUNTU_IMAGE_SOURCE" ${UBUNTU_IMAGE_NAME}-${UBUNTU_IMAGE_ARCH}.iso || exit $?
|
||||
fastesturl $CENTOS_IMAGE_SOURCE $CENTOS_IMAGE_SOURCE_ASIA
|
||||
if [[ "$?" != "0" ]]; then
|
||||
echo "failed to determine the fastest source for centos image"
|
||||
exit 1
|
||||
fi
|
||||
read -r CENTOS_ISO_SOURCE</tmp/url
|
||||
download $CENTOS_ISO_SOURCE ${CENTOS_IMAGE_NAME}-${CENTOS_IMAGE_ARCH}.iso || exit $?
|
||||
|
||||
fastesturl $UBUNTU_IMAGE_SOURCE $UBUNTU_IMAGE_SOURCE_ASIA
|
||||
if [[ "$?" != "0" ]]; then
|
||||
echo "failed to determine the fastest source for ubuntu image"
|
||||
exit 1
|
||||
fi
|
||||
read -r UBUNTU_ISO_SOURCE</tmp/url
|
||||
download $UBUNTU_ISO_SOURCE ${UBUNTU_IMAGE_NAME}-${UBUNTU_IMAGE_ARCH}.iso || exit $?
|
||||
|
||||
# download local repo
|
||||
if [[ $LOCAL_REPO = "y" ]]; then
|
||||
download https://s3-us-west-1.amazonaws.com/compass-local-repo/local_repo.tar.gz local_repo.tar.gz || exit $?
|
||||
fastesturl $LOCAL_REPO_US $LOCAL_REPO_ASIA
|
||||
if [[ "$?" != "0" ]]; then
|
||||
echo "failed to determine the fastest source for local repo"
|
||||
exit 1
|
||||
fi
|
||||
read -r LOCAL_REPO_SOURCE</tmp/url
|
||||
download $LOCAL_REPO_SOURCE local_repo.tar.gz || exit $?
|
||||
fi
|
||||
|
||||
# Install net-snmp
|
||||
echo "install snmp config"
|
||||
if [[ ! -e /etc/snmp ]]; then
|
||||
|
@ -10,6 +10,5 @@ NEXTSERVER=\${NEXTSERVER:-$NEXTSERVER}
|
||||
IP_START=\${IP_START:-$IP_START}
|
||||
IP_END=\${IP_END:-$IP_END}
|
||||
LOCAL_REPO=\${LOCAL_REPO:-$LOCAL_REPO}
|
||||
REGION=\${REGION:-$REGION}
|
||||
EOF
|
||||
chmod ugo+x $SCRIPT_DIR/env.conf
|
||||
|
Loading…
x
Reference in New Issue
Block a user