monitors the branches for 4.2 only
[build.git] / vbuild-init-vserver.sh
index dcfc15e..2556087 100755 (executable)
@@ -10,6 +10,10 @@ PATH=$(dirname $0):$PATH . build.common
 DEFAULT_FCDISTRO=f8
 DEFAULT_PLDISTRO=planetlab
 DEFAULT_PERSONALITY=linux32
+DEFAULT_IFNAME=eth0
+
+COMMAND_VBUILD="vbuild-init-vserver.sh"
+COMMAND_MYPLC="vtest-init-vserver.sh"
 
 function failure () {
     echo "$COMMAND : Bailing out"
@@ -89,10 +93,10 @@ function setup_vserver () {
     # try to work around the vserver issue:
     # vc_ctx_migrate: No such process
     # rpm-fake.so: failed to initialize communication with resolver
-    for i in 1 2 3 4 5 ; do
+    for i in $(seq 20) ; do
        $personality vserver $VERBOSE $vserver build $VSERVER_OPTIONS -m yum -- -d $fcdistro && break || true
-       echo "Waiting for 30 seconds"
-       sleep 30
+       echo "* ${i}-th attempt to 'vserver build' failed - waiting for 3 seconds"
+       sleep 3
     done
     # check success
     [ -d /vservers/$vserver ] 
@@ -130,10 +134,10 @@ function setup_vserver () {
 
     $personality vyum $vserver -- -y install yum
     # ditto
-    for i in 1 2 3 4 5 ; do
+    for i in $(seq 20) ; do
        $personality vserver $VERBOSE $vserver pkgmgmt internalize && break || true
-       echo "Waiting for 30 seconds"
-       sleep 30
+       echo "* ${i}-th attempt to 'vserver pkgmgmt internalize' failed - waiting for 3 seconds"
+       sleep 3
     done
 
     # start the vserver so we can do the following operations
@@ -212,6 +216,9 @@ function post_install () {
     else
        post_install_myplc "$@"
     fi
+    # setup localtime from the host
+    vserver=$1; shift 
+    cp /etc/localtime /vservers/$vserver/etc/localtime
 }
 
 function post_install_vbuild () {
@@ -296,8 +303,34 @@ PROFILE
 EOF
 }
 
-COMMAND_VBUILD="vbuild-init-vserver.sh"
-COMMAND_MYPLC="vtest-init-vserver.sh"
+# parses ifconfig's output to find out ip address and mask
+# will then be passed to vserver as e.g. --interface 138.96.250.126/255.255.0.0
+# default is to use lo, that's enough for local mirrors
+# use -i eth0 in case your fedora mirror is on a separate box on the network
+function vserverIfconfig () {
+    ifname=$1; shift
+    local result="" 
+    line=$(ifconfig $ifname 2> /dev/null | grep 'inet addr')
+    if [ -n "$line" ] ; then
+       set $line
+       for word in "$@" ; do
+           addr=$(echo $word | sed -e s,[aA][dD][dD][rR]:,,)
+           mask=$(echo $word | sed -e s,[mM][aA][sS][kK]:,,)
+           if [ "$word" != "$addr" ] ; then
+               result="${addr}"
+           elif [ "$word" != "$mask" ] ; then
+               result="${result}/${mask}"
+           fi
+       done
+    fi
+    if [ -z "$result" ] ; then 
+       echo "vserverIfconfig failed to locate $ifname"
+       exit 1
+    else
+       echo $result
+    fi
+}
+
 function usage () {
     set +x 
     echo "Usage: $COMMAND_VBUILD [options] vserver-name [ -- vserver-options ]"
@@ -310,6 +343,7 @@ function usage () {
     echo " -f fcdistro - for creating the root filesystem - defaults to $DEFAULT_FCDISTRO"
     echo " -d pldistro - defaults to $DEFAULT_PLDISTRO"
     echo " -p personality - defaults to $DEFAULT_PERSONALITY"
+    echo " -i ifname: determines ip and netmask attached to ifname, and passes it to the vserver"
     echo " -v : verbose - passes -v to calls to vserver"
     echo "vserver-options"
     echo "  all args after the optional -- are passed to vserver <name> build <options>"
@@ -333,11 +367,14 @@ function main () {
     esac
 
     VERBOSE=
-    while getopts "f:d:p:v" opt ; do
+    IFNAME=""
+    VSERVER_OPTIONS=""
+    while getopts "f:d:p:i:v" opt ; do
        case $opt in
            f) fcdistro=$OPTARG;;
            d) pldistro=$OPTARG;;
            p) personality=$OPTARG;;
+           i) IFNAME=$OPTARG;;
            v) VERBOSE="-v" ;;
            *) usage ;;
        esac
@@ -363,6 +400,15 @@ function main () {
        fi
     fi
 
+    # with new util-vserver, it is mandatory to provide an IP even for building
+    if [ -n "$VBUILD_MODE" ] ; then
+       [ -z "$IFNAME" ] && IFNAME=$DEFAULT_IFNAME
+    fi
+    if [ -n "$IFNAME" ] ; then
+       localip=$(vserverIfconfig $IFNAME)
+       VSERVER_OPTIONS="$VSERVER_OPTIONS --interface $localip"
+    fi
+
     [ -z "$fcdistro" ] && fcdistro=$DEFAULT_FCDISTRO
     [ -z "$pldistro" ] && pldistro=$DEFAULT_PLDISTRO
     [ -z "$personality" ] && personality=$DEFAULT_PERSONALITY