]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Description: fix handling of non-precise cloud image format
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Tue, 31 Jul 2012 14:04:33 +0000 (16:04 +0200)
committerDaniel Lezcano <daniel.lezcano@free.fr>
Tue, 31 Jul 2012 14:04:33 +0000 (16:04 +0200)
Also includes a fix for broken check for $debug

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
templates/lxc-ubuntu-cloud.in

index 267dbabf216683724680807fd49dd72786a5189a..2133fb1eff2c5a019ca169bbde0a7e7435e9beb7 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-# template script for generating ubuntu container for LXC based on daily cloud
+# template script for generating ubuntu container for LXC based on released cloud
 # images
 #
 # Copyright © 2012 Serge Hallyn <serge.hallyn@canonical.com>
@@ -147,6 +147,10 @@ else
     elif [ "$arch" = "x86_64" ]; then
         arch="amd64"
     elif [ "$arch" = "armv7l" ]; then
+        # note: arm images don't exist before oneiric;  are called armhf in
+        # precise;  and are not supported by the query, so we don't actually
+        # support them yet (see check later on).  When Query2 is available,
+        # we'll use that to enable arm images.
         arch="armel"
     fi
 fi
@@ -177,7 +181,7 @@ do
     esac
 done
 
-if [ $debug -eq ]; then
+if [ $debug -eq ]; then
     set -x
 fi
 
@@ -219,12 +223,47 @@ mkdir -p $cache
 if [ -n "$tarball" ]; then
        url2="$tarball"
 else
-       url1=`ubuntu-cloudimg-query precise daily $arch --format "%{url}\n"`
+       url1=`ubuntu-cloudimg-query $release released $arch --format "%{url}\n"`
        url2=`echo $url1 | sed -e 's/.tar.gz/-root\0/'`
 fi
 
 filename=`basename $url2`
 
+buildcleanup()
+{
+    cd $rootfs
+    umount -l $cache/$xdir || true
+    rm -rf $cache
+}
+
+# if the release doesn't have a *-rootfs.tar.gz, then create one from the
+# cloudimg.tar.gz by extracting the .img, mounting it loopback, and creating
+# a tarball from the mounted image.
+build_root_tgz()
+{
+    url=$1
+    filename=$2
+
+    xdir=`mktemp -d -p .`
+    tarname=`basename $url`
+    imgname="`basename $tarname .tar.gz`.img"
+    trap buildcleanup EXIT
+    if [ $flushcache -eq 1 -o ! -f $cache/$tarname ]; then
+        rm -f $tarname
+        echo "Downloading cloud image from $url"
+        wget $url || { echo "Couldn't find cloud image $url."; exit 1; }
+    fi
+    echo "Creating new cached cloud image rootfs"
+    tar zxf $tarname $imgname
+    mount -o loop $imgname $xdir
+    (cd $xdir; tar zcf ../$filename .)
+    umount $xdir
+    rm -f $tarname $imgname
+    rmdir $xdir
+    echo "New cloud image cache created"
+    trap EXIT
+}
+
 mkdir -p /var/lock/subsys/
 (
     flock -n -x 200
@@ -236,10 +275,10 @@ mkdir -p /var/lock/subsys/
     fi
 
     if [ ! -f $filename ]; then
-       wget $url2
+       wget $url2 || build_root_tgz $url1 $filename
     fi
 
-    echo "Extracting rootfs"
+    echo "Extracting container rootfs"
     mkdir -p $rootfs
     cd $rootfs
     tar -zxf $cache/$filename
@@ -294,6 +333,7 @@ EOF
        fi
 
        chroot $rootfs /usr/sbin/usermod -U ubuntu
+       echo "ubuntu:ubuntu" | chroot $rootfs chpasswd
        echo "Please login as user ubuntu with password ubuntu."
 
    else