New import
[util-vserver.git] / distrib / alpine / initpost
1 #!/bin/bash
2
3 # Copyright (C) 2007 Natanael Copa <ncopa@alpinelinux.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 cfgdir="$1"
21 vdir="$cfgdir"/vdir
22 . "$2"
23
24 cd "$vdir"
25
26 echo ">>> Creating missing dirs..."
27 $_CHROOT_SH mkdir proc sys dev home etc etc/rcL.d etc/rcK.d 2>/dev/null
28
29 # remove mtab which is a link
30 if test -e "$vdir/etc/mtab"; then
31         $_CHROOT_SH rm /etc/mtab 2>/dev/null
32 fi
33
34 # trick to install busybox links and boot services
35 echo ">>> Installing boot services..."
36 vserver="$1"
37 $_VSERVER "$vserver" stop  &>/dev/null || true
38 $_VSERVER "$vserver" start --rescue --rescue-init /bin/busybox sh -c '
39         /bin/busybox --install -s
40         /sbin/rc_add -s 20 -k syslog
41 '
42
43 # set up hostname
44 if test -r "$cfgdir"/uts/nodename; then
45         echo ">>> Setting hostname..."
46         $_CHROOT_SH truncate /etc/hostname < "$cfgdir/uts/nodename"
47 fi
48
49 # create fstab
50 echo -e "none\t/\tnone\tdefaults" | $_CHROOT_SH truncate /etc/fstab
51
52 # create busybox style inittab
53 cat <<EOF | $_CHROOT_SH truncate /etc/inittab
54 ::wait:/etc/init.d/rcL
55 ::ctrlaltdel:/etc/init.d/rcK
56 ::ctrlaltdel:/usr/bin/killall5 -15
57 EOF
58
59 # set up cmd.start and cmd stop if needed
60 test -e "$1"/apps/init/style && initstlye=$(cat "$1"/apps/init/style)
61 if test "$initstlye" != "plain"; then
62         echo "/etc/init.d/rcL" > "$cfgdir/apps/init/cmd.start"
63         echo "/etc/init.d/rcK" > "$cfgdir/apps/init/cmd.stop"
64 fi
65
66 # vserver should not be running at this point but lets be sure
67 $_VSERVER "$vserver" stop  &>/dev/null || true
68