From 0ba568d42e53c4526e5735ac5181c0d036d4998b Mon Sep 17 00:00:00 2001 From: Jeremy Stanley Date: Thu, 21 Jul 2016 18:40:55 +0000 Subject: [PATCH] Refactor mirror configuration script for scaling To make it easier to follow additions to configure_mirror.sh as we grow more and more mirrors of things, separate the configuration file contents into separate variable definitions so they don't make the script logic as hard to follow. Change-Id: I421da8eefeb040d9daded59b8d62158f0aa1610b Signed-off-by: Paul Belanger --- nodepool/scripts/configure_mirror.sh | 141 +++++++++++++++++---------- 1 file changed, 89 insertions(+), 52 deletions(-) diff --git a/nodepool/scripts/configure_mirror.sh b/nodepool/scripts/configure_mirror.sh index 01c4b433fc..c253f33864 100755 --- a/nodepool/scripts/configure_mirror.sh +++ b/nodepool/scripts/configure_mirror.sh @@ -21,6 +21,9 @@ source /etc/nodepool/provider # Generate the AFS Slug from the host system. source /usr/local/jenkins/slave_scripts/afs-slug.sh +LSBDISTID=$(lsb_release -is) +LSBDISTCODENAME=$(lsb_release -cs) + NODEPOOL_MIRROR_HOST=${NODEPOOL_MIRROR_HOST:-mirror.$NODEPOOL_REGION.$NODEPOOL_CLOUD.openstack.org} NODEPOOL_MIRROR_HOST=$(echo $NODEPOOL_MIRROR_HOST|tr '[:upper:]' '[:lower:]') NODEPOOL_PYPI_MIRROR=${NODEPOOL_PYPI_MIRROR:-http://$NODEPOOL_MIRROR_HOST/pypi/simple} @@ -32,67 +35,39 @@ NODEPOOL_CEPH_MIRROR=${NODEPOOL_CEPH_MIRROR:-http://$NODEPOOL_MIRROR_HOST/ceph-d NODEPOOL_UCA_MIRROR=${NODEPOOL_UCA_MIRROR:-http://$NODEPOOL_MIRROR_HOST/ubuntu-cloud-archive} NODEPOOL_NPM_MIRROR=${NODEPOOL_NPM_MIRROR:-http://$NODEPOOL_MIRROR_HOST/npm/} -cat >/tmp/pip.conf </home/jenkins/.pydistutils.cfg </home/jenkins/.npmrc </tmp/pip.conf +sudo mv /tmp/pip.conf /etc/ +sudo chown root:root /etc/pip.conf +sudo chmod 0644 /etc/pip.conf + +# Write jenkins user distutils/setuptools configuration used by easy_install +echo "$PYDISTUTILS_CFG" >/home/jenkins/.pydistutils.cfg + +# Write jenkins user npm configuration +echo "$NPMRC" >/home/jenkins/.npmrc + +# NOTE(pabelanger): We don't actually have mirrors for ubuntu-precise, so skip +# them. +if [ "$LSBDISTID" == "Ubuntu" ] && [ "$LSBDISTCODENAME" != 'precise' ]; then + echo "$UBUNTU_SOURCES_LIST" >/tmp/sources.list + sudo mv /tmp/sources.list /etc/apt/ + sudo chown root:root /etc/apt/sources.list + sudo chmod 0644 /etc/apt/sources.list + + # Opt in repos. Jobs that want to take advantage of them can copy or + # symlink them into /etc/apt/sources.list.d/ + sudo mkdir -p /etc/apt/sources.list.available.d + + # Ceph + echo "$CEPH_SOURCES_LIST" >/tmp/ceph-deb-hammer.list + sudo mv /tmp/ceph-deb-hammer.list /etc/apt/sources.list.available.d/ + + # Ubuntu Cloud Archive + echo "$UCA_SOURCES_LIST" >/tmp/ubuntu-cloud-archive.list + sudo mv /tmp/ubuntu-cloud-archive.list /etc/apt/sources.list.available.d/ + + sudo chown root:root /etc/apt/sources.list.available.d/* + sudo chmod 0644 /etc/apt/sources.list.available.d/* + + if [ "$LSBDISTCODENAME" != 'precise' ] ; then + # Turn off multi-arch + sudo dpkg --remove-architecture i386 + fi + # Turn off checking of GPG signatures + echo "$APT_CONF_UNAUTHENTICATED" >/tmp/99unauthenticated + sudo mv /tmp/99unauthenticated /etc/apt/apt.conf.d/ + sudo chown root:root /etc/apt/apt.conf.d/99unauthenticated + sudo chmod 0644 /etc/apt/apt.conf.d/99unauthenticated + +elif [ "$LSBDISTID" == "Debian" ] ; then + echo "$DEBIAN_SOURCES_LIST" >/tmp/sources.list + sudo mv /tmp/sources.list /etc/apt/ + sudo chown root:root /etc/apt/sources.list + sudo chmod 0644 /etc/apt/sources.list + +elif [ "$LSBDISTID" == "CentOS" ]; then + echo "$YUM_REPOS_CENTOS_BASE" >/tmp/CentOS-Base.repo + sudo mv /tmp/CentOS-Base.repo /etc/yum.repos.d/ + echo "$YUM_REPOS_EPEL" >/tmp/epel.repo + sudo mv /tmp/epel.repo /etc/yum.repos.d/ + sudo chown root:root /etc/yum.repos.d/* + sudo chmod 0644 /etc/yum.repos.d/* + fi