HOOK_DIR="@LXCHOOKDIR@"
CLONE_HOOK_FN="$HOOK_DIR/ubuntu-cloud-prep"
LXC_TEMPLATE_CONFIG="@LXCTEMPLATECONFIG@"
-KNOWN_RELEASES="precise trusty utopic vivid"
+KNOWN_RELEASES="precise trusty xenial yakkety zesty"
skip_arch_check=${UCTEMPLATE_SKIP_ARCH_CHECK:-0}
# Make sure the usual locations are in PATH
# if there is exactly one veth network entry, make sure it has an
# associated hwaddr.
- nics=`grep -e '^lxc\.network\.type[ \t]*=[ \t]*veth' $path/config | wc -l`
+ nics=`grep -e '^lxc\.net\.0\.type[ \t]*=[ \t]*veth' $path/config | wc -l`
if [ $nics -eq 1 ]; then
- grep -q "^lxc.network.hwaddr" $path/config || sed -i -e "/^lxc\.network\.type[ \t]*=[ \t]*veth/a lxc.network.hwaddr = 00:16:3e:$(openssl rand -hex 3| sed 's/\(..\)/\1:/g; s/.$//')" $path/config
+ grep -q "^lxc.net.0.hwaddr" $path/config || sed -i -e "/^lxc\.net\.0\.type[ \t]*=[ \t]*veth/a lxc.net.0.hwaddr = 00:16:3e:$(openssl rand -hex 3| sed 's/\(..\)/\1:/g; s/.$//')" $path/config
fi
# Generate the configuration file
## Relocate all the network config entries
- sed -i -e "/lxc.network/{w ${path}/config-network" -e "d}" $path/config
+ sed -i -e "/lxc.net.0/{w ${path}/config-network" -e "d}" $path/config
## Relocate any other config entries
sed -i -e "/lxc./{w ${path}/config-auto" -e "d}" $path/config
echo "" >> $path/config
echo "# Container specific configuration" >> $path/config
[ -e "$path/config-auto" ] && cat $path/config-auto >> $path/config && rm $path/config-auto
- grep -q "^lxc.rootfs" $path/config 2>/dev/null || echo "lxc.rootfs = $rootfs" >> $path/config
+ grep -q "^lxc.rootfs.path" $path/config 2>/dev/null || echo "lxc.rootfs.path = $rootfs" >> $path/config
cat <<EOF >> $path/config
-lxc.utsname = $name
+lxc.uts.name = $name
lxc.arch = $arch
EOF
mapped_uid=-1
mapped_gid=-1
-# default release is precise, or the systems release if recognized
-release=precise
+# default release is trusty, or the systems release if recognized
+release=trusty
if [ -f /etc/lsb-release ]; then
. /etc/lsb-release
rels=$(ubuntu-distro-info --supported 2>/dev/null) ||
arch="amd64"
elif [ "$arch" = "armv7l" ]; then
# note: arm images don't exist before oneiric; are called armhf in
- # precise and later; and are not supported by the query, so we don't actually
+ # trusty and later; 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="armhf"
while true
do
case "$1" in
- -h|--help) usage $0 && exit 0;;
+ -h|--help) usage $0 && exit 1;;
-p|--path) path=$2; shift 2;;
-n|--name) name=$2; shift 2;;
-F|--flush-cache) flushcache=1; shift 1;;
# detect rootfs
config="$path/config"
if [ -z "$rootfs" ]; then
- if grep -q '^lxc.rootfs' $config 2>/dev/null ; then
- rootfs=$(awk -F= '/^lxc.rootfs =/{ print $2 }' $config)
+ if grep -q '^lxc.rootfs.path' $config 2>/dev/null ; then
+ rootfs=$(awk -F= '/^lxc.rootfs.path =/{ print $2 }' $config)
else
rootfs=$path/rootfs
fi
if ! url1=`ubuntu-cloudimg-query $release $stream $arch --format "%{url}\n"`; then
echo "There is no download available for release=$release, stream=$stream, arch=$arch"
[ "$stream" = "daily" ] || echo "You may try with '--stream=daily'"
- exit
+ exit 1
+ fi
+ if [ "$release" = "precise" ] || [ "$release" = "trusty" ]; then
+ url2=`echo $url1 | sed -e 's/.tar.gz/-root\0/' -e 's/.tar.gz/.tar.xz/'`
+ else
+ url2=`echo $url1 | sed -e 's/.tar.gz/.squashfs/'`
fi
- url2=`echo $url1 | sed -e 's/.tar.gz/-root\0/'`
fi
filename=`basename $url2`
rm -f $filename
}
-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="$release-*-cloudimg-$arch.img"
- trap buildcleanup EXIT SIGHUP SIGINT SIGTERM
- 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 --wildcards -zxf "$tarname" "$imgname"
- mount -o loop $imgname $xdir
- (cd $xdir; tar --numeric-owner -cpzf "../$filename" .)
- umount $xdir
- rm -f $tarname $imgname
- rmdir $xdir
- echo "New cloud image cache created"
- trap EXIT
- trap SIGHUP
- trap SIGINT
- trap SIGTERM
-}
-
do_extract_rootfs() {
cd $cache
trap wgetcleanup EXIT SIGHUP SIGINT SIGTERM
if [ ! -f $filename ]; then
- wget $url2 || build_root_tgz $url1 $filename
+ wget $url2
fi
trap EXIT
trap SIGHUP
echo "Extracting container rootfs"
mkdir -p $rootfs
cd $rootfs
- if [ $in_userns -eq 1 ]; then
- tar --anchored --exclude="dev/*" --numeric-owner -xpzf "$cache/$filename"
- mkdir -p $rootfs/dev/pts/
+ if [ "${filename##*.}" = "squashfs" ]; then
+ unsquashfs -n -f -d "$rootfs" "$cache/$filename"
else
- tar --numeric-owner -xpzf "$cache/$filename"
+ if [ $in_userns -eq 1 ]; then
+ tar --anchored --exclude="dev/*" --numeric-owner -xpf "$cache/$filename"
+ mkdir -p $rootfs/dev/pts/
+ else
+ tar --numeric-owner -xpf "$cache/$filename"
+ fi
fi
}