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