]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
detect APT_PROXY from host apt.conf
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Tue, 23 Apr 2013 13:37:41 +0000 (08:37 -0500)
committerStéphane Graber <stgraber@ubuntu.com>
Tue, 23 Apr 2013 22:57:18 +0000 (00:57 +0200)
Introduce a new HTTP_PROXY variable in /etc/default/lxc.  If unset or
set to none, then behavior continues as before.  If set to 'apt', then
any http::proxy set in apt.conf will be used as http_proxy for
debootstrap, and specified in the container's
/etc/apt/apt.conf.d/70proxy.  If set to something else, then the
value of HTTP_PROXY will be used as http_proxy for debootstrap and
specified in the container's 70proxy.

Changelog: (apr 23) merge the two apt proxy detection functions.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
templates/lxc-ubuntu.in

index 8a92f955bb52bb6cae528b4236957e2736287802..83311fddeb523b64c2117c993d1605a19350188d 100644 (file)
@@ -134,12 +134,48 @@ finalize_user()
     return 0
 }
 
+#
+# Choose proxies for container
+# http_proxy will be used by debootstrap on the host.
+# APT_PROXY will be used to set /etc/apt/apt.conf.d/70proxy in the container.
+#
+choose_container_proxy()
+{
+    local rootfs=$1
+    local arch=$2
+
+    if [ -z "$HTTP_PROXY" ]; then
+        HTTP_PROXY="none"
+    fi
+    case "$HTTP_PROXY" in
+    none)
+        APT_PROXY=
+        ;;
+    apt)
+        RES=`apt-config shell APT_PROXY Acquire::http::Proxy`
+        eval $RES
+        [ -z "$APT_PROXY" ] || export http_proxy=$APT_PROXY
+        ;;
+    *)
+        APT_PROXY=$HTTP_PROXY
+        export http_proxy=$HTTP_PROXY
+        ;;
+    esac
+}
+
 write_sourceslist()
 {
     # $1 => path to the rootfs
     # $2 => architecture we want to add
     # $3 => whether to use the multi-arch syntax or not
 
+    if [ -n "$APT_PROXY" ]; then
+        mkdir -p $rootfs/etc/apt/apt.conf.d
+        cat > $rootfs/etc/apt/apt.conf.d/70proxy << EOF
+Acquire::http::Proxy "$APT_PROXY" ;
+EOF
+    fi
+
     case $2 in
       amd64|i386)
             MIRROR=${MIRROR:-http://archive.ubuntu.com/ubuntu}
@@ -206,6 +242,7 @@ download_ubuntu()
         return 1
     fi
 
+    choose_container_proxy $cache/partial-$arch/ $arch
     # download a mini ubuntu into a cache
     echo "Downloading ubuntu $release minimal ..."
     if [ -n "$(which qemu-debootstrap)" ]; then