vshost-util-vserver

Build script and sources for util-vserver.
git clone https://ccx.te2000.cz/git/vshost-util-vserver
Log | Files | Refs

initpost (3754B)


      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 
    108 # upstart fixing
    109 if $_CHROOT_SH testfile /sbin/initctl; then
    110     for i in etc/init/*; do
    111 	i=${i##*/}
    112 	case "$i" in
    113 	  (control-alt-delete.conf|rc.conf)
    114 	    ;;
    115 	  (rsyslog.conf|syslog-ng.conf)
    116 	    ;;
    117 	  (*)
    118 	    chrootsed /etc/init/$i \
    119 		-e 's/^/#/'
    120 	    ;;
    121 	esac
    122     done
    123     $_CHROOT_SH truncate /etc/init/vserver.conf <<EOF
    124 start on startup
    125 script
    126        initctl emit virtual-filesystems
    127        initctl emit local-filesystems
    128        initctl emit remote-filesystems
    129        initctl emit filesystem
    130 end script
    131 EOF
    132 fi
    133 
    134 
    135 # start vserver before we can exec anything inside it
    136 $_VSERVER "$NAME" stop &>/dev/null || :
    137 startSleepingGuest "$NAME" 30
    138 
    139 # run the configure commands from within the server
    140 export LANG=C LC_ALL=C
    141 
    142 $_CHROOT_SH testfile /usr/sbin/locale-gen && \
    143     $_VSERVER "$NAME" exec /usr/sbin/locale-gen
    144 
    145 have_halt=
    146 test "$(cat "$cfgdir"/apps/init/style 2>/dev/null)" != "plain" || \
    147     have_halt=halt
    148 
    149 pushd etc/init.d &>/dev/null
    150 for i in *; do
    151     case "$i" in
    152       (sysklogd|syslog-ng|rsyslog|dsyslog)
    153 	;;
    154       (README|skeleton|sendsigs|single|rc|rc.local|rcS)
    155 	;;
    156       ($have_halt)
    157 	;;
    158       (*)
    159 	$_VSERVER "$NAME" exec update-rc.d -f "$i" remove
    160 	;;
    161     esac
    162 done
    163 popd &>/dev/null
    164 
    165 # stop the vserver
    166 stopSleepingGuest "$NAME" &>/dev/null || :
    167 
    168 popd &>/dev/null