From 4d30a3e98c2014dc68193a1886ce1e28f554fb29 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Wed, 26 Mar 2008 13:49:23 +0000 Subject: [PATCH] moved convenience function for detecting local IP from nightly to init-vserver - now the default for the latter --- vbuild-init-vserver.sh | 49 +++++++++++++++++++++++++++++++++++++++--- vbuild-nightly.sh | 33 ++-------------------------- 2 files changed, 48 insertions(+), 34 deletions(-) diff --git a/vbuild-init-vserver.sh b/vbuild-init-vserver.sh index 47122fb0..24d3bec0 100755 --- a/vbuild-init-vserver.sh +++ b/vbuild-init-vserver.sh @@ -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" @@ -296,8 +300,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 +340,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 build " @@ -333,11 +364,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 +397,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 diff --git a/vbuild-nightly.sh b/vbuild-nightly.sh index a50b9ac8..5e8d0a7d 100755 --- a/vbuild-nightly.sh +++ b/vbuild-nightly.sh @@ -117,34 +117,6 @@ function success () { exit 0 } -# 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 -} - # run in the vserver - do not manage success/failure, will be done from the root ctx function build () { set -x @@ -251,7 +223,7 @@ function usage () { echo " -m mailto" echo " -a makevar=value - space in values are not supported" echo " -w webpath - defaults to $DEFAULT_WEBPATH" - echo " -i ifname - defaults to $DEFAULT_IFNAME - set to e.g. eth0 for non-local mirrors" + echo " -i ifname - defaults to $DEFAULT_IFNAME - used to determine local IP" echo " -B : run build only" echo " -T : run test only" echo " -x testsvnpath - defaults to $DEFAULT_TESTSVNPATH" @@ -373,8 +345,7 @@ function main () { svn export $SVNPATH $tmpdir # Create vserver cd $tmpdir - localip=$(vserverIfconfig $IFNAME) - ./vbuild-init-vserver.sh -f ${FCDISTRO} -d ${PLDISTRO} -p ${PERSONALITY} ${BASE} -- --interface $localip + ./vbuild-init-vserver.sh -f ${FCDISTRO} -d ${PLDISTRO} -p ${PERSONALITY} -i ${IFNAME} ${BASE} -- --interface $localip # cleanup cd - rm -rf $tmpdir -- 2.43.0