manual merge of the distrib/ part from a prerelease of 0.30.215
[util-vserver.git] / distrib / redhat / initpost
1 #! /bin/bash
2
3 # Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
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 ## HACK: this script is full of races...
19
20 vdir=$1/vdir
21 . "$2"
22 . "$_LIB_VSERVER_BUILD_FUNCTIONS"
23
24 function relink
25 {
26     test ! -e "$2" -o -L "$2" || mv -f "$2"{,.orig}
27     ln -sf "$1" "$2"
28 }
29
30 ## Usage: subst <file> <regexp>
31 function subst
32 {
33     tmp=$(mktemp /tmp/initpost-subst.XXXXXX)
34
35     case "$1" in
36         (/*|./*)        cat "$1";;
37         (*)             $_CHROOT_SH cat "$1";;
38     esac              | sed -e "$2"          >$tmp
39     cmp -s $tmp "$1" || $_CHROOT_SH truncate "$1" <$tmp
40
41     rm -f $tmp
42 }
43
44 vserver=$1
45
46 ## Do some magic to set the vserver into a defined state
47 $_VSERVER "$vserver" stop  &>/dev/null || :
48 startSleepingGuest "$vserver" 15
49
50 pushd "$vdir"/etc/init.d &>/dev/null ||
51     pushd "$vdir"/etc/rc.d/init.d &>/dev/null || exit 1
52
53     for i in *; do
54         test -e "$i" || continue
55         case "$i" in
56             functions|halt|killall|single) ;;
57             syslog|rsyslog) ;;
58             *)
59                 $_VSERVER "$1" chkconfig "$i" off
60                 ;;
61         esac
62     done
63
64 popd >/dev/null
65
66 pushd "$vdir"/sbin &>/dev/null
67     relink /bin/true new-kernel-pkg
68 popd >/dev/null
69
70 pushd "$vdir"/usr/bin &>/dev/null
71     relink /bin/true rhgb-client
72 popd >/dev/null
73
74 pushd "$vdir" &>/dev/null
75     echo 'NETWORKING=yes' | $_CHROOT_SH append /etc/sysconfig/network
76 popd >/dev/null
77
78 pushd "$vdir" &>/dev/null
79     cat <<EOF | $_CHROOT_SH truncate /etc/init.d/halt
80 #! /bin/bash
81
82 exec /sbin/killall5 -15
83 EOF
84     $_CHROOT_SH chmod 0755 /etc/init.d/halt
85     
86     : | $_CHROOT_SH truncate /etc/sysctl.conf
87     echo "none    /       none    defaults" | $_CHROOT_SH truncate /etc/fstab
88     cat "$__DISTRIBDIR"/redhat/rc.sysinit   | $_CHROOT_SH truncate /etc/rc.d/rc.sysinit.vserver
89     $_CHROOT_SH chmod 0755 /etc/rc.d/rc.sysinit.vserver
90     subst etc/inittab 's!^\([^#].*:respawn:.* tty\)!#\1!;
91                        s!si::sysinit:/etc/rc.d/rc.sysinit!si::sysinit:/etc/rc.d/rc.sysinit.vserver!'
92 popd >/dev/null
93
94 stopSleepingGuest "$vserver" &> /dev/null || :