# -*-shell-*-
# $Id$
+#shopt -s huponexit
+
COMMAND=$(basename $0)
DIRNAME=$(dirname $0)
# pkgs parsing utilities
-PATH=$(dirname $0):$PATH . build.common
+PATH=$(dirname $0):$PATH export PATH
+. build.common
DEFAULT_FCDISTRO=f8
DEFAULT_PLDISTRO=planetlab
echo "Cannot initialize yum.repos.d in $vserver"
fi
- if [ -n "$MYPLC_MODE" ] ; then
+ # for using vtest-init-vserver.sh as a general-purpose vserver creation wrapper
+ # just mention 'none' as the repo url
+ if [ -n "$MYPLC_MODE" -a "$REPO_URL" != "none" ] ; then
if [ ! -d /vservers/$vserver/etc/yum.repos.d ] ; then
echo "WARNING : cannot create myplc repo"
else
[ $cap -eq 0 ] && echo 'CAP_NET_BIND_SERVICE' >> /etc/vservers/$vserver/bcapabilities
fi
+ # Set persistent for the network context
+ echo persistent,lback_allow > /etc/vservers/$vserver/nflags
+
+ # Set the init style of your vserver to plain for f13
+ if [ "$fcdistro" == "f13" ] ; then
+ echo plain > /etc/vservers/$vserver/apps/init/style
+ fi
+
if [ "$pkg_method" = "yum" ] ; then
$personality vyum $vserver -- -y install yum
# ditto
fi
# start the vserver so we can do the following operations
- $personality vserver $VERBOSE $vserver start
- [ "$pkg_method" = "yum" ] && $personality vserver $VERBOSE $vserver exec sh -c "rm -f /var/lib/rpm/__db*"
- [ "$pkg_method" = "yum" ] && $personality vserver $VERBOSE $vserver exec rpm --rebuilddb
+ # redirect out/err to protect against the vserver's init sequence getting stalled
+ # mostly used for f10 vservers created remotely through ssh
+ $personality vserver $VERBOSE $vserver start >& /dev/null
+
+ if [ "$pkg_method" == "yum" ] ; then
+ $personality vserver $VERBOSE $vserver exec sh -c "rm -f /var/lib/rpm/__db*"
+
+ # run the host rpmdb_dump and restore with the guest rpmdb_load
+ function translate_rpm_hashes () {
+ set -x
+ set -e
+ local personality="$1"; shift
+ local vserver="$1"; shift
+ # need to have utilities installed
+ type -p file
+ type -p awk
+ type -p cut
+ guest_dir=/var/lib/rpm
+ host_dir=/vservers/$vserver/$guest_dir
+ files=$(cd $host_dir ; file * | grep Hash | cut -d: -f 1)
+ for file in $files; do
+ (cd $host_dir && mv $file ${file}-foreign)
+ /usr/lib/rpm/rpmdb_dump $host_dir/${file}-foreign | $personality vserver $VERBOSE $vserver exec /usr/lib/rpm/rpmdb_load $guest_dir/$file
+ done
+ $personality vserver $VERBOSE $vserver exec rpm --rebuilddb
+ return 0
+ }
+
+ # try the simple way, if that fails try to cross fix the rpm hashes
+ $personality vserver $VERBOSE $vserver exec rpm --rebuilddb || translate_rpm_hashes $personality $vserver
+ fi
- # with vserver 2.3, granting the vserver CAP_MKNOD is not enough
- # check whether we run vs2.3 or above
- vs_version=$(uname -a | sed -e 's,.*[\.\-]vs\([0-9]\)\.\([0-9]\)\..*,\1\2,')
- # at this stage we have here 22 or 23
- need_vdevmap=$(( $vs_version >= 23 ))
+ # check if the vserver kernel is using VSERVER_DEVICE (vdevmap) support
+ need_vdevmap=$(grep "CONFIG_VSERVER_DEVICE=y" /boot/config-$(uname -r) | wc -l)
- if [ "$need_vdevmap" == 1 ] ; then
+ if [ $need_vdevmap -eq 1 ] ; then
ctx=$(cat /etc/vservers/$vserver/context)
vdevmap --set --xid $ctx --open --create --target /dev/null
vdevmap --set --xid $ctx --open --create --target /dev/root
cp /etc/resolv.conf /vservers/$vserver/etc/resolv.conf
# and /etc/hosts for at least localhost
[ -f /vservers/$vserver/etc/hosts ] || echo "127.0.0.1 localhost localhost.localdomain" > /vservers/$vserver/etc/hosts
+
}
function devel_or_vtest_tools () {
groups=$(pl_getGroups -a $vserver_arch $fcdistro $pldistro $pkgsfile)
[ "$pkg_method" = yum ] && [ -n "$packages" ] && $personality vserver $vserver exec yum -y install $packages
- [ "$pkg_method" = yum ] && [ -n "$groups" ] && $personality vserver $vserver exec yum -y groupinstall $groups
+ [ "$pkg_method" = yum ] && for group_plus in $groups; do
+ group=$(echo $group_plus | sed -e "s,+++, ,g")
+ $personality vserver $vserver exec yum -y groupinstall "$group"
+ done
[ "$pkg_method" = debootstrap ] && $personality vserver $vserver exec apt-get update
[ "$pkg_method" = debootstrap ] && for package in $packages ; do
echo "vserver-options"
echo " all args after the optional -- are passed to vserver <name> build <options>"
echo " typical usage is e.g. --interface eth0:200.150.100.10/24"
+ echo "With $COMMAND_MYPLC you can give 'none' as the URL, in which case"
+ echo " myplc.repo does not get created"
exit 1
}