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