~kim0/lxc/bug-740167

« back to all changes in this revision

Viewing changes to .pc/0002-disable-debian-checkroot-script.patch/templates/lxc-debian.in

  • Committer: Bazaar Package Importer
  • Author(s): Guido Trotter
  • Date: 2010-12-06 16:24:31 UTC
  • mfrom: (1.1.6 upstream) (3.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20101206162431-lvg92fyuiupfoqek
Tags: 0.7.3-1
* New upstream version (closes: #602631)
  - Support for specifying debian suite (closes: #600459)
  - Support for declaring a different architecture (closes: #597875)
* Fix restart init.d action sequence (closes: #597998)
* Move too-deep /usr/lib/lxc/lxc path to a proper patch
* Disable checkroot script in debian template (closes: #601001)
* Create missing tty devices under squeeze (closes: #600466)
* Restore bindmount functionality in newer kernels (closes: #604475)
* Make debian mirror configurable (closes: #601422)
* Default to cdn.debian.net as a debian mirror (closes: #600464)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
 
 
3
#
 
4
# lxc: linux Container library
 
5
 
 
6
# Authors:
 
7
# Daniel Lezcano <daniel.lezcano@free.fr>
 
8
 
 
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.
 
13
 
 
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.
 
18
 
 
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
 
22
 
 
23
SUITE=${SUITE:-lenny}
 
24
 
 
25
configure_debian()
 
26
{
 
27
    rootfs=$1
 
28
    hostname=$2
 
29
 
 
30
    # configure the inittab
 
31
    cat <<EOF > $rootfs/etc/inittab
 
32
id:3:initdefault:
 
33
si::sysinit:/etc/init.d/rcS
 
34
l0:0:wait:/etc/init.d/rc 0
 
35
l1:1:wait:/etc/init.d/rc 1
 
36
l2:2:wait:/etc/init.d/rc 2
 
37
l3:3:wait:/etc/init.d/rc 3
 
38
l4:4:wait:/etc/init.d/rc 4
 
39
l5:5:wait:/etc/init.d/rc 5
 
40
l6:6:wait:/etc/init.d/rc 6
 
41
# Normally not reached, but fallthrough in case of emergency.
 
42
z6:6:respawn:/sbin/sulogin
 
43
1:2345:respawn:/sbin/getty 38400 console
 
44
c1:12345:respawn:/sbin/getty 38400 tty1 linux
 
45
c2:12345:respawn:/sbin/getty 38400 tty2 linux
 
46
c3:12345:respawn:/sbin/getty 38400 tty3 linux
 
47
c4:12345:respawn:/sbin/getty 38400 tty4 linux
 
48
EOF
 
49
 
 
50
    # disable selinux in debian
 
51
    mkdir -p $rootfs/selinux
 
52
    echo 0 > $rootfs/selinux/enforce
 
53
 
 
54
    # configure the network using the dhcp
 
55
    cat <<EOF > $rootfs/etc/network/interfaces
 
56
auto lo
 
57
iface lo inet loopback
 
58
 
 
59
auto eth0
 
60
iface eth0 inet dhcp
 
61
EOF
 
62
 
 
63
    # set the hostname
 
64
    cat <<EOF > $rootfs/etc/hostname
 
65
$hostname
 
66
EOF
 
67
 
 
68
    # reconfigure some services
 
69
    if [ -z "$LANG" ]; then
 
70
        chroot $rootfs locale-gen en_US.UTF-8
 
71
        chroot $rootfs update-locale LANG=en_US.UTF-8
 
72
    else
 
73
        chroot $rootfs locale-gen $LANG
 
74
        chroot $rootfs update-locale LANG=$LANG
 
75
    fi
 
76
 
 
77
    # remove pointless services in a container
 
78
    chroot $rootfs /usr/sbin/update-rc.d -f umountfs remove
 
79
    chroot $rootfs /usr/sbin/update-rc.d -f hwclock.sh remove
 
80
    chroot $rootfs /usr/sbin/update-rc.d -f hwclockfirst.sh remove
 
81
 
 
82
    echo "root:root" | chroot $rootfs chpasswd
 
83
    echo "Root password is 'root', please change !"
 
84
 
 
85
    return 0
 
86
}
 
87
 
 
88
download_debian()
 
89
{
 
90
    packages=\
 
91
ifupdown,\
 
92
locales,\
 
93
libui-dialog-perl,\
 
94
dialog,\
 
95
dhcp3-client,\
 
96
netbase,\
 
97
net-tools,\
 
98
iproute,\
 
99
openssh-server
 
100
 
 
101
    cache=$1
 
102
    arch=$2
 
103
 
 
104
    # check the mini debian was not already downloaded
 
105
    mkdir -p "$cache/partial-$SUITE-$arch"
 
106
    if [ $? -ne 0 ]; then
 
107
        echo "Failed to create '$cache/partial-$SUITE-$arch' directory"
 
108
        return 1
 
109
    fi
 
110
 
 
111
    # download a mini debian into a cache
 
112
    echo "Downloading debian minimal ..."
 
113
    debootstrap --verbose --variant=minbase --arch=$arch \
 
114
        --include $packages \
 
115
        "$SUITE" "$cache/partial-$SUITE-$arch" http://ftp.debian.org/debian
 
116
    if [ $? -ne 0 ]; then
 
117
        echo "Failed to download the rootfs, aborting."
 
118
        return 1
 
119
    fi
 
120
 
 
121
    mv "$1/partial-$SUITE-$arch" "$1/rootfs-$SUITE-$arch"
 
122
    echo "Download complete."
 
123
 
 
124
    return 0
 
125
}
 
126
 
 
127
copy_debian()
 
128
{
 
129
    cache=$1
 
130
    arch=$2
 
131
    rootfs=$3
 
132
 
 
133
    # make a local copy of the minidebian
 
134
    echo -n "Copying rootfs to $rootfs..."
 
135
    cp -a "$cache/rootfs-$SUITE-$arch" $rootfs || return 1
 
136
    return 0
 
137
}
 
138
 
 
139
install_debian()
 
140
{
 
141
    cache="@LOCALSTATEDIR@/cache/lxc/debian"
 
142
    rootfs=$1
 
143
    mkdir -p @LOCALSTATEDIR@/lock/subsys/
 
144
    (
 
145
        flock -n -x 200
 
146
        if [ $? -ne 0 ]; then
 
147
            echo "Cache repository is busy."
 
148
            return 1
 
149
        fi
 
150
 
 
151
        arch=$(arch)
 
152
        if [ "$arch" == "x86_64" ]; then
 
153
            arch=amd64
 
154
        fi
 
155
 
 
156
        if [ "$arch" == "i686" ]; then
 
157
            arch=i386
 
158
        fi
 
159
 
 
160
        echo "Checking cache download in $cache/rootfs-$SUITE-$arch ... "
 
161
        if [ ! -e "$cache/rootfs-$SUITE-$arch" ]; then
 
162
            download_debian $cache $arch
 
163
            if [ $? -ne 0 ]; then
 
164
                echo "Failed to download 'debian base'"
 
165
                return 1
 
166
            fi
 
167
        fi
 
168
 
 
169
        copy_debian $cache $arch $rootfs
 
170
        if [ $? -ne 0 ]; then
 
171
            echo "Failed to copy rootfs"
 
172
            return 1
 
173
        fi
 
174
 
 
175
        return 0
 
176
 
 
177
        ) 200>@LOCALSTATEDIR@/lock/subsys/lxc
 
178
 
 
179
    return $?
 
180
}
 
181
 
 
182
copy_configuration()
 
183
{
 
184
    path=$1
 
185
    rootfs=$2
 
186
    name=$3
 
187
 
 
188
    cat <<EOF >> $path/config
 
189
lxc.tty = 4
 
190
lxc.pts = 1024
 
191
lxc.rootfs = $rootfs
 
192
lxc.cgroup.devices.deny = a
 
193
# /dev/null and zero
 
194
lxc.cgroup.devices.allow = c 1:3 rwm
 
195
lxc.cgroup.devices.allow = c 1:5 rwm
 
196
# consoles
 
197
lxc.cgroup.devices.allow = c 5:1 rwm
 
198
lxc.cgroup.devices.allow = c 5:0 rwm
 
199
lxc.cgroup.devices.allow = c 4:0 rwm
 
200
lxc.cgroup.devices.allow = c 4:1 rwm
 
201
# /dev/{,u}random
 
202
lxc.cgroup.devices.allow = c 1:9 rwm
 
203
lxc.cgroup.devices.allow = c 1:8 rwm
 
204
lxc.cgroup.devices.allow = c 136:* rwm
 
205
lxc.cgroup.devices.allow = c 5:2 rwm
 
206
# rtc
 
207
lxc.cgroup.devices.allow = c 254:0 rwm
 
208
 
 
209
# mounts point
 
210
lxc.mount.entry=proc $rootfs/proc proc nodev,noexec,nosuid 0 0
 
211
lxc.mount.entry=devpts $rootfs/dev/pts devpts defaults 0 0
 
212
lxc.mount.entry=sysfs $rootfs/sys sysfs defaults  0 0
 
213
EOF
 
214
 
 
215
    if [ $? -ne 0 ]; then
 
216
        echo "Failed to add configuration"
 
217
        return 1
 
218
    fi
 
219
 
 
220
    return 0
 
221
}
 
222
 
 
223
clean()
 
224
{
 
225
    cache="@LOCALSTATEDIR@/cache/lxc/debian"
 
226
 
 
227
    if [ ! -e $cache ]; then
 
228
        exit 0
 
229
    fi
 
230
 
 
231
    # lock, so we won't purge while someone is creating a repository
 
232
    (
 
233
        flock -n -x 200
 
234
        if [ $? != 0 ]; then
 
235
            echo "Cache repository is busy."
 
236
            exit 1
 
237
        fi
 
238
 
 
239
        echo -n "Purging the download cache..."
 
240
        rm --preserve-root --one-file-system -rf $cache && echo "Done." || exit 1
 
241
        exit 0
 
242
 
 
243
    ) 200>@LOCALSTATEDIR@/lock/subsys/lxc
 
244
}
 
245
 
 
246
usage()
 
247
{
 
248
    cat <<EOF
 
249
$1 -h|--help -p|--path=<path> --clean
 
250
EOF
 
251
    return 0
 
252
}
 
253
 
 
254
options=$(getopt -o hp:n:c -l help,path:,name:,clean -- "$@")
 
255
if [ $? -ne 0 ]; then
 
256
        usage $(basename $0)
 
257
        exit 1
 
258
fi
 
259
eval set -- "$options"
 
260
 
 
261
while true
 
262
do
 
263
    case "$1" in
 
264
        -h|--help)      usage $0 && exit 0;;
 
265
        -p|--path)      path=$2; shift 2;;
 
266
        -n|--name)      name=$2; shift 2;;
 
267
        -c|--clean)     clean=$2; shift 2;;
 
268
        --)             shift 1; break ;;
 
269
        *)              break ;;
 
270
    esac
 
271
done
 
272
 
 
273
if [ ! -z "$clean" -a -z "$path" ]; then
 
274
    clean || exit 1
 
275
    exit 0
 
276
fi
 
277
 
 
278
type debootstrap
 
279
if [ $? -ne 0 ]; then
 
280
    echo "'debootstrap' command is missing"
 
281
    exit 1
 
282
fi
 
283
 
 
284
if [ -z "$path" ]; then
 
285
    echo "'path' parameter is required"
 
286
    exit 1
 
287
fi
 
288
 
 
289
if [ "$(id -u)" != "0" ]; then
 
290
    echo "This script should be run as 'root'"
 
291
    exit 1
 
292
fi
 
293
 
 
294
rootfs=$path/rootfs
 
295
 
 
296
install_debian $rootfs
 
297
if [ $? -ne 0 ]; then
 
298
    echo "failed to install debian"
 
299
    exit 1
 
300
fi
 
301
 
 
302
configure_debian $rootfs $name
 
303
if [ $? -ne 0 ]; then
 
304
    echo "failed to configure debian for a container"
 
305
    exit 1
 
306
fi
 
307
 
 
308
copy_configuration $path $rootfs
 
309
if [ $? -ne 0 ]; then
 
310
    echo "failed write configuration file"
 
311
    exit 1
 
312
fi
 
313
 
 
314
if [ ! -z $clean ]; then
 
315
    clean || exit 1
 
316
    exit 0
 
317
fi