4
# lxc: linux Container library
7
# Daniel Lezcano <daniel.lezcano@free.fr>
9
# This library is free software; you can redistribute it and/or
10
# modify it under the terms of the GNU Lesser General Public
11
# License as published by the Free Software Foundation; either
12
# version 2.1 of the License, or (at your option) any later version.
14
# This library is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
# Lesser General Public License for more details.
19
# You should have received a copy of the GNU Lesser General Public
20
# License along with this library; if not, write to the Free Software
21
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
echo "usage: lxc-create -n <name> [-f configuration] [-t template] [-h]"
30
echo "creates a lxc system object."
33
echo "name : name of the container"
34
echo "configuration: lxc configuration"
35
echo "template : lxc-template is an accessible template script"
38
shortoptions='hn:f:t:'
39
longoptions='help,name:,config:,template:'
42
templatedir=@LXCTEMPLATEDIR@
44
getopt=$(getopt -o $shortoptions --longoptions $longoptions -- "$@")
84
if [ -z "$lxc_path" ]; then
85
echo "no configuration path defined !"
89
if [ ! -r $lxc_path ]; then
90
echo "configuration path '$lxc_path' not found"
94
if [ -z "$lxc_name" ]; then
95
echo "no container name specified"
100
if [ "$(id -u)" != "0" ]; then
101
echo "This command has to be run as root"
105
if [ ! -r $lxc_path ]; then
106
echo "no configuration path defined !"
110
if [ -d "$lxc_path/$lxc_name" ]; then
111
echo "'$lxc_name' already exists"
115
trap "${bindir}/lxc-destroy -n $lxc_name; echo aborted; exit 1" SIGHUP SIGINT SIGTERM
117
mkdir -p $lxc_path/$lxc_name
119
if [ -z "$lxc_config" ]; then
120
touch $lxc_path/$lxc_name/config
122
if [ ! -r "$lxc_config" ]; then
123
echo "'$lxc_config' configuration file not found"
127
cp $lxc_config $lxc_path/$lxc_name/config
130
if [ ! -z $lxc_template ]; then
132
type ${templatedir}/lxc-$lxc_template >/dev/null
133
if [ $? -ne 0 ]; then
134
echo "unknown template '$lxc_template'"
135
${bindir}/lxc-destroy -n $lxc_name
139
if [ -z "$lxc_config" ]; then
143
echo "Usually the template option is called with a configuration"
144
echo "file option too, mostly to configure the network."
145
echo "eg. lxc-create -n foo -f lxc.conf -t debian"
146
echo "The configuration file is often:"
148
echo "lxc.network.type=macvlan"
149
echo "lxc.network.link=eth0"
150
echo "lxc.network.flags=up"
152
echo "or alternatively:"
154
echo "lxc.network.type=veth"
155
echo "lxc.network.link=br0"
156
echo "lxc.network.flags=up"
158
echo "For more information look at lxc.conf (5)"
160
echo "At this point, I assume you know what you do."
161
echo "Press <enter> to continue ..."
165
${templatedir}/lxc-$lxc_template --path=$lxc_path/$lxc_name --name=$lxc_name
166
if [ $? -ne 0 ]; then
167
echo "failed to execute template '$lxc_template'"
168
${bindir}/lxc-destroy -n $lxc_name
172
echo "'$lxc_template' template installed"
175
echo "'$lxc_name' created"