5c68bb3ccd0e7912a799f44031b1dc538c9b269b
[util-vserver.git] / distrib / gentoo / initpost
1 #!/bin/bash
2
3 # Copyright (C) 2006 Benedikt Boehm <hollow@gentoo.org>
4 #  
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; version 2 of the License.
8 #  
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #  
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18 ## Called as: initpost <cfgdir> <path of util-vserver-vars>
19
20 vdir="$1"/vdir
21 . "$2"
22
23 # portage stuff
24 pushd "$vdir" &>/dev/null
25 $_CHROOT_SH mkdir /usr         2>/dev/null || :
26 $_CHROOT_SH mkdir /usr/portage 2>/dev/null || :
27 popd &>/dev/null
28
29
30 # check for baselayout >= 1.13
31 pushd "$vdir" &>/dev/null
32 basever=$($_CHROOT_SH cat /etc/gentoo-release | $_AWK '{print $5}')
33 popd &>/dev/null
34
35 echo ">>> Found baselayout-$basever"
36
37 basemaj=${basever/.*}
38 basemin=${basever#*.}
39 basemin=${basemin/.*}
40
41 if test "$basemaj" -lt 1 -o "$basemin" -lt 13; then
42         echo "!!! Will not do automagic changes to baselayout < 1.13"
43         echo "!!! You have to take care for yourself ..."
44         exit 0
45 fi
46
47
48 # fix gettys in inittab
49 pushd "$vdir" &>/dev/null
50
51 if $_CHROOT_SH testfile /etc/inittab; then
52         echo ">>> Fixing inittab ... "
53         inittabtmp=$($_MKTEMP inittab.XXXXXX)
54
55         $_CHROOT_SH cat /etc/inittab | \
56         $_SED 's/\(^[^#].*getty.*$\)/#\1/' > $inittabtmp
57         $_CHROOT_SH truncate /etc/inittab  < $inittabtmp
58
59         $_RM -f $inittabtmp
60 fi
61
62 popd &>/dev/null
63
64
65 # unneeded runlevel scripts
66 pushd "$vdir" &>/dev/null
67 echo ">>> Fixing default runlevel scripts ... "
68 $_CHROOT_SH rm /etc/runlevels/boot/{clock,consolefont,keymaps,modules,net.lo} 2>/dev/null || :
69 $_CHROOT_SH rm /etc/runlevels/default/{hdparm,netmount} 2>/dev/null || :
70 popd &>/dev/null
71
72
73 # fix fstab for checkfs/localmount
74 pushd "$vdir" &>/dev/null
75 echo ">>> Fixing fstab ... "
76 echo "/dev/hdv1 / ufs defaults 0 0" | $_CHROOT_SH truncate /etc/fstab
77 popd &>/dev/null
78
79
80 # gentoo initstyle magic
81 initstyle=sysv
82 test -e "$1"/apps/init/style && initstyle=$(<"$1"/apps/init/style)
83
84 if test "$initstyle" == "gentoo"; then
85         pushd "$vdir" &>/dev/null
86
87         echo ">>> Installing special init-style magic ... "
88
89         $_CAT "$__DISTRIBDIR"/gentoo/init-vserver.sh | \
90         $_CHROOT_SH truncate   /lib/rcscripts/sh/init-vserver.sh
91         $_CHROOT_SH chmod 0755 /lib/rcscripts/sh/init-vserver.sh
92
93         popd &>/dev/null
94
95         echo "!!!"
96         echo "!!! You have to install a service (e.g. syslog-ng) and add it to the"
97         echo "!!! default runlevel before you start the guest the first time!"
98         echo "!!! Otherwise the guest will die as soon as it has finished booting."
99         echo "!!!"
100         echo "!!! Consult the Gentoo Handbook on how to chroot and install"
101         echo "!!! packages into the guest environment."
102         echo "!!!"
103 fi