lxc-ubuntu-cloud.in revision 9c3bc32c5789b76b8c42b75d7625377d61e052c1
e437b19c184243f688c2dd9b3bf083a454c804c7Julian Kornberger# template script for generating ubuntu container for LXC based on released
e437b19c184243f688c2dd9b3bf083a454c804c7Julian Kornberger# cloud images.
e437b19c184243f688c2dd9b3bf083a454c804c7Julian Kornberger# Copyright © 2012 Serge Hallyn <serge.hallyn@canonical.com>
e437b19c184243f688c2dd9b3bf083a454c804c7Julian Kornberger# This library is free software; you can redistribute it and/or
e437b19c184243f688c2dd9b3bf083a454c804c7Julian Kornberger# modify it under the terms of the GNU Lesser General Public
e437b19c184243f688c2dd9b3bf083a454c804c7Julian Kornberger# License as published by the Free Software Foundation; either
e437b19c184243f688c2dd9b3bf083a454c804c7Julian Kornberger# version 2.1 of the License, or (at your option) any later version.
e437b19c184243f688c2dd9b3bf083a454c804c7Julian Kornberger# This library is distributed in the hope that it will be useful,
e437b19c184243f688c2dd9b3bf083a454c804c7Julian Kornberger# but WITHOUT ANY WARRANTY; without even the implied warranty of
e437b19c184243f688c2dd9b3bf083a454c804c7Julian Kornberger# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e437b19c184243f688c2dd9b3bf083a454c804c7Julian Kornberger# Lesser General Public License for more details.
e437b19c184243f688c2dd9b3bf083a454c804c7Julian Kornberger# You should have received a copy of the GNU Lesser General Public
e437b19c184243f688c2dd9b3bf083a454c804c7Julian Kornberger# License along with this library; if not, write to the Free Software
e437b19c184243f688c2dd9b3bf083a454c804c7Julian Kornberger# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
e437b19c184243f688c2dd9b3bf083a454c804c7Julian KornbergerCLONE_HOOK_FN="$HOOK_DIR/ubuntu-cloud-prep"
echo yes
path=$1
rootfs=$2
name=$3
arch=$4
release=$5
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
if [ $in_userns -eq 1 ]; then
cat <<EOF
options=$(getopt -o a:hp:r:n:Fi:CLS:T:ds:u: -l arch:,help,rootfs:,path:,release:,name:,flush-cache,hostid:,auth-key:,cloud,no_locales,tarball:,debug,stream:,userdata: -- "$@")
eval set -- "$options"
if [ $hostarch != "i386" -a $hostarch != "amd64" -a $hostarch != "armhf" -a $hostarch != "armel" ]; then
if [ -z "$path" ]; then
if [ -z "$rootfs" ]; then
type wget
if [ -n "$tarball" ]; then
cd $rootfs
# 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
url=$1
filename=$2
trap buildcleanup EXIT SIGHUP SIGINT SIGTERM
if [ $flushcache -eq 1 -o ! -f $cache/$tarname ]; then
trap EXIT
trap SIGHUP
trap SIGINT
trap SIGTERM
cd $cache
if [ $flushcache -eq 1 ]; then
trap wgetcleanup EXIT SIGHUP SIGINT SIGTERM
if [ ! -f $filename ]; then
trap EXIT
trap SIGHUP
trap SIGINT
trap SIGTERM
cd $rootfs
if [ -n "$tarball" ]; then
flock -x 200
"$CLONE_HOOK_FN" "${cloneargs[@]}" "$rootfs"
echo "Container $name created."