#/bin/sh # # A utility to take some of the manual labor out of the non-Vagrant # based chef-bcpc bringup procedure on VMs # echo "this is not working yet" exit # bash imports source ./virtualbox_env.sh setglobal UP = $[$VBM showvminfo bcpc-bootstrap | grep -i State] if [[ ! $UP =~ running ]] { # This just doesn't seem to work # $VBM modifyvm bcpc-bootstrap --nic1 bridged --bridgeadapter1 en0 $VBM startvm bcpc-bootstrap sleep 30 } else { echo "bcpc-bootstrap is running" } ./vm-to-cluster.sh bloomberg.com while read HOSTNAME MACADDR IPADDR ILOIPADDR DOMAIN ROLE { if [[ $HOSTNAME = "end" ]] { break; } if [[ "$HOSTNAME" = bcpc-bootstrap ]] { setglobal NATADDR = $IPADDR echo "bcpc-bootstrap is currently at (NAT) address $NATADDR" break } } < cluster.txt if [[ -z $NATADDR ]] { echo "Couldn't find the bootstrap node's IP address" exit 1 } else { for ATTEMPT in [A B C D E F G] { if [[ "$1" ]] { setglobal HOST = $1 } else { setglobal HOST = $NATADDR } if hash fping 2>/dev/null { setglobal UP = $[fping -aq $(HOST) | awk '{print $1}] } else { setglobal UP = $[ping -c 1 $(HOST) | grep ttl |cut -f4 -d" " | cut -f1 -d":] } if [[ -z "$UP" ]] { echo "VM is not up yet or is unreachable" if [[ $ATTEMPT = G ]] { echo "Maybe machine needs rework. Rerun this when it's up" exit 1 } sleep 5 } else { break } } setglobal SSHCOMMON = '"-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o VerifyHostKeyDNS=no'" setglobal SSHCMD = ""ssh $SSHCOMMON"" setglobal SCPCMD = ""scp $SSHCOMMON"" if hash sshpass 2>/dev/null { setglobal EDITED = $[sshpass -p ubuntu $SSHCMD -t ubuntu@$HOST "echo ubuntu | sudo -S grep 'Static interfaces' /etc/network/interfaces] echo "EDITED = $EDITED" } else { echo "please install sshpass" exit 1 } if [[ "$EDITED" =~ "Static interfaces" ]] { echo "interfaces file appears adjusted already" exit 0 } else { echo "copy interfaces file fragment..." sshpass -p ubuntu $SCPCMD -p "vm-eth.txt" "ubuntu@$HOST:/tmp" echo "add the network definitions" # can't simply cat file >> file when updating the interfaces, due to the permissions # rename does work to atomically replace the file sshpass -p ubuntu $SSHCMD -t ubuntu@$HOST "echo ubuntu | sudo -S cp -p /etc/network/interfaces /etc/network/interfaces.orig" sshpass -p ubuntu $SSHCMD -t ubuntu@$HOST "echo ubuntu | sudo -S cat /etc/network/interfaces /tmp/vm-eth.txt > /tmp/combined.txt" sshpass -p ubuntu $SSHCMD -t ubuntu@$HOST "echo ubuntu | sudo -S mv /tmp/combined.txt /etc/network/interfaces" echo "restart networking" sshpass -p ubuntu $SSHCMD -t ubuntu@$HOST "echo ubuntu | sudo -S service networking restart" } }