summaryrefslogtreecommitdiff
blob: 782c3f1b450988b4744db848c4257969938ab58f (plain)
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
Index: scripts/vserver.functions
===================================================================
--- scripts/vserver.functions	(revision 2354)
+++ scripts/vserver.functions	(revision 2370)
@@ -299,8 +299,28 @@
 	    ;;
 
 	(xgentoo)
-	    panic "init-style '$INITSTYLE' is no longer supported; please use plain instead; aborting";;
+	    test -n "$RUNLEVEL_START" || RUNLEVEL_START="default"
 
+	    INITCMD_START=( /lib/rcscripts/sh/init-vserver.sh "$RUNLEVEL_START" )
+	    INITCMD_STOP=( /sbin/rc shutdown )
+	    INITCMD_PREPARE=( $_FAKE_RUNLEVEL 3 /var/run/utmp )
+
+	    pushd "$vdir"/vdir &>/dev/null
+	    basever=$($_CHROOT_SH cat /etc/gentoo-release | $_AWK '{print $5}')
+	    popd &>/dev/null
+
+	    basemaj=${basever/.*}
+	    basemin=${basever#*.}
+	    basemin=${basemin/.*}
+
+	    test "$basemaj" -lt 1 -o "$basemin" -lt 13 && \
+	    panic "\
+Using init-style 'gentoo' requires >=baselayout-1.13 inside the vserver!
+
+Your vserver ($(basename "$vdir")) seems to have baselayout-$basever,
+please use 'plain' init-style instead!"
+	    ;;
+
 	(x) ;;
 	(*) panic "Unknown init-style '$INITSTYLE'; aborting";;
     esac
Index: distrib/Makefile.am
===================================================================
--- distrib/Makefile.am	(revision 2354)
+++ distrib/Makefile.am	(revision 2370)
@@ -31,7 +31,9 @@
 nobase_distrib_SCRIPTS	=  redhat/initpost \
 			   redhat/initpre \
 			   redhat/rc.sysinit \
-			   gentoo/initpost
+			   gentoo/initpost \
+			   gentoo/initpre \
+			   gentoo/init-vserver.sh
 
 nobase_distrib_DATA	=  defaults/devs \
 			   defaults/apt.conf \
Index: distrib/gentoo/init-vserver.sh
===================================================================
--- distrib/gentoo/init-vserver.sh	(revision 0)
+++ distrib/gentoo/init-vserver.sh	(revision 2370)
@@ -0,0 +1,29 @@
+#!/bin/bash
+#
+# Copyright (C) 2006 Benedikt Boehm <hollow@gentoo.org>
+#  
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#  
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#  
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+#
+# BIG FAT WARNING:
+#
+# Do not remove this file if you are using gentoo init style!
+# Your vserver will not boot anymore!
+#
+# You have been warned...
+#
+
+RUNLEVEL=1 /sbin/rc sysinit
+/sbin/rc boot
+/sbin/rc ${1:-default}
Index: distrib/gentoo/initpost
===================================================================
--- distrib/gentoo/initpost	(revision 2354)
+++ distrib/gentoo/initpost	(revision 2370)
@@ -1,6 +1,6 @@
-#! /bin/bash
+#!/bin/bash
 
-# Copyright (C) 2005 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+# Copyright (C) 2006 Benedikt Boehm <hollow@gentoo.org>
 #  
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -17,12 +17,87 @@
 
 ## Called as: initpost <cfgdir> <path of util-vserver-vars>
 
+vdir="$1"/vdir
 . "$2"
 
-$_MKDIR -p "$1"/vdir/usr/portage
+# portage stuff
+pushd "$vdir" &>/dev/null
+$_CHROOT_SH mkdir /usr         2>/dev/null || :
+$_CHROOT_SH mkdir /usr/portage 2>/dev/null || :
+popd &>/dev/null
 
-$_CAT <<EOF >> "$1"/fstab
-# shared portage tree
-/usr/portage           /usr/portage           none bind,ro 0 0
-/usr/portage/distfiles /usr/portage/distfiles none bind,rw 0 0
-EOF
+
+# gentoo initstyle magic
+initstyle=sysv
+test -e "$1"/apps/init/style && initstyle=$(<"$1"/apps/init/style)
+
+if test "$initstyle" == "gentoo"; then
+	pushd "$vdir" &>/dev/null
+
+	echo ">>> Installing special init-style magic ... "
+
+	$_CAT "$__DISTRIBDIR"/gentoo/init-vserver.sh | \
+	$_CHROOT_SH truncate   /lib/rcscripts/sh/init-vserver.sh
+	$_CHROOT_SH chmod 0755 /lib/rcscripts/sh/init-vserver.sh
+
+	popd &>/dev/null
+
+	echo "!!!"
+	echo "!!! You have to install a service (e.g. syslog-ng) and add it to the"
+	echo "!!! default runlevel before you start the guest the first time!"
+	echo "!!! Otherwise the guest will die as soon as it has finished booting."
+	echo "!!!"
+	echo "!!! Consult the Gentoo Handbook on how to chroot and install"
+	echo "!!! packages into the guest environment."
+	echo "!!!"
+fi
+
+
+# check for baselayout >= 1.13
+pushd "$vdir" &>/dev/null
+basever=$($_CHROOT_SH cat /etc/gentoo-release | $_AWK '{print $5}')
+popd &>/dev/null
+
+echo ">>> Found baselayout-$basever"
+
+basemaj=${basever/.*}
+basemin=${basever#*.}
+basemin=${basemin/.*}
+
+if test "$basemaj" -lt 1 -o "$basemin" -lt 13; then
+	echo "!!! Will not do automagic changes to baselayout < 1.13"
+	echo "!!! You have to take care for yourself ..."
+	exit 0
+fi
+
+
+# fix gettys in inittab
+pushd "$vdir" &>/dev/null
+
+if $_CHROOT_SH testfile /etc/inittab; then
+	echo ">>> Fixing inittab ... "
+	inittabtmp=$($_MKTEMP inittab.XXXXXX)
+
+	$_CHROOT_SH cat /etc/inittab | \
+	$_SED 's/\(^[^#].*getty.*$\)/#\1/' > $inittabtmp
+	$_CHROOT_SH truncate /etc/inittab  < $inittabtmp
+
+	$_RM -f $inittabtmp
+fi
+
+popd &>/dev/null
+
+
+# unneeded runlevel scripts
+pushd "$vdir" &>/dev/null
+echo ">>> Fixing default runlevel scripts ... "
+$_CHROOT_SH rm /etc/runlevels/boot/{clock,consolefont,keymaps,modules,net.lo} 2>/dev/null || :
+$_CHROOT_SH rm /etc/runlevels/default/{hdparm,netmount} 2>/dev/null || :
+popd &>/dev/null
+
+
+# fix fstab for checkfs/localmount
+pushd "$vdir" &>/dev/null
+echo ">>> Fixing fstab ... "
+echo "/dev/hdv1 / ufs defaults 0 0" | $_CHROOT_SH truncate /etc/fstab
+popd &>/dev/null
Index: distrib/gentoo/initpre
===================================================================
--- distrib/gentoo/initpre	(revision 0)
+++ distrib/gentoo/initpre	(revision 2370)
@@ -0,0 +1,48 @@
+#!/bin/bash
+
+# Copyright (C) 2006 Benedikt Boehm <hollow@gentoo.org>
+#  
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#  
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#  
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+## Called as: initpost <cfgdir> <path of util-vserver-vars>
+
+vdir="$1"/vdir
+. "$2"
+
+# portage stuff
+
+echo ">>> Adding shared /usr/portage to fstab ... "
+
+if test -d /usr/portage; then
+	( echo
+	  echo "# shared portage tree"
+	  echo "/usr/portage           /usr/portage           none bind,ro 0 0"
+	  echo "/usr/portage/distfiles /usr/portage/distfiles none bind,rw 0 0"
+	) >> "$1"/fstab
+else
+	echo "!!! Cannot find /usr/portage! You should definitely use a"
+	echo "!!! shared portage tree if you have multiple Gentoo guests!"
+fi
+
+
+# initstyle sanity
+initstyle=sysv
+test -e "$1"/apps/init/style && initstyle=$(<"$1"/apps/init/style)
+
+echo ">>> Checking init-style ... $initstyle"
+
+if test "$initstyle" != "gentoo" -a "$initstyle" != "plain"; then
+	echo "!!! The init-style you specified is not supported for Gentoo"
+	echo "!!! Please use one of: plain, gentoo"
+fi