Commit 3eecde70 by Serge Hallyn Committed by Daniel Lezcano

Description: fix handling of non-precise cloud image format

Also includes a fix for broken check for $debug Signed-off-by: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com> Signed-off-by: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com>
parent 9db1aba4
#!/bin/bash #!/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 # images
# #
# Copyright © 2012 Serge Hallyn <serge.hallyn@canonical.com> # Copyright © 2012 Serge Hallyn <serge.hallyn@canonical.com>
...@@ -147,6 +147,10 @@ else ...@@ -147,6 +147,10 @@ else
elif [ "$arch" = "x86_64" ]; then elif [ "$arch" = "x86_64" ]; then
arch="amd64" arch="amd64"
elif [ "$arch" = "armv7l" ]; then 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" arch="armel"
fi fi
fi fi
...@@ -177,7 +181,7 @@ do ...@@ -177,7 +181,7 @@ do
esac esac
done done
if [ $debug -eq ]; then if [ $debug -eq 1 ]; then
set -x set -x
fi fi
...@@ -219,12 +223,47 @@ mkdir -p $cache ...@@ -219,12 +223,47 @@ mkdir -p $cache
if [ -n "$tarball" ]; then if [ -n "$tarball" ]; then
url2="$tarball" url2="$tarball"
else 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/'` url2=`echo $url1 | sed -e 's/.tar.gz/-root\0/'`
fi fi
filename=`basename $url2` 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/ mkdir -p /var/lock/subsys/
( (
flock -n -x 200 flock -n -x 200
...@@ -236,10 +275,10 @@ mkdir -p /var/lock/subsys/ ...@@ -236,10 +275,10 @@ mkdir -p /var/lock/subsys/
fi fi
if [ ! -f $filename ]; then if [ ! -f $filename ]; then
wget $url2 wget $url2 || build_root_tgz $url1 $filename
fi fi
echo "Extracting rootfs" echo "Extracting container rootfs"
mkdir -p $rootfs mkdir -p $rootfs
cd $rootfs cd $rootfs
tar -zxf $cache/$filename tar -zxf $cache/$filename
...@@ -294,6 +333,7 @@ EOF ...@@ -294,6 +333,7 @@ EOF
fi fi
chroot $rootfs /usr/sbin/usermod -U ubuntu chroot $rootfs /usr/sbin/usermod -U ubuntu
echo "ubuntu:ubuntu" | chroot $rootfs chpasswd
echo "Please login as user ubuntu with password ubuntu." echo "Please login as user ubuntu with password ubuntu."
else else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment