]> git.proxmox.com Git - mirror_lxc.git/blobdiff - templates/lxc-ubuntu.in
Make ubuntu templates squid-deb-proxy-client aware
[mirror_lxc.git] / templates / lxc-ubuntu.in
index 3dcc93ab1c0ec5aa989737261118ce46cda7af7f..a707f5b9d3ffc5d7cf0735baad7a756f07ba1644 100644 (file)
@@ -147,6 +147,33 @@ finalize_user()
     return 0
 }
 
+# A function to try and autodetect squid-deb-proxy servers on the local network
+# if either the squid-deb-proxy-client package is installed on the host or
+# a parent container set the 50squid-deb-proxy-client file.
+squid_deb_proxy_autodetect()
+{
+    local apt_discover=/usr/share/squid-deb-proxy-client/apt-avahi-discover
+    local proxy_file=/etc/apt/apt.conf.d/50squid-deb-proxy-client
+    squid_proxy_line=  # That's a global :/
+
+    # Maybe the host is aware of a squid-deb-proxy?
+    if [ -f $apt_discover ]; then
+        echo -n "Discovering squid-deb-proxy..."
+        squid_proxy_line=$($apt_discover)
+        if [ -n "$squid_proxy_line" ]; then
+            echo "found squid-deb-proxy: $squid_proxy_line"
+        else
+            echo "no squid-deb-proxy found"
+        fi
+    fi
+
+    # Are we in a nested container, and the parent already knows of a proxy?
+    if [ -f $proxy_file ]; then
+        # Extract the squid URL from the file (whatever is between "")
+        squid_proxy_line=`cat $proxy_file | sed "s/.*\"\(.*\)\".*/\1/"`
+    fi
+}
+
 #
 # Choose proxies for container
 # http_proxy will be used by debootstrap on the host.
@@ -162,7 +189,13 @@ choose_container_proxy()
     fi
     case "$HTTP_PROXY" in
     none)
-        APT_PROXY=
+        squid_deb_proxy_autodetect
+        if [ -n "$squid_proxy_line" ]; then
+            APT_PROXY=$squid_proxy_line
+            export http_proxy=$squid_proxy_line
+        else
+            APT_PROXY=
+        fi
         ;;
     apt)
         RES=`apt-config shell APT_PROXY Acquire::http::Proxy`
@@ -239,7 +272,7 @@ cleanup()
 suggest_flush()
 {
     echo "Container upgrade failed.  The container cache may be out of date,"
-    echo "in which case flushing the case (see -F in the hep output) may help."
+    echo "in which case flushing the cache (see -F in the help output) may help."
 }
 
 download_ubuntu()
@@ -248,7 +281,7 @@ download_ubuntu()
     arch=$2
     release=$3
 
-    packages_template=${packages_template:-"ssh"}
+    packages_template=${packages_template:-"ssh,vim"}
 
     # Try to guess a list of langpacks to install
     langpacks="language-pack-en"
@@ -338,7 +371,7 @@ install_ubuntu()
     mkdir -p $LOCALSTATEDIR/lock/subsys/
 
     (
-        flock -x 200
+        flock -x 9
         if [ $? -ne 0 ]; then
             echo "Cache repository is busy."
             return 1
@@ -369,7 +402,7 @@ install_ubuntu()
 
         return 0
 
-    ) 200>$LOCALSTATEDIR/lock/subsys/lxc-ubuntu
+    ) 9>$LOCALSTATEDIR/lock/subsys/lxc-ubuntu$release
 
     return $?
 }
@@ -507,7 +540,7 @@ EOF
     fi
 
     # Install Packages in container
-    if [ -n $packages ]
+    if [ -n "$packages" ]
     then
         local packages="`echo $packages | sed 's/,/ /g'`"
         echo "Installing packages: ${packages}"
@@ -519,7 +552,7 @@ EOF
         cat /etc/timezone > $rootfs/etc/timezone
         chroot $rootfs dpkg-reconfigure -f noninteractive tzdata
     elif [ -f /etc/sysconfig/clock ]; then
-        source /etc/sysconfig/clock
+        . /etc/sysconfig/clock
         echo $ZONE > $rootfs/etc/timezone
         chroot $rootfs dpkg-reconfigure -f noninteractive tzdata
     else
@@ -631,7 +664,7 @@ fi
 debug=0
 hostarch=$arch
 flushcache=0
-packages="vim,ssh"
+packages=""
 user="ubuntu"
 password="ubuntu"
 while true
@@ -670,7 +703,7 @@ if [ -n "$bindhome" ]; then
 fi
 
 
-if [ "$arch" == "i686" ]; then
+if [ "$arch" = "i686" ]; then
     arch=i386
 fi