vshost-util-vserver

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

initpost (3516B)


      1 #! /bin/bash
      2 
      3 # Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
      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 ## HACK: this script is full of races...
     19 
     20 vdir=$1/vdir
     21 . "$2"
     22 . "$_LIB_VSERVER_BUILD_FUNCTIONS"
     23 
     24 function relink
     25 {
     26     test ! -e "$2" -o -L "$2" || mv -f "$2"{,.orig}
     27     ln -sf "$1" "$2"
     28 }
     29 
     30 ## Usage: subst <file> <regexp>
     31 function subst
     32 {
     33     tmp=$(mktemp /tmp/initpost-subst.XXXXXX)
     34 
     35     case "$1" in
     36 	(/*|./*)	cat "$1";;
     37 	(*)		$_CHROOT_SH cat "$1";;
     38     esac              | sed -e "$2"          >$tmp
     39     cmp -s $tmp "$1" || $_CHROOT_SH truncate "$1" <$tmp
     40 
     41     rm -f $tmp
     42 }
     43 
     44 vserver=$1
     45 
     46 ## Do some magic to set the vserver into a defined state
     47 $_VSERVER "$vserver" stop  &>/dev/null || :
     48 startSleepingGuest "$vserver" 15
     49 
     50 pushd "$vdir"/etc/init.d &>/dev/null ||
     51     pushd "$vdir"/etc/rc.d/init.d &>/dev/null || exit 1
     52 
     53     for i in *; do
     54 	test -e "$i" || continue
     55 	case "$i" in
     56 	    functions|halt|killall|single|reboot|README) ;;
     57 	    syslog|rsyslog)
     58 		$_VSERVER "$1" chkconfig "$i" on
     59 		;;
     60 	    *)
     61 		$_VSERVER "$1" chkconfig "$i" off
     62 		;;
     63 	esac
     64     done
     65 
     66 popd >/dev/null
     67 
     68 pushd "$vdir"/sbin &>/dev/null
     69     relink /bin/true new-kernel-pkg
     70 popd >/dev/null
     71 
     72 pushd "$vdir"/usr/bin &>/dev/null
     73     relink /bin/true rhgb-client
     74 popd >/dev/null
     75 
     76 pushd "$vdir" &>/dev/null
     77     echo 'NETWORKING=yes' | $_CHROOT_SH append /etc/sysconfig/network
     78 popd >/dev/null
     79 
     80 pushd "$vdir" &>/dev/null
     81     cat <<EOF | $_CHROOT_SH truncate /etc/init.d/halt
     82 #! /bin/bash
     83 
     84 exec /sbin/killall5 -15
     85 EOF
     86     $_CHROOT_SH chmod 0755 /etc/init.d/halt
     87     
     88     : | $_CHROOT_SH truncate /etc/sysctl.conf
     89     echo "none    /       none    defaults" | $_CHROOT_SH truncate /etc/fstab
     90     cat "$__DISTRIBDIR"/redhat/rc.sysinit   | $_CHROOT_SH truncate /etc/rc.d/rc.sysinit.vserver
     91     $_CHROOT_SH chmod 0755 /etc/rc.d/rc.sysinit.vserver
     92     subst etc/inittab 's!^\([^#].*:respawn:.* tty\)!#\1!;
     93 		       s!si::sysinit:/etc/rc.d/rc.sysinit!si::sysinit:/etc/rc.d/rc.sysinit.vserver!'
     94 
     95     if $_CHROOT_SH testfile /sbin/initctl; then
     96 	cat "$__DISTRIBDIR"/redhat/initctl | $_CHROOT_SH truncate /sbin/initctl.vserver
     97 	$_CHROOT_SH chmod 0755 /sbin/initctl.vserver
     98 	subst etc/rc.d/rc 's!^\(.*\)/proc/cmdline\(.*\)$!\1/proc/cmdline 2>/dev/null \2!;s!initctl!initctl.vserver!'
     99 	if test -d etc/event.d; then
    100 	    subst etc/event.d/rcS 's!/etc/rc.d/rc.sysinit!/etc/rc.d/rc.sysinit.vserver!'
    101 	    $_CHROOT_SH rm /etc/event.d/tty{1,2,3,4,5,6}
    102 	elif test -d etc/init; then
    103 	    for i in etc/init/*; do
    104 		subst $i 's!^console output!#\0!'
    105 	    done
    106 	    subst etc/init/control-alt-delete.conf 's!/sbin/shutdown -r!/sbin/shutdown -h!'
    107 	    subst etc/init/rcS.conf 's!/etc/rc.d/rc.sysinit!/etc/rc.d/rc.sysinit.vserver!;s!cat /proc/cmdline!cat /proc/cmdline 2>/dev/null!'
    108 	    subst etc/init/start-ttys.conf 's!^start on !\0never and !'
    109 	fi
    110     fi
    111 popd >/dev/null
    112 
    113 stopSleepingGuest "$vserver" &> /dev/null || :