vshost-util-vserver

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

initpost (4225B)


      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 # finish notice from initpre
     21 echo "ok"
     22 
     23 
     24 #setup environment
     25 cfgdir="$1"
     26 vdir="$cfgdir"/vdir
     27 . "$2"
     28 
     29 
     30 # go to vdir for chroot-sh
     31 pushd "$vdir" &>/dev/null
     32 
     33 
     34 # helper for sed in chroot
     35 chrootsed() {
     36 	local file="$1"
     37 	shift
     38 	
     39 	sedtmp=$($_MKTEMP chrootsed.XXXXXX)
     40 	
     41 	$_CHROOT_SH cat "$file" | $_SED "$@" > $sedtmp
     42 	$_CHROOT_SH truncate "$file"  < $sedtmp
     43 	
     44 	$_RM -f $sedtmp
     45 }
     46 
     47 
     48 # portage stuff
     49 $_CHROOT_SH mkdir /usr 2>/dev/null || :
     50 $_CHROOT_SH mkdir /usr/portage 2>/dev/null || :
     51 $_CHROOT_SH mkdir /usr/portage/distfiles 2>/dev/null || :
     52 
     53 
     54 # check if we have openrc
     55 have_openrc=0
     56 $_CHROOT_SH testfile /lib/rc/bin/is_older_than && have_openrc=1
     57 
     58 
     59 # gentoo initstyle magic
     60 initstyle=sysv
     61 test -e "$cfgdir"/apps/init/style && initstyle=$(<"$cfgdir"/apps/init/style)
     62 
     63 if test "$initstyle" == "gentoo"; then
     64 	echo ">>> Installing special init-style magic ... "
     65 
     66 	# force /lib/rc/sh even if we don't have it in older stages
     67 	$_CHROOT_SH mkdir /lib 2>/dev/null || :
     68 	$_CHROOT_SH mkdir /lib/rc 2>/dev/null || :
     69 	$_CHROOT_SH mkdir /lib/rc/sh 2>/dev/null || :
     70 
     71 	$_CAT "$__DISTRIBDIR"/gentoo/init-vserver.sh | \
     72 	$_CHROOT_SH truncate   /lib/rc/sh/init-vserver.sh
     73 	$_CHROOT_SH chmod 0755 /lib/rc/sh/init-vserver.sh
     74 
     75 	$_CAT "$__DISTRIBDIR"/gentoo/reboot.sh | \
     76 	$_CHROOT_SH truncate   /etc/init.d/reboot.sh
     77 	$_CHROOT_SH chmod 0755 /etc/init.d/reboot.sh
     78 
     79 	$_CAT "$__DISTRIBDIR"/gentoo/shutdown.sh | \
     80 	$_CHROOT_SH truncate   /etc/init.d/shutdown.sh
     81 	$_CHROOT_SH chmod 0755 /etc/init.d/shutdown.sh
     82 
     83 	echo "!!!"
     84 	echo "!!! You have to install a service (e.g. syslog/cron) and add it to the"
     85 	echo "!!! default runlevel before you start the guest the first time!"
     86 	echo "!!! Otherwise the guest will die as soon as it has finished booting."
     87 	echo "!!!"
     88 	echo "!!! Consult the Gentoo Handbook on how to chroot and install"
     89 	echo "!!! packages into the guest environment."
     90 	echo "!!!"
     91 else
     92 	# fix gettys in inittab
     93 	if $_CHROOT_SH testfile /etc/inittab; then
     94 		echo ">>> Fixing inittab ... "
     95 		chrootsed /etc/inittab \
     96 			-e 's/\(^[^#].*getty.*$\)/#\1/'
     97 	fi
     98 fi
     99 
    100 # unneeded runlevel scripts
    101 if test $have_openrc -ne 1; then
    102 	echo ">>> Fixing default runlevel scripts ... "
    103 	$_CHROOT_SH rm /etc/runlevels/boot/{clock,consolefont,keymaps,modules,net.lo} 2>/dev/null || :
    104 	$_CHROOT_SH rm /etc/runlevels/default/{hdparm,netmount} 2>/dev/null || :
    105 fi
    106 
    107 # setting hostname
    108 if test -r "$cfgdir"/uts/nodename && $_CHROOT_SH testfile /etc/conf.d/hostname; then
    109 	echo ">>> Setting hostname ... "
    110 	chrootsed /etc/conf.d/hostname \
    111 		-e "s:\(HOSTNAME\)=\"\(.*\)\":\1=\"$(< "$cfgdir"/uts/nodename)\":i"
    112 fi
    113 
    114 # fix syslog-ng.conf
    115 if $_CHROOT_SH testfile /etc/syslog-ng/syslog-ng.conf; then
    116 	echo ">>> Fixing syslog-ng.conf ... "
    117 	chrootsed /etc/syslog-ng/syslog-ng.conf \
    118 		-e '/proc\/kmsg/d' \
    119 		-e 's:\(.*console_all.*\):#\1:g'
    120 fi
    121 
    122 # fix fstab for checkfs/localmount in baselayout-2
    123 # (does not affect any previous versions)
    124 if test $have_openrc -ne 1; then
    125 	echo ">>> Fixing fstab ... "
    126 	echo "/dev/hdv1 / ufs defaults 0 0" | $_CHROOT_SH truncate /etc/fstab
    127 fi
    128 
    129 # always satisfy net dependency in baselayout-2
    130 # (does not affect any previous versions)
    131 if test $have_openrc -ne 1; then
    132 	echo ">>> Providing dummy net dependency ... "
    133 	$_CAT "$__DISTRIBDIR"/gentoo/net.vserver | \
    134 	$_CHROOT_SH truncate /etc/init.d/net.vserver
    135 	$_CHROOT_SH chmod 0755 /etc/init.d/net.vserver
    136 	$_CHROOT_SH link /etc/init.d/net.vserver /etc/runlevels/boot/net.vserver
    137 fi
    138 
    139 popd &>/dev/null