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