e30455bf7c730cb9a8b2d445f23d125b03013d52
[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 cfgdir="$1"
21 vdir="$cfgdir"/vdir
22 . "$2"
23
24 # portage stuff
25 pushd "$vdir" &>/dev/null
26 $_CHROOT_SH mkdir /usr         2>/dev/null || :
27 $_CHROOT_SH mkdir /usr/portage 2>/dev/null || :
28 popd &>/dev/null
29
30
31 # gentoo initstyle magic
32 initstyle=sysv
33 test -e "$cfgdir"/apps/init/style && initstyle=$(<"$cfgdir"/apps/init/style)
34
35 if test "$initstyle" == "gentoo"; then
36         pushd "$vdir" &>/dev/null
37
38         echo ">>> Installing special init-style magic ... "
39
40         $_CAT "$__DISTRIBDIR"/gentoo/init-vserver.sh | \
41         $_CHROOT_SH truncate   /lib/rcscripts/sh/init-vserver.sh
42         $_CHROOT_SH chmod 0755 /lib/rcscripts/sh/init-vserver.sh
43
44         popd &>/dev/null
45
46         echo "!!!"
47         echo "!!! You have to install a service (e.g. syslog-ng) and add it to the"
48         echo "!!! default runlevel before you start the guest the first time!"
49         echo "!!! Otherwise the guest will die as soon as it has finished booting."
50         echo "!!!"
51         echo "!!! Consult the Gentoo Handbook on how to chroot and install"
52         echo "!!! packages into the guest environment."
53         echo "!!!"
54 fi
55
56
57 # unneeded runlevel scripts
58 pushd "$vdir" &>/dev/null
59 echo ">>> Fixing default runlevel scripts ... "
60 $_CHROOT_SH rm /etc/runlevels/boot/{clock,consolefont,keymaps,modules,net.lo} 2>/dev/null || :
61 $_CHROOT_SH rm /etc/runlevels/default/{hdparm,netmount} 2>/dev/null || :
62 popd &>/dev/null
63
64
65 # setting hostname
66 pushd "$vdir" &>/dev/null
67
68 if test -r "$cfgdir"/uts/nodename && $_CHROOT_SH testfile /etc/conf.d/hostname; then
69         echo ">>> Setting hostname ... "
70         hostnametmp=$($_MKTEMP hostname.XXXXXX)
71
72         $_CHROOT_SH cat /etc/conf.d/hostname | \
73         $_SED "s:HOSTNAME=\"\(.*\)\":HOSTNAME=\"$(< "$cfgdir"/uts/nodename)\":" > $hostnametmp
74         $_CHROOT_SH truncate /etc/conf.d/hostname  < $hostnametmp
75
76         $_RM -f $hostnametmp
77 fi
78
79 popd &>/dev/null
80
81
82 # check for baselayout >= 1.13
83 pushd "$vdir" &>/dev/null
84 basever=$($_CHROOT_SH cat /etc/gentoo-release | $_AWK '{print $5}')
85 popd &>/dev/null
86
87 echo ">>> Found baselayout-$basever"
88
89 basemaj=${basever/.*}
90 basemin=${basever#*.}
91 basemin=${basemin/.*}
92
93 if test "$basemaj" -lt 1 -o "$basemin" -lt 13; then
94         echo "!!! Will not do automagic changes to baselayout < 1.13"
95         echo "!!! You have to take care for yourself ..."
96         exit 0
97 fi
98
99
100 # fix gettys in inittab
101 pushd "$vdir" &>/dev/null
102
103 if $_CHROOT_SH testfile /etc/inittab; then
104         echo ">>> Fixing inittab ... "
105         inittabtmp=$($_MKTEMP inittab.XXXXXX)
106
107         $_CHROOT_SH cat /etc/inittab | \
108         $_SED 's/\(^[^#].*getty.*$\)/#\1/' > $inittabtmp
109         $_CHROOT_SH truncate /etc/inittab  < $inittabtmp
110
111         $_RM -f $inittabtmp
112 fi
113
114 popd &>/dev/null
115
116
117 # fix fstab for checkfs/localmount
118 pushd "$vdir" &>/dev/null
119 echo ">>> Fixing fstab ... "
120 echo "/dev/hdv1 / ufs defaults 0 0" | $_CHROOT_SH truncate /etc/fstab
121 popd &>/dev/null