f2816561ec36cf892be0a6d1e2b0dfdedba26499
[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
23 function relink
24 {
25     test ! -e "$2" -o -L "$2" || mv -f "$2"{,.orig}
26     ln -sf "$1" "$2"
27 }
28
29 ## Usage: subst <file> <regexp>
30 function subst
31 {
32     tmp=$(mktemp /tmp/initpost-subst.XXXXXX)
33
34     case "$1" in
35         (/*|./*)        cat "$1";;
36         (*)             $_CHROOT_SH cat "$1";;
37     esac              | sed -e "$2"          >$tmp
38     cmp -s $tmp "$1" || $_CHROOT_SH truncate "$1" <$tmp
39
40     rm -f $tmp
41 }
42
43 pushd "$vdir"/etc/init.d &>/dev/null ||
44     pushd "$vdir"/etc/rc.d/init.d &>/dev/null || exit 1
45
46     for i in *; do
47         test -e "$i" || continue
48         case "$i" in
49             functions|halt|killall|single) ;;
50             syslog) ;;
51             *)
52                 $_VSERVER ----insecure "$1" chkconfig "$i" off
53                 ;;
54         esac
55     done
56
57     relink /bin/true halt
58 popd >/dev/null
59
60 pushd "$vdir"/sbin &>/dev/null
61     relink /bin/true new-kernel-pkg
62 popd >/dev/null
63
64 pushd "$vdir"/usr/bin &>/dev/null
65     relink /bin/true rhgb-client
66 popd >/dev/null
67
68 pushd "$vdir" &>/dev/null
69     echo 'NETWORKING=yes' | $_CHROOT_SH append /etc/sysconfig/network
70 popd >/dev/null
71
72 pushd "$vdir" &>/dev/null
73     : | $_CHROOT_SH truncate /etc/sysctl.conf
74     echo "none    /       none    defaults" | $_CHROOT_SH truncate /etc/fstab
75     cat "$__DISTRIBDIR"/redhat/rc.sysinit   | $_CHROOT_SH truncate /etc/rc.d/rc.sysinit.vserver
76     # TODO: remove race/symlink-attack
77     chmod +x etc/rc.d/rc.sysinit.vserver
78     subst etc/inittab 's!^\([^#].*:respawn:.* tty\)!#\1!;
79                        s!si::sysinit:/etc/rc.d/rc.sysinit!si::sysinit:/etc/rc.d/rc.sysinit.vserver!'
80 popd >/dev/null