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