ready for tagging
[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"
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 echo
107 echo ">>> Executing post install script ... "
108 echo
109
110 # start vserver before we can exec anything inside it
111 $_VSERVER "$NAME" stop &>/dev/null || :
112 $_VSERVER "$NAME" start --rescue --rescue-init bash -c '
113     exec  > /dev/null
114     exec 2> /dev/null
115
116     set -x
117     f=/tmp/startwait
118     trap "rm -f $f" EXIT
119     mkfifo $f
120     ( sleep 15; kill -s 9 -- -1 ) &
121     cat "$f"
122     kill -s 9 -- -1
123     wait
124 '
125
126 # run the configure commands from within the server
127 export LANG=C LC_ALL=C
128
129 $_CHROOT_SH testfile /usr/sbin/locale-gen && \
130     $_VSERVER "$NAME" exec /usr/sbin/locale-gen
131
132 for i in bootlogd checkfs checkroot halt hwclock.sh ifupdown klogd \
133          libdevmapper1.02 makedev module-init-tools mountall.sh \
134          mountdevsubfs.sh mountnfs.sh mountkernfs.sh mountvirtfs \
135          networking reboot setserial single stop-bootlogd \
136          stop-bootlogd-single umountfs umountnfs.sh umountroot \
137          urandom; do
138     $_VSERVER "$NAME" exec update-rc.d -f "$i" remove
139 done
140
141 # stop the vserver
142 $_VSERVER "$NAME" exec bash -c ': >/tmp/startwait' &>/dev/null || :
143 $_VSERVER "$NAME" stop &>/dev/null || :
144
145 popd &>/dev/null