cf42fe94f570b157965f5ff333dad0c68832311b
[util-vserver.git] / distrib / debian / 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 # setup environment
21 cfgdir="$1"
22 vdir="$cfgdir"/vdir
23 . "$2"
24
25
26 # vserver name
27 NAME=$(< "$cfgdir"/name)
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 # create a locale.gen if needed.
49 if test -n "$LANG" && test "$LANG" != "C"; then
50         echo $LANG $(locale charmap) | $_CHROOT_SH append /etc/locale.gen
51 fi
52
53
54 # make apt and friends work
55 $_CHROOT_SH truncate /etc/apt/sources.list <<EOF
56 deb $MIRROR/ $DISTRIBUTION main
57 deb-src $MIRROR/ $DISTRIBUTION main
58
59 deb http://security.debian.org $DISTRIBUTION/updates main
60 EOF
61
62
63 # setting hostname
64 if test -r "$cfgdir"/uts/nodename; then
65         $_CHROOT_SH truncate /etc/hostname < "$cfgdir"/uts/nodename
66 fi
67
68
69 # setting default /etc/hosts
70 $_CHROOT_SH truncate /etc/hosts <<EOF
71 # /etc/hosts
72
73 127.0.0.1       localhost
74
75 # The following lines are desirable for IPv6 capable hosts
76 # (added automatically by netbase upgrade)
77
78 ::1     ip6-localhost ip6-loopback
79 fe00::0 ip6-localnet
80 ff00::0 ip6-mcastprefix
81 ff02::1 ip6-allnodes
82 ff02::2 ip6-allrouters
83 ff02::3 ip6-allhosts
84 EOF
85
86
87 # copy proxy server statement from host if any
88 if test -f /etc/apt/apt.conf; then
89         $_CHROOT_SH truncate /etc/apt/apt.conf < /etc/apt/apt.conf
90 fi
91
92
93 # fix gettys in inittab
94 if $_CHROOT_SH testfile /etc/inittab; then
95         chrootsed /etc/inittab \
96                 -e 's/\(^[^#].*getty.*$\)/#\1/'
97 fi
98
99
100 # fix /proc/cmdline in sendsigs
101 if $_CHROOT_SH testfile /etc/init.d/sendsigs; then
102         chrootsed /etc/init.d/sendsigs \
103                 -e 's/^\(\s\+splash_back\)$/#\1/'
104 fi
105
106 # from here on we need to do things live in the server
107 $_CHROOT_SH truncate   /vserver-config.sh < "$__DISTRIBDIR"/etch/vserver-config.sh
108 $_CHROOT_SH chmod 0755 /vserver-config.sh
109
110 echo
111 echo ">>> Executing post install script ... "
112 echo
113
114 # start vserver before we can exec anything inside it
115 vserver $NAME start
116
117 # run the configure commands from within the server
118 vserver $NAME exec /vserver-config.sh
119 $_CHROOT_SH rm /vserver-config.sh
120
121 # stop the vserver
122 vserver $NAME stop
123
124 popd &>/dev/null