From ec771c247a14cedcb44fa0686f922f13ab29ed1d Mon Sep 17 00:00:00 2001 From: Roger Luethi Date: Wed, 18 Jun 2014 08:17:17 +0200 Subject: [PATCH] Configure apt and update index This script configures apt to use a proxy (if VM_PROXY is set), adds the ubuntu-cloud repo (release set by OPENSTACK_RELEASE) and updates the apt index. Partial-Bug: 1312764 Implements: blueprint openstack-training-labs Change-Id: I6a426ee31746424a761fc8cd6d81723ac7740f04 --- labs/scripts/apt_init.sh | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 labs/scripts/apt_init.sh diff --git a/labs/scripts/apt_init.sh b/labs/scripts/apt_init.sh new file mode 100644 index 00000000..69eecca6 --- /dev/null +++ b/labs/scripts/apt_init.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +TOP_DIR=$(cd $(dirname "$0")/.. && pwd) +source "$TOP_DIR/config/paths" +source "$CONFIG_DIR/openstack" +# Pick up VM_PROXY +source "$CONFIG_DIR/localrc" +source "$LIB_DIR/functions.guest" + +indicate_current_auto + +exec_logfile + +function set_apt_proxy { + local PRX_KEY="Acquire::http::Proxy" + local APT_FILE=/etc/apt/apt.conf + + if [ -f $APT_FILE ] && grep -q $PRX_KEY $APT_FILE; then + # apt proxy has already been set (by preseed/kickstart) + if [ -n "${VM_PROXY-}" ]; then + # Replace with requested proxy + sudo sed -i "s#^\($PRX_KEY\).*#\1 \"$VM_PROXY\";#" $APT_FILE + else + # No proxy requested -- remove + sudo sed -i "s#^$PRX_KEY.*##" $APT_FILE + fi + elif [ -n "${VM_PROXY-}" ]; then + # Proxy requested, but none configured: add line + echo "$PRX_KEY \"$VM_PROXY\";" | sudo tee -a $APT_FILE + fi +} + +set_apt_proxy + +# Get apt index files +sudo apt-get update + +# cloud-keyring to verify packages from ubuntu-cloud repo +sudo apt-get install ubuntu-cloud-keyring + +# Install packages needed for add-apt-repository +sudo apt-get -y install software-properties-common python-software-properties +sudo add-apt-repository -y "cloud-archive:$OPENSTACK_RELEASE" + +# Get index files only for ubuntu-cloud repo but keep standard lists +sudo apt-get update \ + -o Dir::Etc::sourcelist="sources.list.d/cloudarchive-$OPENSTACK_RELEASE.list" \ + -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0"