#!/bin/bash # Configures this VM to be be node Y in topology X # # Example usage (on guest): # vn-deploynode 3 2 # deploys node 2 in topology 3 # # A third option is available to change the virtual network IP # address range from 192.168 to whatever is specified, e.g.: # vn-deploynode 3 2 10.173 # deploys node 2 in topology 3 with addresses being 10.173.x.y # instead of 192.168.x.y. # For more info see: http://sandilands.info/sgordon/virtnet # # $Revision$ # $Author$ # $Date$ # $URL$ # Input parameters # topology topology=`echo $1 | sed 's/^0*//'` # node number nodenum=`echo $2 | sed 's/^0*//'` # Add leading 0's where necessary if [ ${topology} -lt 10 ]; then topology="0${topology}" fi if [ ${nodenum} -lt 10 ]; then nodenum="0${nodenum}" fi echo ${topology} node=`echo ${nodenum} | sed 's/^0*//'` # Set the hostname sudo bash /home/network/virtnet/bin/vn-sethostname base node${node} # Copy interfaces sudo cp /home/network/virtnet/data/topologies/interfaces-topology-${topology}-node-${nodenum} /etc/network/interfaces # If a 3rd parameter is passed, use it to change the network mask if [ -n "$3" ]; then ip1=`echo $3 | cut -d . -f 1` ip2=`echo $3 | cut -d . -f 2` if [ ${ip1} -lt 255 -a ${ip2} -lt 255 ]; then sudo sed -i 's/192\.168\./'${3}'\./g' /etc/network/interfaces fi fi # Count the number of interfaces numif=`grep "iface eth" /home/network/virtnet/data/topologies/interfaces-topology-${topology}-node-${nodenum} | grep -v "#iface eth" | grep -c "static"` # If more than 1 interface, then enable router if [ ${numif} -gt 1 ]; then sudo sed -i 's/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/' /etc/sysctl.conf fi # Message for user to reboot echo "You should now reboot by typing:" echo " sudo reboot"