lxc-ubuntu-cloud.in revision 4b954f12173c382f7104a0e9464fa66dd3cade35
# template script for generating ubuntu container for LXC based on released
# cloud images.
#
# Copyright © 2012 Serge Hallyn <serge.hallyn@canonical.com>
#
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
set -e
STATE_DIR="@LOCALSTATEDIR@"
HOOK_DIR="@LXCHOOKDIR@"
CLONE_HOOK_FN="$HOOK_DIR/ubuntu-cloud-prep"
LXC_TEMPLATE_CONFIG="@LXCTEMPLATECONFIG@"
fi
echo yes
}
{
path=$1
rootfs=$2
name=$3
arch=$4
release=$5
arch="i686"
fi
# if there is exactly one veth network entry, make sure it has an
# associated hwaddr.
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
fi
# Generate the configuration file
## Create the fstab (empty by default)
## Relocate all the network config entries
## Relocate any other config entries
## Add all the includes
fi
if [ -e "${LXC_TEMPLATE_CONFIG}/ubuntu-cloud.${release}.conf" ]; then
fi
fi
## Add the container-specific config
cat <<EOF >> $path/config
lxc.mount = $path/fstab
lxc.utsname = $name
lxc.arch = $arch
EOF
## Re-add the previously removed network config
# Set initial timezone as on host
else
echo "Timezone in container is not configured. Adjust it manually."
fi
# it, and in case that fails move it out of the way.
# NOTE: This can only be removed once 12.04 goes out of support
fi
return 0
}
usage()
{
cat <<EOF
LXC Container configuration for Ubuntu Cloud images.
Generic Options
[ -r | --release <release> ]: Release name of container, defaults to host
[ --rootfs <path> ]: Path in which rootfs will be placed
[ -a | --arch ]: Architecture of container, defaults to host architecture
[ -T | --tarball ]: Location of tarball
[ -d | --debug ]: Run with 'set -x' to debug errors
[ -s | --stream]: Use specified stream rather than 'released'
Additionally, clone hooks can be passed through (ie, --userdata). For those,
see:
$CLONE_HOOK_FN --help
EOF
return 0
}
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:,mapped-uid: -- "$@")
if [ $? -ne 0 ]; then
exit 1
fi
eval set -- "$options"
mapped_uid=-1
# default release is precise, or the systems release if recognized
if [ -f /etc/lsb-release ]; then
. /etc/lsb-release
rels="lucid natty oneiric precise quantal raring saucy"
done
fi
# Code taken from debootstrap
arch=`/usr/bin/dpkg --print-architecture`
arch=`/usr/bin/udpkg --print-architecture`
else
if [ "$arch" = "i686" ]; then
arch="i386"
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 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"
fi
fi
debug=0
cloud=0
locales=1
stream="tryreleased"
cloneargs=()
while true
do
case "$1" in
--) shift 1; break ;;
*) break ;;
esac
done
echo "mapped_uid is .$mapped_uid."
set -x
fi
if [ "$arch" = "i686" ]; then
fi
echo "Only i386, amd64, armel and armhf are supported by the ubuntu cloud template."
exit 1
fi
if [ $hostarch != "i386" -a $hostarch != "amd64" -a $hostarch != "armhf" -a $hostarch != "armel" ]; then
echo "Only i386, amd64, armel and armhf are supported as host."
exit 1
fi
exit 1
fi
exit 1
fi
exit 1
fi
echo "Only 'daily' and 'released' and 'tryreleased' streams are supported"
exit 1
fi
if [ -z "$path" ]; then
echo "'path' parameter is required"
exit 1
fi
echo "This script should be run as 'root'"
exit 1
fi
# detect rootfs
if [ -z "$rootfs" ]; then
else
fi
fi
type wget
# determine the url, tarball, and directory names
# download if needed
fi
if [ "$stream" = "tryreleased" ]; then
fi
if [ -n "$tarball" ]; then
else
fi
{
}
{
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
# a tarball from the mounted image.
{
url=$1
filename=$2
trap buildcleanup EXIT SIGHUP SIGINT SIGTERM
if [ $flushcache -eq 1 -o ! -f $cache/$tarname ]; then
echo "Downloading cloud image from $url"
fi
echo "Creating new cached cloud image rootfs"
echo "New cloud image cache created"
trap EXIT
trap SIGHUP
trap SIGINT
trap SIGTERM
}
cd $cache
if [ $flushcache -eq 1 ]; then
echo "Clearing the cached images"
fi
trap wgetcleanup EXIT SIGHUP SIGINT SIGTERM
if [ ! -f $filename ]; then
fi
trap EXIT
trap SIGHUP
trap SIGINT
trap SIGTERM
echo "Extracting container rootfs"
cd $rootfs
if [ $in_userns -eq 1 ]; then
else
fi
}
if [ -n "$tarball" ]; then
else
mkdir -p "$STATE_DIR/lock/subsys/"
(
flock -x 9
fi
"$CLONE_HOOK_FN" "${cloneargs[@]}" "$rootfs"
fi
echo "Container $name created."
exit 0
# vi: ts=4 expandtab