review usage
[build.git] / vbuild-init-vserver.sh
index cc7b10b..90a3f41 100755 (executable)
@@ -27,7 +27,7 @@ function configure_yum_in_vserver () {
     vserver=$1; shift
     fcdistro=$1; shift
 
-    cd /etc/vservers/.distributions/${fcdistro}
+    pushd /etc/vservers/.distributions/${fcdistro}
     if [ -f yum/yum.conf ] ; then
        echo "Initializing yum.conf in $vserver from $(pwd)/yum"
         sed -e "s!@YUMETCDIR@!/etc!g;
@@ -67,7 +67,7 @@ gpgcheck=0
 EOF
        fi
     fi
-    cd -
+    popd
 }    
 
 function setup_vserver () {
@@ -141,11 +141,41 @@ function setup_vserver () {
     $personality vserver $VERBOSE $vserver exec sh -c "rm -f /var/lib/rpm/__db*"
     $personality vserver $VERBOSE $vserver exec rpm --rebuilddb
 
+    # 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 ))
+
+    if [ "$need_vdevmap" == 1 ] ; then
+       util_vserver_215=0
+       vdevmap --help | grep -- --set &> /dev/null && util_vserver_215=1
+       
+       if [ "$util_vserver_215" == 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
+       else
+           echo "You seem to be running vs2.3 with util-vserver < 0.30.215"
+           echo "This combination is not supported by $COMMAND"
+           echo "Please upgrade your environment"
+           exit 1
+# this supposedly is an equivalent to using vdevmap as invoked above
+# but it's not going to work in this case
+#          mkdir -p /etc/vservers/$vserver/apps/vdevmap/default-{block,char}
+#          touch /etc/vservers/$vserver/apps/vdevmap/default-{block,char}/{open,create}
+#          echo /dev/root > /etc/vservers/$vserver/apps/vdevmap/default-block/target
+#          echo /dev/null > /etc/vservers/$vserver/apps/vdevmap/default-char/target
+       fi
+    fi
+           
     # minimal config in the vserver for yum to work
     configure_yum_in_vserver $vserver $fcdistro 
 
     # set up resolv.conf
     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 () {