#!/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>
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
esac
done
-if [ $debug -eq ]; then
+if [ $debug -eq 1 ]; then
set -x
fi
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
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
fi
chroot $rootfs /usr/sbin/usermod -U ubuntu
+ echo "ubuntu:ubuntu" | chroot $rootfs chpasswd
echo "Please login as user ubuntu with password ubuntu."
else