gentoo: use /var/run for new /run compatibility
[util-vserver.git] / distrib / gentoo / initpost
index e30455b..f1d6229 100755 (executable)
 
 ## Called as: initpost <cfgdir> <path of util-vserver-vars>
 
+# finish notice from initpre
+echo "ok"
+
+
+#setup environment
 cfgdir="$1"
 vdir="$cfgdir"/vdir
 . "$2"
 
-# portage stuff
+
+# go to vdir for chroot-sh
 pushd "$vdir" &>/dev/null
-$_CHROOT_SH mkdir /usr         2>/dev/null || :
+
+
+# helper for sed in chroot
+chrootsed() {
+       local file="$1"
+       shift
+       
+       sedtmp=$($_MKTEMP chrootsed.XXXXXX)
+       
+       $_CHROOT_SH cat "$file" | $_SED "$@" > $sedtmp
+       $_CHROOT_SH truncate "$file"  < $sedtmp
+       
+       $_RM -f $sedtmp
+}
+
+
+# portage stuff
+$_CHROOT_SH mkdir /usr 2>/dev/null || :
 $_CHROOT_SH mkdir /usr/portage 2>/dev/null || :
-popd &>/dev/null
+$_CHROOT_SH mkdir /usr/portage/distfiles 2>/dev/null || :
+
+
+# check if we have openrc
+have_openrc=0
+$_CHROOT_SH testfile /lib/rc/bin/is_older_than && have_openrc=1
 
 
 # gentoo initstyle magic
@@ -33,89 +61,79 @@ initstyle=sysv
 test -e "$cfgdir"/apps/init/style && initstyle=$(<"$cfgdir"/apps/init/style)
 
 if test "$initstyle" == "gentoo"; then
-       pushd "$vdir" &>/dev/null
-
        echo ">>> Installing special init-style magic ... "
 
+       # force /lib/rc/sh even if we don't have it in older stages
+       $_CHROOT_SH mkdir /lib 2>/dev/null || :
+       $_CHROOT_SH mkdir /lib/rc 2>/dev/null || :
+       $_CHROOT_SH mkdir /lib/rc/sh 2>/dev/null || :
+
        $_CAT "$__DISTRIBDIR"/gentoo/init-vserver.sh | \
-       $_CHROOT_SH truncate   /lib/rcscripts/sh/init-vserver.sh
-       $_CHROOT_SH chmod 0755 /lib/rcscripts/sh/init-vserver.sh
+       $_CHROOT_SH truncate   /lib/rc/sh/init-vserver.sh
+       $_CHROOT_SH chmod 0755 /lib/rc/sh/init-vserver.sh
 
-       popd &>/dev/null
+       $_CAT "$__DISTRIBDIR"/gentoo/reboot.sh | \
+       $_CHROOT_SH truncate   /etc/init.d/reboot.sh
+       $_CHROOT_SH chmod 0755 /etc/init.d/reboot.sh
+
+       $_CAT "$__DISTRIBDIR"/gentoo/shutdown.sh | \
+       $_CHROOT_SH truncate   /etc/init.d/shutdown.sh
+       $_CHROOT_SH chmod 0755 /etc/init.d/shutdown.sh
 
        echo "!!!"
-       echo "!!! You have to install a service (e.g. syslog-ng) and add it to the"
+       echo "!!! You have to install a service (e.g. syslog/cron) and add it to the"
        echo "!!! default runlevel before you start the guest the first time!"
        echo "!!! Otherwise the guest will die as soon as it has finished booting."
        echo "!!!"
        echo "!!! Consult the Gentoo Handbook on how to chroot and install"
        echo "!!! packages into the guest environment."
        echo "!!!"
+else
+       # fix gettys in inittab
+       if $_CHROOT_SH testfile /etc/inittab; then
+               echo ">>> Fixing inittab ... "
+               chrootsed /etc/inittab \
+                       -e 's/\(^[^#].*getty.*$\)/#\1/'
+       fi
 fi
 
-
 # unneeded runlevel scripts
-pushd "$vdir" &>/dev/null
-echo ">>> Fixing default runlevel scripts ... "
-$_CHROOT_SH rm /etc/runlevels/boot/{clock,consolefont,keymaps,modules,net.lo} 2>/dev/null || :
-$_CHROOT_SH rm /etc/runlevels/default/{hdparm,netmount} 2>/dev/null || :
-popd &>/dev/null
-
+if test $have_openrc -ne 1; then
+       echo ">>> Fixing default runlevel scripts ... "
+       $_CHROOT_SH rm /etc/runlevels/boot/{clock,consolefont,keymaps,modules,net.lo} 2>/dev/null || :
+       $_CHROOT_SH rm /etc/runlevels/default/{hdparm,netmount} 2>/dev/null || :
+fi
 
 # setting hostname
-pushd "$vdir" &>/dev/null
-
 if test -r "$cfgdir"/uts/nodename && $_CHROOT_SH testfile /etc/conf.d/hostname; then
        echo ">>> Setting hostname ... "
-       hostnametmp=$($_MKTEMP hostname.XXXXXX)
-
-       $_CHROOT_SH cat /etc/conf.d/hostname | \
-       $_SED "s:HOSTNAME=\"\(.*\)\":HOSTNAME=\"$(< "$cfgdir"/uts/nodename)\":" > $hostnametmp
-       $_CHROOT_SH truncate /etc/conf.d/hostname  < $hostnametmp
-
-       $_RM -f $hostnametmp
+       chrootsed /etc/conf.d/hostname \
+               -e "s:\(HOSTNAME\)=\"\(.*\)\":\1=\"$(< "$cfgdir"/uts/nodename)\":i"
 fi
 
-popd &>/dev/null
-
-
-# check for baselayout >= 1.13
-pushd "$vdir" &>/dev/null
-basever=$($_CHROOT_SH cat /etc/gentoo-release | $_AWK '{print $5}')
-popd &>/dev/null
-
-echo ">>> Found baselayout-$basever"
-
-basemaj=${basever/.*}
-basemin=${basever#*.}
-basemin=${basemin/.*}
-
-if test "$basemaj" -lt 1 -o "$basemin" -lt 13; then
-       echo "!!! Will not do automagic changes to baselayout < 1.13"
-       echo "!!! You have to take care for yourself ..."
-       exit 0
+# fix syslog-ng.conf
+if $_CHROOT_SH testfile /etc/syslog-ng/syslog-ng.conf; then
+       echo ">>> Fixing syslog-ng.conf ... "
+       chrootsed /etc/syslog-ng/syslog-ng.conf \
+               -e '/proc\/kmsg/d' \
+               -e 's:\(.*console_all.*\):#\1:g'
 fi
 
-
-# fix gettys in inittab
-pushd "$vdir" &>/dev/null
-
-if $_CHROOT_SH testfile /etc/inittab; then
-       echo ">>> Fixing inittab ... "
-       inittabtmp=$($_MKTEMP inittab.XXXXXX)
-
-       $_CHROOT_SH cat /etc/inittab | \
-       $_SED 's/\(^[^#].*getty.*$\)/#\1/' > $inittabtmp
-       $_CHROOT_SH truncate /etc/inittab  < $inittabtmp
-
-       $_RM -f $inittabtmp
+# fix fstab for checkfs/localmount in baselayout-2
+# (does not affect any previous versions)
+if test $have_openrc -ne 1; then
+       echo ">>> Fixing fstab ... "
+       echo "/dev/hdv1 / ufs defaults 0 0" | $_CHROOT_SH truncate /etc/fstab
 fi
 
-popd &>/dev/null
-
+# always satisfy net dependency in baselayout-2
+# (does not affect any previous versions)
+if test $have_openrc -ne 1; then
+       echo ">>> Providing dummy net dependency ... "
+       $_CAT "$__DISTRIBDIR"/gentoo/net.vserver | \
+       $_CHROOT_SH truncate /etc/init.d/net.vserver
+       $_CHROOT_SH chmod 0755 /etc/init.d/net.vserver
+       $_CHROOT_SH link /etc/init.d/net.vserver /etc/runlevels/boot/net.vserver
+fi
 
-# fix fstab for checkfs/localmount
-pushd "$vdir" &>/dev/null
-echo ">>> Fixing fstab ... "
-echo "/dev/hdv1 / ufs defaults 0 0" | $_CHROOT_SH truncate /etc/fstab
 popd &>/dev/null