2acb7d04c989d7481ee17037527f6fffb7bd7ab8
[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 . "$_LIB_VSERVER_BUILD_FUNCTIONS"
25
26
27 # vserver name
28 NAME="$cfgdir"
29
30
31 # go to vdir for chroot-sh
32 pushd "$vdir" &>/dev/null
33
34
35 # helper for sed in chroot
36 chrootsed() {
37         local file="$1"
38         shift
39         
40         sedtmp=$($_MKTEMP chrootsed.XXXXXX)
41         
42         $_CHROOT_SH cat "$file" | $_SED "$@" > $sedtmp
43         $_CHROOT_SH truncate "$file"  < $sedtmp
44         
45         $_RM -f $sedtmp
46 }
47
48
49 # create a locale.gen if needed.
50 if test -n "$LANG" && test "$LANG" != "C"; then
51         echo $LANG $(locale charmap) | $_CHROOT_SH append /etc/locale.gen
52 fi
53
54
55 # make apt and friends work
56 $_CHROOT_SH truncate /etc/apt/sources.list <<EOF
57 deb $MIRROR/ $DISTRIBUTION main
58 deb-src $MIRROR/ $DISTRIBUTION main
59
60 deb http://security.debian.org $DISTRIBUTION/updates main
61 EOF
62
63
64 # setting hostname
65 if test -r "$cfgdir"/uts/nodename; then
66         $_CHROOT_SH truncate /etc/hostname < "$cfgdir"/uts/nodename
67 fi
68
69
70 # setting default /etc/hosts
71 $_CHROOT_SH truncate /etc/hosts <<EOF
72 # /etc/hosts
73
74 127.0.0.1       localhost
75
76 # The following lines are desirable for IPv6 capable hosts
77 # (added automatically by netbase upgrade)
78
79 ::1     ip6-localhost ip6-loopback
80 fe00::0 ip6-localnet
81 ff00::0 ip6-mcastprefix
82 ff02::1 ip6-allnodes
83 ff02::2 ip6-allrouters
84 ff02::3 ip6-allhosts
85 EOF
86
87
88 # copy proxy server statement from host if any
89 if test -f /etc/apt/apt.conf; then
90         $_CHROOT_SH truncate /etc/apt/apt.conf < /etc/apt/apt.conf
91 fi
92
93
94 # fix gettys in inittab
95 if $_CHROOT_SH testfile /etc/inittab; then
96         chrootsed /etc/inittab \
97                 -e 's/\(^[^#].*getty.*$\)/#\1/'
98 fi
99
100
101 # fix /proc/cmdline in sendsigs
102 if $_CHROOT_SH testfile /etc/init.d/sendsigs; then
103         chrootsed /etc/init.d/sendsigs \
104                 -e 's/^\(\s\+splash_back\)$/#\1/'
105 fi
106
107 echo
108 echo ">>> Executing post install script ... "
109 echo
110
111 # start vserver before we can exec anything inside it
112 $_VSERVER "$NAME" stop &>/dev/null || :
113 startSleepingGuest "$NAME" 30
114
115 # run the configure commands from within the server
116 export LANG=C LC_ALL=C
117
118 $_CHROOT_SH testfile /usr/sbin/locale-gen && \
119     $_VSERVER "$NAME" exec /usr/sbin/locale-gen
120
121 have_halt=
122 test "$(cat "$cfgdir"/apps/init/style 2>/dev/null)" != "plain" || \
123     have_halt=halt
124
125 pushd etc/init.d &>/dev/null
126 for i in *; do
127     case "$i" in
128       (sysklogd|syslog-ng|README|skeleton|sendsigs|single|rc|rc.local|rcS)
129         ;;
130       ($have_halt)
131         ;;
132       (*)
133         $_VSERVER "$NAME" exec update-rc.d -f "$i" remove
134         ;;
135     esac
136 done
137 popd &>/dev/null
138
139 # stop the vserver
140 stopSleepingGuest "$NAME" &>/dev/null || :
141
142 popd &>/dev/null