lxc-ubuntu.in revision b145c6ef5e7959016f54dadc2a92398f7ec684a4
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher#!/bin/bash
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher#
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher# template script for generating ubuntu container for LXC
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher#
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher# This script consolidates and extends the existing lxc ubuntu scripts
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher#
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher# XXX todo: add -lvm option
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher# Copyright � 2011 Serge Hallyn <serge.hallyn@canonical.com>
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher# Copyright � 2010 Wilhelm Meier
45db68ae27147955a4be4c2c772041824c0dc00fStephen Gallagher# Author: Wilhelm Meier <wilhelm.meier@fh-kl.de>
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher#
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher# This program is free software; you can redistribute it and/or modify
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher# it under the terms of the GNU General Public License version 2, as
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher# published by the Free Software Foundation.
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher# This program is distributed in the hope that it will be useful,
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher# but WITHOUT ANY WARRANTY; without even the implied warranty of
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher# GNU General Public License for more details.
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher# You should have received a copy of the GNU General Public License along
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher# with this program; if not, write to the Free Software Foundation, Inc.,
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher#
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagherif [ -r /etc/default/lxc ]; then
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher . /etc/default/lxc
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherfi
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherconfigure_ubuntu()
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher{
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher rootfs=$1
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher hostname=$2
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher # configure the network using the dhcp
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher cat <<EOF > $rootfs/etc/network/interfaces
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherauto lo
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagheriface lo inet loopback
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagherauto eth0
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagheriface eth0 inet dhcp
52261fe16203dec6e6f69177c6d0a810b47d073fStephen GallagherEOF
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher # so you can 'ssh $hostname.' or 'ssh $hostname.local'
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher if [ -f $rootfs/etc/dhcp/dhclient.conf ]; then
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher sed -i "s/<hostname>/$hostname/" $rootfs/etc/dhcp/dhclient.conf
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher elif [ -f $rootfs/etc/dhcp3/dhclient.conf ]; then
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher sed -i "s/<hostname>/$hostname/" $rootfs/etc/dhcp3/dhclient.conf
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher fi
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher # set the hostname
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher cat <<EOF > $rootfs/etc/hostname
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher$hostname
52261fe16203dec6e6f69177c6d0a810b47d073fStephen GallagherEOF
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher # set minimal hosts
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher cat <<EOF > $rootfs/etc/hosts
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher127.0.0.1 localhost $hostname
2ea6196484055397cc4bc011c5960f790431fa9dStephen GallagherEOF
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher # suppress log level output for udev
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher sed -i "s/=\"err\"/=0/" $rootfs/etc/udev/udev.conf
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher # remove jobs for consoles 5 and 6 since we only create 4 consoles in
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher # this template
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher rm -f $rootfs/etc/init/tty{5,6}.conf
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher echo "Please change root-password !"
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher echo "root:root" | chroot $rootfs chpasswd
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher return 0
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher}
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherdownload_ubuntu()
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher{
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher cache=$1
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher arch=$2
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher release=$3
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher if [ $release = "lucid" ]; then
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher packages=dialog,apt,apt-utils,resolvconf,iproute,inetutils-ping,vim,dhcp3-client,ssh,lsb-release,gnupg
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher elif [ $release = "maverick" ]; then
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher packages=dialog,apt,apt-utils,resolvconf,iproute,inetutils-ping,vim,dhcp3-client,ssh,lsb-release,gnupg,netbase
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher elif [ $release = "natty" ]; then
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher packages=dialog,apt,apt-utils,resolvconf,iproute,inetutils-ping,vim,isc-dhcp-client,isc-dhcp-common,ssh,lsb-release,gnupg,netbase
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher else
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher packages=dialog,apt,apt-utils,resolvconf,iproute,inetutils-ping,vim,isc-dhcp-client,isc-dhcp-common,ssh,lsb-release,gnupg,netbase,ubuntu-keyring
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher fi
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher echo "installing packages: $packages"
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher # check the mini ubuntu was not already downloaded
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher mkdir -p "$cache/partial-$arch"
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher if [ $? -ne 0 ]; then
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher echo "Failed to create '$cache/partial-$arch' directory"
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher return 1
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher fi
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher # download a mini ubuntu into a cache
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher echo "Downloading ubuntu $release minimal ..."
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher debootstrap --verbose --components=main,universe --arch=$arch --include=$packages $release $cache/partial-$arch $MIRROR
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher if [ $? -ne 0 ]; then
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher echo "Failed to download the rootfs, aborting."
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher return 1
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher fi
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher mv "$1/partial-$arch" "$1/rootfs-$arch"
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher echo "Download complete."
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher return 0
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher}
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallaghercopy_ubuntu()
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher{
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher cache=$1
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher arch=$2
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher rootfs=$3
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher # make a local copy of the miniubuntu
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher echo -n "Copying rootfs to $rootfs ..."
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher cp -a $cache/rootfs-$arch $rootfs || return 1
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher return 0
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher}
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherinstall_ubuntu()
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher{
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher rootfs=$1
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher release=$2
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher cache="/var/cache/lxc/$release"
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher mkdir -p /var/lock/subsys/
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher (
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher flock -n -x 200
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher if [ $? -ne 0 ]; then
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher echo "Cache repository is busy."
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher return 1
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher fi
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher echo "Checking cache download in $cache/rootfs-$arch ... "
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher if [ ! -e "$cache/rootfs-$arch" ]; then
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher download_ubuntu $cache $arch $release
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher if [ $? -ne 0 ]; then
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher echo "Failed to download 'ubuntu $release base'"
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher return 1
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher fi
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher fi
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher echo "Copy $cache/rootfs-$arch to $rootfs ... "
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher copy_ubuntu $cache $arch $rootfs
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher if [ $? -ne 0 ]; then
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher echo "Failed to copy rootfs"
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher return 1
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher fi
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher return 0
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher ) 200>/var/lock/subsys/lxc
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher return $?
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher}
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallaghercopy_configuration()
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher{
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher path=$1
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher rootfs=$2
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher name=$3
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher arch=$4
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher if [ $arch = "i386" ]; then
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher arch="i686"
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher fi
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher cat <<EOF >> $path/config
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherlxc.utsname = $name
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherlxc.tty = 4
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherlxc.pts = 1024
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherlxc.rootfs = $rootfs
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagherlxc.mount = $path/fstab
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherlxc.arch = $arch
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherlxc.cap.drop = sys_module mac_override mac_admin
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherlxc.cgroup.devices.deny = a
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher# /dev/null and zero
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagherlxc.cgroup.devices.allow = c 1:3 rwm
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherlxc.cgroup.devices.allow = c 1:5 rwm
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher# consoles
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherlxc.cgroup.devices.allow = c 5:1 rwm
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherlxc.cgroup.devices.allow = c 5:0 rwm
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher#lxc.cgroup.devices.allow = c 4:0 rwm
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher#lxc.cgroup.devices.allow = c 4:1 rwm
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher# /dev/{,u}random
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherlxc.cgroup.devices.allow = c 1:9 rwm
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherlxc.cgroup.devices.allow = c 1:8 rwm
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherlxc.cgroup.devices.allow = c 136:* rwm
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherlxc.cgroup.devices.allow = c 5:2 rwm
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher# rtc
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherlxc.cgroup.devices.allow = c 254:0 rwm
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher#fuse
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherlxc.cgroup.devices.allow = c 10:229 rwm
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher#tun
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagherlxc.cgroup.devices.allow = c 10:200 rwm
2ea6196484055397cc4bc011c5960f790431fa9dStephen GallagherEOF
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher cat <<EOF > $path/fstab
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherproc $rootfs/proc proc nodev,noexec,nosuid 0 0
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallaghersysfs $rootfs/sys sysfs defaults 0 0
52261fe16203dec6e6f69177c6d0a810b47d073fStephen GallagherEOF
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher if [ $? -ne 0 ]; then
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher echo "Failed to add configuration"
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher return 1
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher fi
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher return 0
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher}
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallaghertrim()
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher{
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher rootfs=$1
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher release=$2
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher # provide the lxc service
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher cat <<EOF > $rootfs/etc/init/lxc.conf
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher# fake some events needed for correct startup other services
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherdescription "Container Upstart"
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherstart on startup
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherscript
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher rm -rf /var/run/*.pid
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher rm -rf /var/run/network/*
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher /sbin/initctl emit stopped JOB=udevtrigger --no-wait
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher /sbin/initctl emit started JOB=udev --no-wait
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherend script
52261fe16203dec6e6f69177c6d0a810b47d073fStephen GallagherEOF
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher # fix buggus runlevel with sshd
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher cat <<EOF > $rootfs/etc/init/ssh.conf
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher# ssh - OpenBSD Secure Shell server
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher#
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher# The OpenSSH server provides secure shell access to the system.
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherdescription "OpenSSH server"
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherstart on filesystem
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherstop on runlevel [!2345]
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherexpect fork
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherrespawn
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagherrespawn limit 10 5
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagherumask 022
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher# replaces SSHD_OOM_ADJUST in /etc/default/ssh
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagheroom never
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherpre-start script
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher test -x /usr/sbin/sshd || { stop; exit 0; }
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher test -e /etc/ssh/sshd_not_to_be_run && { stop; exit 0; }
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher test -c /dev/null || { stop; exit 0; }
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher mkdir -p -m0755 /var/run/sshd
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagherend script
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher# if you used to set SSHD_OPTS in /etc/default/ssh, you can change the
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher# 'exec' line here instead
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherexec /usr/sbin/sshd
2ea6196484055397cc4bc011c5960f790431fa9dStephen GallagherEOF
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher cat <<EOF > $rootfs/etc/init/console.conf
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher# console - getty
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher#
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher# This service maintains a console on tty1 from the point the system is
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher# started until it is shut down again.
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherstart on stopped rc RUNLEVEL=[2345]
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherstop on runlevel [!2345]
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherrespawn
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherexec /sbin/getty -8 38400 /dev/console
2ea6196484055397cc4bc011c5960f790431fa9dStephen GallagherEOF
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher cat <<EOF > $rootfs/lib/init/fstab
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher# /lib/init/fstab: cleared out for bare-bones lxc
52261fe16203dec6e6f69177c6d0a810b47d073fStephen GallagherEOF
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher # reconfigure some services
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher if [ -z "$LANG" ]; then
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher chroot $rootfs locale-gen en_US.UTF-8
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher chroot $rootfs update-locale LANG=en_US.UTF-8
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher else
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher chroot $rootfs locale-gen $LANG
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher chroot $rootfs update-locale LANG=$LANG
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher fi
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher # remove pointless services in a container
056302a92862fda16351d7192600746746f38e5dStephen Gallagher chroot $rootfs /usr/sbin/update-rc.d -f ondemand remove
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls u*.conf); do mv $f $f.orig; done'
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls tty[2-9].conf); do mv $f $f.orig; done'
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls plymouth*.conf); do mv $f $f.orig; done'
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls hwclock*.conf); do mv $f $f.orig; done'
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls module*.conf); do mv $f $f.orig; done'
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher # if this isn't lucid, then we need to twiddle the network upstart bits :(
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher if [ $release != "lucid" ]; then
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher sed -i 's/^.*emission handled.*$/echo Emitting lo/' $rootfs/etc/network/if-up.d/upstart
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher fi
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher}
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherpost_process()
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher{
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher rootfs=$1
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher release=$2
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher trim_container=$3
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher if [ $trim_container -eq 1 ]; then
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher trim $rootfs $release
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher else
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher # for lucid and maverick, if not trimming, then add the ubuntu-virt
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher # ppa and install lxcguest
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher if [ $release = "lucid" -o $release = "maverick" ]; then
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher chroot $rootfs apt-get install --force-yes -y python-software-properties
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher chroot $rootfs add-apt-repository ppa:ubuntu-virt/ppa
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher chroot $rootfs apt-get update
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher fi
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher chroot $rootfs apt-get install --force-yes -y lxcguest
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher fi
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher}
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagherdo_bindhome()
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher{
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher rootfs=$1
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher user=$2
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher # bind-mount the user's path into the container's /home
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher h=`getent passwd $user | cut -d: -f 6`
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher mkdir -p $rootfs/$h
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher echo "$h $rootfs/$h none bind 0 0" >> $path/fstab
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher # copy /etc/passwd, /etc/shadow, and /etc/group entries into container
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher pwd=`getent passwd $user`
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher if [ $? -ne 0 ]; then
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher echo 'Warning: failed to copy password entry for $user'
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher else
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher echo $pwd >> $rootfs/etc/passwd
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher fi
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher shad=`getent shadow $user`
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher echo $shad >> $rootfs/etc/shadow
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher}
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherclean()
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher{
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher release=$1
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher cache="/var/cache/lxc/$release"
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher if [ ! -e $cache ]; then
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher exit 0
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher fi
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher # lock, so we won't purge while someone is creating a repository
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher (
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher flock -n -x 200
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher if [ $? != 0 ]; then
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher echo "Cache repository is busy."
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher exit 1
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher fi
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher echo -n "Purging the download cache..."
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher rm --preserve-root --one-file-system -rf $cache && echo "Done." || exit 1
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher exit 0
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher ) 200>/var/lock/subsys/lxc
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher}
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagherusage()
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher{
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher cat <<EOF
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher$1 -h|--help -p|--path=<path> --clean [-a|--arch] [-b|--bindhome <user>] [--trim] [-r|--release]
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherrelease: lucid | maverick | natty | oneiric
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallaghertrim: make a minimal (faster, but not upgrade-safe) container
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagherbindhome: bind <user>'s home into the container
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherarch: amd64 or i386: defaults to host arch
52261fe16203dec6e6f69177c6d0a810b47d073fStephen GallagherEOF
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher return 0
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher}
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagheroptions=$(getopt -o a:b:hp:r:xn:c -l arch:,bindhome:,help,path:,release:,trim,name:,clean -- "$@")
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherif [ $? -ne 0 ]; then
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher usage $(basename $0)
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher exit 1
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherfi
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallaghereval set -- "$options"
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherrelease=lucid
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagherif [ -f /etc/lsb-release ]; then
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher . /etc/lsb-release
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher case "$DISTRIB_CODENAME" in
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher lucid|maverick|natty|oneiric)
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher release=$DISTRIB_CODENAME
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher ;;
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher esac
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagherfi
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherbindhome=
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagherarch=$(arch)
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher# Code taken from debootstrap
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherif [ -x /usr/bin/dpkg ] && /usr/bin/dpkg --print-architecture >/dev/null 2>&1; then
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher arch=`/usr/bin/dpkg --print-architecture`
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagherelif type udpkg >/dev/null 2>&1 && udpkg --print-architecture >/dev/null 2>&1; then
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher arch=`/usr/bin/udpkg --print-architecture`
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherelse
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher arch=$(arch)
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher if [ "$arch" = "i686" ]; then
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher arch="i386"
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher elif [ "$arch" = "x86_64" ]; then
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher arch="amd64"
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher elif [ "$arch" = "armv7l" ]; then
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher arch="armel"
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher fi
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherfi
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallaghertrim_container=0
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherhostarch=$arch
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherwhile true
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherdo
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher case "$1" in
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher -h|--help) usage $0 && exit 0;;
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher -p|--path) path=$2; shift 2;;
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher -n|--name) name=$2; shift 2;;
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher -c|--clean) clean=$2; shift 2;;
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher -r|--release) release=$2; shift 2;;
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher -b|--bindhome) bindhome=$2; shift 2;;
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher -a|--arch) arch=$2; shift 2;;
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher -x|--trim) trim_container=1; shift 1;;
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher --) shift 1; break ;;
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher *) break ;;
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher esac
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagherdone
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherif [ "$arch" == "i686" ]; then
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher arch=i386
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagherfi
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherif [ ! -z "$clean" -a -z "$path" ]; then
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher clean || exit 1
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher exit 0
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagherfi
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherif [ $hostarch = "i386" -a $arch = "amd64" ]; then
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher echo "can't create amd64 container on i386"
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher exit 1
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherfi
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallaghertype debootstrap
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherif [ $? -ne 0 ]; then
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher echo "'debootstrap' command is missing"
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher exit 1
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherfi
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherif [ -z "$path" ]; then
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher echo "'path' parameter is required"
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher exit 1
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherfi
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagherif [ "$(id -u)" != "0" ]; then
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher echo "This script should be run as 'root'"
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher exit 1
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherfi
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagherrootfs=$path/rootfs
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherinstall_ubuntu $rootfs $release
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherif [ $? -ne 0 ]; then
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher echo "failed to install ubuntu $release"
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher exit 1
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherfi
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagherconfigure_ubuntu $rootfs $name
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagherif [ $? -ne 0 ]; then
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher echo "failed to configure ubuntu $release for a container"
52261fe16203dec6e6f69177c6d0a810b47d073fStephen Gallagher exit 1
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagherfi
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallaghercopy_configuration $path $rootfs $name $arch
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagherif [ $? -ne 0 ]; then
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher echo "failed write configuration file"
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher exit 1
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagherfi
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagherpost_process $rootfs $release $trim_container
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagherif [ ! -z $bindhome ]; then
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher do_bindhome $rootfs $bindhome
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagherfi
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagherif [ ! -z $clean ]; then
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher clean $release || exit 1
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher exit 0
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagherfi
e59e09b5010f262228bbdeb92a79b733bf5854b3Stephen Gallagher