From: Serge Hallyn Date: Tue, 31 Jul 2012 14:04:33 +0000 (+0200) Subject: Description: fix handling of non-precise cloud image format X-Git-Tag: lxc-0.8.0~38 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3eecde703e9ac3af788ac17357f378d6b6d7c658;p=thirdparty%2Flxc.git Description: fix handling of non-precise cloud image format Also includes a fix for broken check for $debug Signed-off-by: Serge Hallyn Signed-off-by: Daniel Lezcano --- diff --git a/templates/lxc-ubuntu-cloud.in b/templates/lxc-ubuntu-cloud.in index 267dbabf2..2133fb1ef 100644 --- a/templates/lxc-ubuntu-cloud.in +++ b/templates/lxc-ubuntu-cloud.in @@ -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 @@ -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 1 ]; 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