vagrant-lxc 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/BOXES.md +55 -0
- data/CHANGELOG.md +14 -0
- data/CONTRIBUTING.md +20 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +4 -3
- data/README.md +16 -19
- data/boxes/build-debian-box.sh +167 -0
- data/boxes/build-ubuntu-box.sh +151 -0
- data/boxes/common/install-babushka +4 -3
- data/boxes/common/install-chef +3 -2
- data/boxes/common/install-puppet +3 -2
- data/boxes/common/install-salt +3 -2
- data/boxes/common/lxc-template +10 -13
- data/boxes/common/metadata.json +2 -1
- data/development/Vagrantfile +4 -4
- data/development/site.pp +31 -6
- data/lib/vagrant-lxc/action.rb +44 -40
- data/lib/vagrant-lxc/action/clear_forwarded_ports.rb +4 -0
- data/lib/vagrant-lxc/action/fetch_ip_from_dnsmasq_leases.rb +1 -1
- data/lib/vagrant-lxc/action/fetch_ip_with_lxc_attach.rb +4 -7
- data/lib/vagrant-lxc/action/message.rb +1 -0
- data/lib/vagrant-lxc/action/setup_package_files.rb +1 -0
- data/lib/vagrant-lxc/action/wait_for_communicator.rb +9 -14
- data/lib/vagrant-lxc/driver.rb +10 -7
- data/lib/vagrant-lxc/driver/cli.rb +7 -1
- data/lib/vagrant-lxc/errors.rb +5 -0
- data/lib/vagrant-lxc/version.rb +1 -1
- data/locales/en.yml +8 -2
- data/spec/Vagrantfile +7 -2
- data/spec/unit/driver/cli_spec.rb +8 -0
- metadata +8 -18
- data/boxes/debian/download +0 -156
- data/boxes/debian/finalize +0 -195
- data/boxes/debian/lxc-template +0 -367
- data/boxes/debian/metadata.json.template +0 -9
- data/boxes/ubuntu/download +0 -113
- data/boxes/ubuntu/finalize +0 -374
- data/boxes/ubuntu/lxc-template +0 -559
- data/boxes/ubuntu/metadata.json.template +0 -9
- data/development/shell-provisioning/upgrade-kernel +0 -14
- data/example/Vagrantfile +0 -46
- data/example/cookbooks/hello-world/recipes/default.rb +0 -4
- data/example/puppet/manifests/site.pp +0 -5
- data/example/puppet/modules/hello_world/manifests/init.pp +0 -3
- data/tasks/boxes.rake +0 -115
- data/tasks/boxes.v2.rake +0 -188
data/boxes/ubuntu/lxc-template
DELETED
@@ -1,559 +0,0 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
|
3
|
-
# This is a modified version of /usr/share/lxc/templates/lxc-ubuntu
|
4
|
-
# that comes with Ubuntu 13.04 changed to suit vagrant-lxc needs
|
5
|
-
|
6
|
-
#
|
7
|
-
# template script for generating ubuntu container for LXC
|
8
|
-
#
|
9
|
-
# This script consolidates and extends the existing lxc ubuntu scripts
|
10
|
-
#
|
11
|
-
|
12
|
-
# Copyright © 2011 Serge Hallyn <serge.hallyn@canonical.com>
|
13
|
-
# Copyright © 2010 Wilhelm Meier
|
14
|
-
# Author: Wilhelm Meier <wilhelm.meier@fh-kl.de>
|
15
|
-
#
|
16
|
-
# This program is free software; you can redistribute it and/or modify
|
17
|
-
# it under the terms of the GNU General Public License version 2, as
|
18
|
-
# published by the Free Software Foundation.
|
19
|
-
|
20
|
-
# This program is distributed in the hope that it will be useful,
|
21
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
22
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
23
|
-
# GNU General Public License for more details.
|
24
|
-
|
25
|
-
# You should have received a copy of the GNU General Public License along
|
26
|
-
# with this program; if not, write to the Free Software Foundation, Inc.,
|
27
|
-
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
28
|
-
#
|
29
|
-
|
30
|
-
set -e
|
31
|
-
|
32
|
-
if [ -r /etc/default/lxc ]; then
|
33
|
-
. /etc/default/lxc
|
34
|
-
fi
|
35
|
-
|
36
|
-
configure_ubuntu()
|
37
|
-
{
|
38
|
-
rootfs=$1
|
39
|
-
release=$2
|
40
|
-
hostname=$2
|
41
|
-
|
42
|
-
# configure the network using the dhcp
|
43
|
-
cat <<EOF > $rootfs/etc/network/interfaces
|
44
|
-
# This file describes the network interfaces available on your system
|
45
|
-
# and how to activate them. For more information, see interfaces(5).
|
46
|
-
|
47
|
-
# The loopback network interface
|
48
|
-
auto lo
|
49
|
-
iface lo inet loopback
|
50
|
-
|
51
|
-
auto eth0
|
52
|
-
iface eth0 inet dhcp
|
53
|
-
EOF
|
54
|
-
|
55
|
-
# set the hostname
|
56
|
-
cat <<EOF > $rootfs/etc/hostname
|
57
|
-
$hostname
|
58
|
-
EOF
|
59
|
-
# set minimal hosts
|
60
|
-
cat <<EOF > $rootfs/etc/hosts
|
61
|
-
127.0.0.1 localhost
|
62
|
-
127.0.1.1 $hostname
|
63
|
-
|
64
|
-
# The following lines are desirable for IPv6 capable hosts
|
65
|
-
::1 ip6-localhost ip6-loopback
|
66
|
-
fe00::0 ip6-localnet
|
67
|
-
ff00::0 ip6-mcastprefix
|
68
|
-
ff02::1 ip6-allnodes
|
69
|
-
ff02::2 ip6-allrouters
|
70
|
-
ff02::3 ip6-allhosts
|
71
|
-
EOF
|
72
|
-
|
73
|
-
if [ ! -f $rootfs/etc/init/container-detect.conf ]; then
|
74
|
-
# suppress log level output for udev
|
75
|
-
sed -i "s/=\"err\"/=0/" $rootfs/etc/udev/udev.conf
|
76
|
-
|
77
|
-
# remove jobs for consoles 5 and 6 since we only create 4 consoles in
|
78
|
-
# this template
|
79
|
-
rm -f $rootfs/etc/init/tty{5,6}.conf
|
80
|
-
fi
|
81
|
-
|
82
|
-
if ! (grep -q vagrant $rootfs/etc/passwd); then
|
83
|
-
chroot $rootfs useradd --create-home -s /bin/bash vagrant
|
84
|
-
echo "vagrant:vagrant" | chroot $rootfs chpasswd
|
85
|
-
fi
|
86
|
-
|
87
|
-
# make sure we have the current locale defined in the container
|
88
|
-
chroot $rootfs locale-gen en_US.UTF-8
|
89
|
-
chroot $rootfs update-locale LANG=en_US.UTF-8
|
90
|
-
|
91
|
-
return 0
|
92
|
-
}
|
93
|
-
|
94
|
-
# finish setting up the user in the container by injecting ssh key and
|
95
|
-
# adding sudo group membership.
|
96
|
-
# passed-in user is 'vagrant'
|
97
|
-
finalize_user()
|
98
|
-
{
|
99
|
-
user=$1
|
100
|
-
|
101
|
-
sudo_version=$(chroot $rootfs dpkg-query -W -f='${Version}' sudo)
|
102
|
-
|
103
|
-
if chroot $rootfs dpkg --compare-versions $sudo_version gt "1.8.3p1-1"; then
|
104
|
-
groups="sudo"
|
105
|
-
else
|
106
|
-
groups="sudo admin"
|
107
|
-
fi
|
108
|
-
|
109
|
-
for group in $groups; do
|
110
|
-
chroot $rootfs groupadd --system $group >/dev/null 2>&1 || true
|
111
|
-
chroot $rootfs adduser ${user} $group >/dev/null 2>&1 || true
|
112
|
-
done
|
113
|
-
|
114
|
-
chroot $rootfs cp /etc/sudoers /etc/sudoers.orig >/dev/null 2>&1 || true
|
115
|
-
chroot $rootfs sed -i -e 's/%sudo\s\+ALL=(ALL:ALL)\s\+ALL/%sudo ALL=NOPASSWD:ALL/g' /etc/sudoers >/dev/null 2>&1 || true
|
116
|
-
|
117
|
-
if [ -n "$auth_key" -a -f "$auth_key" ]; then
|
118
|
-
u_path="/home/${user}/.ssh"
|
119
|
-
root_u_path="$rootfs/$u_path"
|
120
|
-
|
121
|
-
mkdir -p $root_u_path
|
122
|
-
cp $auth_key "$root_u_path/authorized_keys"
|
123
|
-
chroot $rootfs chown -R ${user}: "$u_path"
|
124
|
-
|
125
|
-
echo "Inserted SSH public key from $auth_key into /home/${user}/.ssh/authorized_keys"
|
126
|
-
fi
|
127
|
-
return 0
|
128
|
-
}
|
129
|
-
|
130
|
-
write_sourceslist()
|
131
|
-
{
|
132
|
-
# $1 => path to the rootfs
|
133
|
-
# $2 => architecture we want to add
|
134
|
-
# $3 => whether to use the multi-arch syntax or not
|
135
|
-
|
136
|
-
case $2 in
|
137
|
-
amd64|i386)
|
138
|
-
MIRROR=${MIRROR:-http://archive.ubuntu.com/ubuntu}
|
139
|
-
SECURITY_MIRROR=${SECURITY_MIRROR:-http://security.ubuntu.com/ubuntu}
|
140
|
-
;;
|
141
|
-
*)
|
142
|
-
MIRROR=${MIRROR:-http://ports.ubuntu.com/ubuntu-ports}
|
143
|
-
SECURITY_MIRROR=${SECURITY_MIRROR:-http://ports.ubuntu.com/ubuntu-ports}
|
144
|
-
;;
|
145
|
-
esac
|
146
|
-
if [ -n "$3" ]; then
|
147
|
-
cat >> "$1/etc/apt/sources.list" << EOF
|
148
|
-
deb [arch=$2] $MIRROR ${release} main restricted universe multiverse
|
149
|
-
deb [arch=$2] $MIRROR ${release}-updates main restricted universe multiverse
|
150
|
-
deb [arch=$2] $SECURITY_MIRROR ${release}-security main restricted universe multiverse
|
151
|
-
EOF
|
152
|
-
else
|
153
|
-
cat >> "$1/etc/apt/sources.list" << EOF
|
154
|
-
deb $MIRROR ${release} main restricted universe multiverse
|
155
|
-
deb $MIRROR ${release}-updates main restricted universe multiverse
|
156
|
-
deb $SECURITY_MIRROR ${release}-security main restricted universe multiverse
|
157
|
-
EOF
|
158
|
-
fi
|
159
|
-
}
|
160
|
-
|
161
|
-
extract_rootfs()
|
162
|
-
{
|
163
|
-
tarball=$1
|
164
|
-
arch=$2
|
165
|
-
rootfs=$3
|
166
|
-
|
167
|
-
echo "Extracting $tarball ..."
|
168
|
-
mkdir -p $(dirname $rootfs)
|
169
|
-
(cd `dirname $rootfs` && tar xfz $tarball)
|
170
|
-
return 0
|
171
|
-
}
|
172
|
-
|
173
|
-
install_ubuntu()
|
174
|
-
{
|
175
|
-
rootfs=$1
|
176
|
-
release=$2
|
177
|
-
tarball=$3
|
178
|
-
mkdir -p /var/lock/subsys/
|
179
|
-
|
180
|
-
(
|
181
|
-
flock -x 200
|
182
|
-
if [ $? -ne 0 ]; then
|
183
|
-
echo "Cache repository is busy."
|
184
|
-
return 1
|
185
|
-
fi
|
186
|
-
|
187
|
-
extract_rootfs $tarball $arch $rootfs
|
188
|
-
if [ $? -ne 0 ]; then
|
189
|
-
echo "Failed to copy rootfs"
|
190
|
-
return 1
|
191
|
-
fi
|
192
|
-
|
193
|
-
return 0
|
194
|
-
|
195
|
-
) 200>/var/lock/subsys/lxc
|
196
|
-
|
197
|
-
return $?
|
198
|
-
}
|
199
|
-
|
200
|
-
copy_configuration()
|
201
|
-
{
|
202
|
-
path=$1
|
203
|
-
rootfs=$2
|
204
|
-
name=$3
|
205
|
-
arch=$4
|
206
|
-
|
207
|
-
if [ $arch = "i386" ]; then
|
208
|
-
arch="i686"
|
209
|
-
fi
|
210
|
-
|
211
|
-
ttydir=""
|
212
|
-
if [ -f $rootfs/etc/init/container-detect.conf ]; then
|
213
|
-
ttydir=" lxc"
|
214
|
-
fi
|
215
|
-
|
216
|
-
# if there is exactly one veth network entry, make sure it has an
|
217
|
-
# associated hwaddr.
|
218
|
-
nics=`grep -e '^lxc\.network\.type[ \t]*=[ \t]*veth' $path/config | wc -l`
|
219
|
-
if [ $nics -eq 1 ]; then
|
220
|
-
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
|
221
|
-
fi
|
222
|
-
|
223
|
-
grep -q "^lxc.rootfs" $path/config 2>/dev/null || echo "lxc.rootfs = $rootfs" >> $path/config
|
224
|
-
cat <<EOF >> $path/config
|
225
|
-
lxc.mount = $path/fstab
|
226
|
-
lxc.pivotdir = lxc_putold
|
227
|
-
|
228
|
-
lxc.devttydir =$ttydir
|
229
|
-
lxc.tty = 4
|
230
|
-
lxc.pts = 1024
|
231
|
-
|
232
|
-
lxc.utsname = $name
|
233
|
-
lxc.arch = $arch
|
234
|
-
lxc.cap.drop = sys_module mac_admin mac_override
|
235
|
-
|
236
|
-
# When using LXC with apparmor, uncomment the next line to run unconfined:
|
237
|
-
#lxc.aa_profile = unconfined
|
238
|
-
|
239
|
-
lxc.cgroup.devices.deny = a
|
240
|
-
# Allow any mknod (but not using the node)
|
241
|
-
lxc.cgroup.devices.allow = c *:* m
|
242
|
-
lxc.cgroup.devices.allow = b *:* m
|
243
|
-
# /dev/null and zero
|
244
|
-
lxc.cgroup.devices.allow = c 1:3 rwm
|
245
|
-
lxc.cgroup.devices.allow = c 1:5 rwm
|
246
|
-
# consoles
|
247
|
-
lxc.cgroup.devices.allow = c 5:1 rwm
|
248
|
-
lxc.cgroup.devices.allow = c 5:0 rwm
|
249
|
-
#lxc.cgroup.devices.allow = c 4:0 rwm
|
250
|
-
#lxc.cgroup.devices.allow = c 4:1 rwm
|
251
|
-
# /dev/{,u}random
|
252
|
-
lxc.cgroup.devices.allow = c 1:9 rwm
|
253
|
-
lxc.cgroup.devices.allow = c 1:8 rwm
|
254
|
-
lxc.cgroup.devices.allow = c 136:* rwm
|
255
|
-
lxc.cgroup.devices.allow = c 5:2 rwm
|
256
|
-
# rtc
|
257
|
-
lxc.cgroup.devices.allow = c 254:0 rwm
|
258
|
-
#fuse
|
259
|
-
lxc.cgroup.devices.allow = c 10:229 rwm
|
260
|
-
#tun
|
261
|
-
lxc.cgroup.devices.allow = c 10:200 rwm
|
262
|
-
#full
|
263
|
-
lxc.cgroup.devices.allow = c 1:7 rwm
|
264
|
-
#hpet
|
265
|
-
lxc.cgroup.devices.allow = c 10:228 rwm
|
266
|
-
#kvm
|
267
|
-
lxc.cgroup.devices.allow = c 10:232 rwm
|
268
|
-
EOF
|
269
|
-
|
270
|
-
cat <<EOF > $path/fstab
|
271
|
-
proc proc proc nodev,noexec,nosuid 0 0
|
272
|
-
sysfs sys sysfs defaults 0 0
|
273
|
-
EOF
|
274
|
-
|
275
|
-
if [ $? -ne 0 ]; then
|
276
|
-
echo "Failed to add configuration"
|
277
|
-
return 1
|
278
|
-
fi
|
279
|
-
|
280
|
-
return 0
|
281
|
-
}
|
282
|
-
|
283
|
-
trim()
|
284
|
-
{
|
285
|
-
rootfs=$1
|
286
|
-
release=$2
|
287
|
-
|
288
|
-
# provide the lxc service
|
289
|
-
cat <<EOF > $rootfs/etc/init/lxc.conf
|
290
|
-
# fake some events needed for correct startup other services
|
291
|
-
|
292
|
-
description "Container Upstart"
|
293
|
-
|
294
|
-
start on startup
|
295
|
-
|
296
|
-
script
|
297
|
-
rm -rf /var/run/*.pid
|
298
|
-
rm -rf /var/run/network/*
|
299
|
-
/sbin/initctl emit stopped JOB=udevtrigger --no-wait
|
300
|
-
/sbin/initctl emit started JOB=udev --no-wait
|
301
|
-
end script
|
302
|
-
EOF
|
303
|
-
|
304
|
-
# fix buggus runlevel with sshd
|
305
|
-
cat <<EOF > $rootfs/etc/init/ssh.conf
|
306
|
-
# ssh - OpenBSD Secure Shell server
|
307
|
-
#
|
308
|
-
# The OpenSSH server provides secure shell access to the system.
|
309
|
-
|
310
|
-
description "OpenSSH server"
|
311
|
-
|
312
|
-
start on filesystem
|
313
|
-
stop on runlevel [!2345]
|
314
|
-
|
315
|
-
expect fork
|
316
|
-
respawn
|
317
|
-
respawn limit 10 5
|
318
|
-
umask 022
|
319
|
-
# replaces SSHD_OOM_ADJUST in /etc/default/ssh
|
320
|
-
oom never
|
321
|
-
|
322
|
-
pre-start script
|
323
|
-
test -x /usr/sbin/sshd || { stop; exit 0; }
|
324
|
-
test -e /etc/ssh/sshd_not_to_be_run && { stop; exit 0; }
|
325
|
-
test -c /dev/null || { stop; exit 0; }
|
326
|
-
|
327
|
-
mkdir -p -m0755 /var/run/sshd
|
328
|
-
end script
|
329
|
-
|
330
|
-
# if you used to set SSHD_OPTS in /etc/default/ssh, you can change the
|
331
|
-
# 'exec' line here instead
|
332
|
-
exec /usr/sbin/sshd
|
333
|
-
EOF
|
334
|
-
|
335
|
-
cat <<EOF > $rootfs/etc/init/console.conf
|
336
|
-
# console - getty
|
337
|
-
#
|
338
|
-
# This service maintains a console on tty1 from the point the system is
|
339
|
-
# started until it is shut down again.
|
340
|
-
|
341
|
-
start on stopped rc RUNLEVEL=[2345]
|
342
|
-
stop on runlevel [!2345]
|
343
|
-
|
344
|
-
respawn
|
345
|
-
exec /sbin/getty -8 38400 /dev/console
|
346
|
-
EOF
|
347
|
-
|
348
|
-
cat <<EOF > $rootfs/lib/init/fstab
|
349
|
-
# /lib/init/fstab: cleared out for bare-bones lxc
|
350
|
-
EOF
|
351
|
-
|
352
|
-
# remove pointless services in a container
|
353
|
-
chroot $rootfs /usr/sbin/update-rc.d -f ondemand remove
|
354
|
-
|
355
|
-
chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls u*.conf); do mv $f $f.orig; done'
|
356
|
-
chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls tty[2-9].conf); do mv $f $f.orig; done'
|
357
|
-
chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls plymouth*.conf); do mv $f $f.orig; done'
|
358
|
-
chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls hwclock*.conf); do mv $f $f.orig; done'
|
359
|
-
chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls module*.conf); do mv $f $f.orig; done'
|
360
|
-
|
361
|
-
# if this isn't lucid, then we need to twiddle the network upstart bits :(
|
362
|
-
if [ $release != "lucid" ]; then
|
363
|
-
sed -i 's/^.*emission handled.*$/echo Emitting lo/' $rootfs/etc/network/if-up.d/upstart
|
364
|
-
fi
|
365
|
-
}
|
366
|
-
|
367
|
-
post_process()
|
368
|
-
{
|
369
|
-
rootfs=$1
|
370
|
-
release=$2
|
371
|
-
trim_container=$3
|
372
|
-
|
373
|
-
if [ $trim_container -eq 1 ]; then
|
374
|
-
trim $rootfs $release
|
375
|
-
elif [ ! -f $rootfs/etc/init/container-detect.conf ]; then
|
376
|
-
# Make sure we have a working resolv.conf
|
377
|
-
cresolvonf="${rootfs}/etc/resolv.conf"
|
378
|
-
mv $cresolvonf ${cresolvonf}.lxcbak
|
379
|
-
cat /etc/resolv.conf > ${cresolvonf}
|
380
|
-
|
381
|
-
# for lucid, if not trimming, then add the ubuntu-virt
|
382
|
-
# ppa and install lxcguest
|
383
|
-
if [ $release = "lucid" ]; then
|
384
|
-
chroot $rootfs apt-get update
|
385
|
-
chroot $rootfs apt-get install --force-yes -y python-software-properties
|
386
|
-
chroot $rootfs add-apt-repository ppa:ubuntu-virt/ppa
|
387
|
-
fi
|
388
|
-
|
389
|
-
chroot $rootfs apt-get update
|
390
|
-
chroot $rootfs apt-get install --force-yes -y lxcguest
|
391
|
-
|
392
|
-
# Restore old resolv.conf
|
393
|
-
rm -f ${cresolvonf}
|
394
|
-
mv ${cresolvonf}.lxcbak ${cresolvonf}
|
395
|
-
fi
|
396
|
-
|
397
|
-
# If the container isn't running a native architecture, setup multiarch
|
398
|
-
if [ -x "$(ls -1 ${rootfs}/usr/bin/qemu-*-static 2>/dev/null)" ]; then
|
399
|
-
dpkg_version=$(chroot $rootfs dpkg-query -W -f='${Version}' dpkg)
|
400
|
-
if chroot $rootfs dpkg --compare-versions $dpkg_version ge "1.16.2"; then
|
401
|
-
chroot $rootfs dpkg --add-architecture ${hostarch}
|
402
|
-
else
|
403
|
-
mkdir -p ${rootfs}/etc/dpkg/dpkg.cfg.d
|
404
|
-
echo "foreign-architecture ${hostarch}" > ${rootfs}/etc/dpkg/dpkg.cfg.d/lxc-multiarch
|
405
|
-
fi
|
406
|
-
|
407
|
-
# Save existing value of MIRROR and SECURITY_MIRROR
|
408
|
-
DEFAULT_MIRROR=$MIRROR
|
409
|
-
DEFAULT_SECURITY_MIRROR=$SECURITY_MIRROR
|
410
|
-
|
411
|
-
# Write a new sources.list containing both native and multiarch entries
|
412
|
-
> ${rootfs}/etc/apt/sources.list
|
413
|
-
write_sourceslist $rootfs $arch "native"
|
414
|
-
|
415
|
-
MIRROR=$DEFAULT_MIRROR
|
416
|
-
SECURITY_MIRROR=$DEFAULT_SECURITY_MIRROR
|
417
|
-
write_sourceslist $rootfs $hostarch "multiarch"
|
418
|
-
|
419
|
-
# Finally update the lists and install upstart using the host architecture
|
420
|
-
chroot $rootfs apt-get update
|
421
|
-
chroot $rootfs apt-get install --force-yes -y --no-install-recommends upstart:${hostarch} mountall:${hostarch} iproute:${hostarch} isc-dhcp-client:${hostarch}
|
422
|
-
fi
|
423
|
-
|
424
|
-
# rmdir /dev/shm for containers that have /run/shm
|
425
|
-
# I'm afraid of doing rm -rf $rootfs/dev/shm, in case it did
|
426
|
-
# get bind mounted to the host's /run/shm. So try to rmdir
|
427
|
-
# it, and in case that fails move it out of the way.
|
428
|
-
if [ ! -L $rootfs/dev/shm ] && [ -d $rootfs/run/shm ] && [ -e $rootfs/dev/shm ]; then
|
429
|
-
mv $rootfs/dev/shm $rootfs/dev/shm.bak
|
430
|
-
ln -s /run/shm $rootfs/dev/shm
|
431
|
-
fi
|
432
|
-
}
|
433
|
-
|
434
|
-
usage()
|
435
|
-
{
|
436
|
-
cat <<EOF
|
437
|
-
$1 -h|--help [-a|--arch] [--trim] [-d|--debug]
|
438
|
-
[-F | --flush-cache] [-r|--release <release>] [ -S | --auth-key <keyfile>]
|
439
|
-
release: the ubuntu release (e.g. precise): defaults to host release on ubuntu, otherwise uses latest LTS
|
440
|
-
trim: make a minimal (faster, but not upgrade-safe) container
|
441
|
-
arch: the container architecture (e.g. amd64): defaults to host arch
|
442
|
-
auth-key: SSH Public key file to inject into container
|
443
|
-
EOF
|
444
|
-
return 0
|
445
|
-
}
|
446
|
-
|
447
|
-
options=$(getopt -o a:b:hp:r:xn:FS:d:C -l arch:,help,path:,release:,trim,name:,flush-cache,auth-key:,debug:,tarball: -- "$@")
|
448
|
-
if [ $? -ne 0 ]; then
|
449
|
-
usage $(basename $0)
|
450
|
-
exit 1
|
451
|
-
fi
|
452
|
-
eval set -- "$options"
|
453
|
-
|
454
|
-
release=precise # Default to the last Ubuntu LTS release for non-Ubuntu systems
|
455
|
-
if [ -f /etc/lsb-release ]; then
|
456
|
-
. /etc/lsb-release
|
457
|
-
if [ "$DISTRIB_ID" = "Ubuntu" ]; then
|
458
|
-
release=$DISTRIB_CODENAME
|
459
|
-
fi
|
460
|
-
fi
|
461
|
-
|
462
|
-
arch=$(uname -m)
|
463
|
-
|
464
|
-
# Code taken from debootstrap
|
465
|
-
if [ -x /usr/bin/dpkg ] && /usr/bin/dpkg --print-architecture >/dev/null 2>&1; then
|
466
|
-
arch=`/usr/bin/dpkg --print-architecture`
|
467
|
-
elif type udpkg >/dev/null 2>&1 && udpkg --print-architecture >/dev/null 2>&1; then
|
468
|
-
arch=`/usr/bin/udpkg --print-architecture`
|
469
|
-
else
|
470
|
-
arch=$(uname -m)
|
471
|
-
if [ "$arch" = "i686" ]; then
|
472
|
-
arch="i386"
|
473
|
-
elif [ "$arch" = "x86_64" ]; then
|
474
|
-
arch="amd64"
|
475
|
-
elif [ "$arch" = "armv7l" ]; then
|
476
|
-
arch="armel"
|
477
|
-
fi
|
478
|
-
fi
|
479
|
-
|
480
|
-
debug=0
|
481
|
-
trim_container=0
|
482
|
-
hostarch=$arch
|
483
|
-
while true
|
484
|
-
do
|
485
|
-
case "$1" in
|
486
|
-
-h|--help) usage $0 && exit 0;;
|
487
|
-
-p|--path) path=$2; shift 2;;
|
488
|
-
-n|--name) name=$2; shift 2;;
|
489
|
-
-T|--tarball) tarball=$2; shift 2;;
|
490
|
-
-r|--release) release=$2; shift 2;;
|
491
|
-
-a|--arch) arch=$2; shift 2;;
|
492
|
-
-x|--trim) trim_container=1; shift 1;;
|
493
|
-
-S|--auth-key) auth_key=$2; shift 2;;
|
494
|
-
-d|--debug) debug=1; shift 1;;
|
495
|
-
--) shift 1; break ;;
|
496
|
-
*) break ;;
|
497
|
-
esac
|
498
|
-
done
|
499
|
-
|
500
|
-
if [ $debug -eq 1 ]; then
|
501
|
-
set -x
|
502
|
-
fi
|
503
|
-
|
504
|
-
|
505
|
-
if [ "$arch" == "i686" ]; then
|
506
|
-
arch=i386
|
507
|
-
fi
|
508
|
-
|
509
|
-
if [ $hostarch = "i386" -a $arch = "amd64" ]; then
|
510
|
-
echo "can't create amd64 container on i386"
|
511
|
-
exit 1
|
512
|
-
fi
|
513
|
-
|
514
|
-
if [ -z "$path" ]; then
|
515
|
-
echo "'path' parameter is required"
|
516
|
-
exit 1
|
517
|
-
fi
|
518
|
-
|
519
|
-
if [ "$(id -u)" != "0" ]; then
|
520
|
-
echo "This script should be run as 'root'"
|
521
|
-
exit 1
|
522
|
-
fi
|
523
|
-
|
524
|
-
# detect rootfs
|
525
|
-
config="$path/config"
|
526
|
-
if grep -q '^lxc.rootfs' $config 2>/dev/null ; then
|
527
|
-
rootfs=`grep 'lxc.rootfs =' $config | awk -F= '{ print $2 }'`
|
528
|
-
else
|
529
|
-
rootfs=$path/rootfs
|
530
|
-
fi
|
531
|
-
|
532
|
-
install_ubuntu $rootfs $release $tarball
|
533
|
-
if [ $? -ne 0 ]; then
|
534
|
-
echo "failed to install ubuntu $release"
|
535
|
-
exit 1
|
536
|
-
fi
|
537
|
-
|
538
|
-
configure_ubuntu $rootfs $release
|
539
|
-
if [ $? -ne 0 ]; then
|
540
|
-
echo "failed to configure ubuntu $release for a container"
|
541
|
-
exit 1
|
542
|
-
fi
|
543
|
-
|
544
|
-
copy_configuration $path $rootfs $name $arch
|
545
|
-
if [ $? -ne 0 ]; then
|
546
|
-
echo "failed write configuration file"
|
547
|
-
exit 1
|
548
|
-
fi
|
549
|
-
|
550
|
-
post_process $rootfs $release $trim_container
|
551
|
-
|
552
|
-
finalize_user vagrant
|
553
|
-
|
554
|
-
echo ""
|
555
|
-
echo "##"
|
556
|
-
echo "# The default user is 'vagrant' with password 'vagrant'!"
|
557
|
-
echo "# Use the 'sudo' command to run tasks as root in the container."
|
558
|
-
echo "##"
|
559
|
-
echo ""
|