~ubuntu-branches/ubuntu/quantal/lxc/quantal-201206191543

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
Description: Simplify the Ubuntu template a bit
     - Update list of extra packages for debootstrap to only include vim
       and ssh. The others were only relevant when we were still using the
       minbase variant. (LP: #996839)
     - Drop any hardcoded Ubuntu version check and replace by feature
       checks instead.
     - Format lxc-ubuntu to consistently use 4-spaces indent instead of
       mixed spaces/tabs.
     - Update default /etc/network/interfaces to include the header.
     - Update default /etc/hosts to match that of a regular Ubuntu system.
     - Drop support for end-of-life releases (gutsy on sparc).
     - Make sure /etc/resolv.conf is valid before running any apt command.
     - Update template help message for release and arch parameters.
     - Switch default Ubuntu version from lucid to precise.
Author: St├ęphane Graber <stgraber@ubuntu.com>

Origin: vendor
Forwarded: no

--- lxc-0.8.0~rc1.orig/templates/lxc-ubuntu.in
+++ lxc-0.8.0~rc1/templates/lxc-ubuntu.in
@@ -38,6 +38,10 @@ configure_ubuntu()
 
    # configure the network using the dhcp
     cat <<EOF > $rootfs/etc/network/interfaces
+# This file describes the network interfaces available on your system
+# and how to activate them. For more information, see interfaces(5).
+
+# The loopback network interface
 auto lo
 iface lo inet loopback
 
@@ -51,10 +55,18 @@ $hostname
 EOF
     # set minimal hosts
     cat <<EOF > $rootfs/etc/hosts
-127.0.0.1 localhost $hostname
+127.0.0.1   localhost
+127.0.1.1   $hostname
+
+# The following lines are desirable for IPv6 capable hosts
+::1     ip6-localhost ip6-loopback
+fe00::0 ip6-localnet
+ff00::0 ip6-mcastprefix
+ff02::1 ip6-allnodes
+ff02::2 ip6-allrouters
 EOF
 
-    if [ "$release" != "precise" ] && [ "$release" != "quantal" ]; then
+    if [ ! -f $rootfs/etc/init/container-detect.conf ]; then
         # suppress log level output for udev
         sed -i "s/=\"err\"/=0/" $rootfs/etc/udev/udev.conf
 
@@ -78,7 +90,9 @@ finalize_user()
 {
     user=$1
 
-    if [ "$release" = "precise" ] || [ "$release" = "quantal" ]; then
+    sudo_version=$(chroot $rootfs dpkg-query -W -f='${Version}' sudo)
+
+    if chroot $rootfs dpkg --compare-versions $sudo_version gt "1.8.3p1-1"; then
         groups="sudo"
     else
         groups="sudo admin"
@@ -90,13 +104,14 @@ finalize_user()
     done
 
     if [ -n "$auth_key" -a -f "$auth_key" ]; then
-    	u_path="/home/${user}/.ssh"
-	root_u_path="$rootfs/$u_path"
-	mkdir -p $root_u_path
-	cp $auth_key "$root_u_path/authorized_keys"
-    	chroot $rootfs chown -R ${user}: "$u_path"
+        u_path="/home/${user}/.ssh"
+        root_u_path="$rootfs/$u_path"
 
-    	echo "Inserted SSH public key from $auth_key into /home/${user}/.ssh/authorized_keys"
+        mkdir -p $root_u_path
+        cp $auth_key "$root_u_path/authorized_keys"
+        chroot $rootfs chown -R ${user}: "$u_path"
+
+        echo "Inserted SSH public key from $auth_key into /home/${user}/.ssh/authorized_keys"
     fi
     return 0
 }
@@ -112,18 +127,6 @@ write_sourceslist()
             MIRROR=${MIRROR:-http://archive.ubuntu.com/ubuntu}
             SECURITY_MIRROR=${SECURITY_MIRROR:-http://security.ubuntu.com/ubuntu}
             ;;
-      sparc)
-            case $SUITE in
-              gutsy)
-            MIRROR=${MIRROR:-http://archive.ubuntu.com/ubuntu}
-            SECURITY_MIRROR=${SECURITY_MIRRORMIRROR:-http://security.ubuntu.com/ubuntu}
-            ;;
-              *)
-            MIRROR=${MIRROR:-http://ports.ubuntu.com/ubuntu-ports}
-            SECURITY_MIRROR=${SECURITY_MIRROR:-http://ports.ubuntu.com/ubuntu-ports}
-            ;;
-            esac
-            ;;
       *)
             MIRROR=${MIRROR:-http://ports.ubuntu.com/ubuntu-ports}
             SECURITY_MIRROR=${SECURITY_MIRROR:-http://ports.ubuntu.com/ubuntu-ports}
@@ -150,13 +153,7 @@ download_ubuntu()
     arch=$2
     release=$3
 
-    if [ $release = "lucid" ]; then
-        packages=dialog,apt,apt-utils,resolvconf,iproute,inetutils-ping,vim,dhcp3-client,ssh,lsb-release,gnupg
-    elif [ $release = "natty" ]; then
-        packages=dialog,apt,apt-utils,resolvconf,iproute,inetutils-ping,vim,isc-dhcp-client,isc-dhcp-common,ssh,lsb-release,gnupg,netbase
-    else
-        packages=dialog,apt,apt-utils,iproute,inetutils-ping,vim,isc-dhcp-client,isc-dhcp-common,ssh,lsb-release,gnupg,netbase,ubuntu-keyring
-    fi
+    packages=vim,ssh
     echo "installing packages: $packages"
 
     # check the mini ubuntu was not already downloaded
@@ -258,39 +255,40 @@ install_ubuntu()
     flushcache=$3
     cache="/var/cache/lxc/$release"
     mkdir -p /var/lock/subsys/
+
     (
-	flock -n -x 200
-	if [ $? -ne 0 ]; then
-	    echo "Cache repository is busy."
-	    return 1
-	fi
-
-
-    if [ $flushcache -eq 1 ]; then
-        echo "Flushing cache..."
-        rm -rf "$cache/partial-$arch"
-        rm -rf "$cache/rootfs-$arch"
-    fi
-
-	echo "Checking cache download in $cache/rootfs-$arch ... "
-	if [ ! -e "$cache/rootfs-$arch" ]; then
-	    download_ubuntu $cache $arch $release
-	    if [ $? -ne 0 ]; then
-		echo "Failed to download 'ubuntu $release base'"
-		return 1
-	    fi
-	fi
-
-	echo "Copy $cache/rootfs-$arch to $rootfs ... "
-	copy_ubuntu $cache $arch $rootfs
-	if [ $? -ne 0 ]; then
-	    echo "Failed to copy rootfs"
-	    return 1
-	fi
+        flock -n -x 200
+        if [ $? -ne 0 ]; then
+            echo "Cache repository is busy."
+            return 1
+        fi
 
-	return 0
 
-	) 200>/var/lock/subsys/lxc
+        if [ $flushcache -eq 1 ]; then
+            echo "Flushing cache..."
+            rm -rf "$cache/partial-$arch"
+            rm -rf "$cache/rootfs-$arch"
+        fi
+
+        echo "Checking cache download in $cache/rootfs-$arch ... "
+        if [ ! -e "$cache/rootfs-$arch" ]; then
+            download_ubuntu $cache $arch $release
+            if [ $? -ne 0 ]; then
+                echo "Failed to download 'ubuntu $release base'"
+                return 1
+            fi
+        fi
+
+        echo "Copy $cache/rootfs-$arch to $rootfs ... "
+        copy_ubuntu $cache $arch $rootfs
+        if [ $? -ne 0 ]; then
+            echo "Failed to copy rootfs"
+            return 1
+        fi
+
+        return 0
+
+    ) 200>/var/lock/subsys/lxc
 
     return $?
 }
@@ -308,7 +306,7 @@ copy_configuration()
     fi
 
     ttydir=""
-    if [ $release = "precise" ] || [ $release = "quantal" ]; then
+    if [ -f $rootfs/etc/init/container-detect.conf ]; then
         ttydir=" lxc"
     fi
 
@@ -371,8 +369,8 @@ sysfs           sys          sysfs defau
 EOF
 
     if [ $? -ne 0 ]; then
-	echo "Failed to add configuration"
-	return 1
+        echo "Failed to add configuration"
+        return 1
     fi
 
     return 0
@@ -449,11 +447,11 @@ EOF
 
     # reconfigure some services
     if [ -z "$LANG" ]; then
-	chroot $rootfs locale-gen en_US.UTF-8
-	chroot $rootfs update-locale LANG=en_US.UTF-8
+        chroot $rootfs locale-gen en_US.UTF-8
+        chroot $rootfs update-locale LANG=en_US.UTF-8
     else
-	chroot $rootfs locale-gen $LANG
-	chroot $rootfs update-locale LANG=$LANG
+        chroot $rootfs locale-gen $LANG
+        chroot $rootfs update-locale LANG=$LANG
     fi
 
     # remove pointless services in a container
@@ -479,21 +477,25 @@ post_process()
 
     if [ $trim_container -eq 1 ]; then
         trim $rootfs $release
-    elif [ $release = "lucid" -o $release = "natty" \
-               -o $release = "oneiric" ]; then
+    elif [ ! -f $rootfs/etc/init/container-detect.conf ]; then
+        # Make sure we have a working resolv.conf
+        cresolvonf="${rootfs}/etc/resolv.conf"
+        mv $cresolvonf ${cresolvonf}.lxcbak
+        cat /etc/resolv.conf > ${cresolvonf}
+
         # for lucid, if not trimming, then add the ubuntu-virt
         # ppa and install lxcguest
         if [ $release = "lucid" ]; then
             chroot $rootfs apt-get install --force-yes -y python-software-properties
             chroot $rootfs add-apt-repository ppa:ubuntu-virt/ppa
         fi
-	cresolvonf="${rootfs}/etc/resolv.conf"
-	mv $cresolvonf ${cresolvonf}.lxcbak
-        cat /etc/resolv.conf > ${cresolvonf}
+
         chroot $rootfs apt-get update
         chroot $rootfs apt-get install --force-yes -y lxcguest
-	rm -f ${cresolvonf}
-	mv ${cresolvonf}.lxcbak ${cresolvonf}
+
+        # Restore old resolv.conf
+        rm -f ${cresolvonf}
+        mv ${cresolvonf}.lxcbak ${cresolvonf}
     fi
 
     # If the container isn't running a native architecture, setup multiarch
@@ -518,11 +520,11 @@ post_process()
         chroot $rootfs apt-get install --force-yes -y --no-install-recommends upstart:${hostarch} mountall:${hostarch} iproute:${hostarch} isc-dhcp-client:${hostarch}
     fi
 
-    # rmdir /dev/shm in precise and quantal containers.
+    # rmdir /dev/shm for containers that have /run/shm
     # I'm afraid of doing rm -rf $rootfs/dev/shm, in case it did
     # get bind mounted to the host's /run/shm.  So try to rmdir
     # it, and in case that fails move it out of the way.
-    if [ $release = "precise" ] || [ $release = "quantal" ]; then
+    if [ -d $rootfs/run/shm ]; then
         [ -d "$rootfs/dev/shm" ] && rmdir $rootfs/dev/shm
         [ -e "$rootfs/dev/shm" ] && mv $rootfs/dev/shm $rootfs/dev/shm.bak
         ln -s /run/shm $rootfs/dev/shm
@@ -553,11 +555,12 @@ do_bindhome()
     # bind-mount the user's path into the container's /home
     h=`getent passwd $user | cut -d: -f 6`
     mkdir -p $rootfs/$h
-	# use relative path in container
-	h2=${h#/}
-	while [ ${h2:0:1} = "/" ]; do
-		h2=${h2#/}
-	done
+
+    # use relative path in container
+    h2=${h#/}
+    while [ ${h2:0:1} = "/" ]; do
+        h2=${h2#/}
+    done
     echo "$h $h2 none bind 0 0" >> $path/fstab
 
     # Make sure the group exists in container
@@ -571,12 +574,12 @@ usage()
     cat <<EOF
 $1 -h|--help [-a|--arch] [-b|--bindhome <user>] [--trim] [-d|--debug]
    [-F | --flush-cache] [-r|--release <release>] [ -S | --auth-key <keyfile>]
-release: lucid | natty | oneiric | precise | quantal
+release: the ubuntu release (e.g. precise): defaults to host release on ubuntu, otherwise uses latest LTS
 trim: make a minimal (faster, but not upgrade-safe) container
 bindhome: bind <user>'s home into the container
           The ubuntu user will not be created, and <user> will have
-	  sudo access.
-arch: amd64 or i386: defaults to host arch
+          sudo access.
+arch: the container architecture (e.g. amd64): defaults to host arch
 auth-key: SSH Public key file to inject into container
 EOF
     return 0
@@ -589,14 +592,12 @@ if [ $? -ne 0 ]; then
 fi
 eval set -- "$options"
 
-release=lucid
+release=precise # Default to the last Ubuntu LTS release for non-Ubuntu systems
 if [ -f /etc/lsb-release ]; then
     . /etc/lsb-release
-    case "$DISTRIB_CODENAME" in
-        lucid|natty|oneiric|precise|quantal)
-            release=$DISTRIB_CODENAME
-        ;;
-    esac
+    if [ "$DISTRIB_ID" = "Ubuntu" ]; then
+        release=$DISTRIB_CODENAME
+    fi
 fi
 
 bindhome=
@@ -641,7 +642,7 @@ do
 done
 
 if [ $debug -eq 1 ]; then
-	set -x
+    set -x
 fi
 
 if [ -n "$bindhome" ]; then