#!/bin/bash set -e # bash imports source ./virtualbox_env.sh if ! hash vagrant !2 >/dev/null { if [[ -z "$1" ]] { # only if vagrant not available do we need the param echo "Usage: $0 (start)" exit } } if [[ -n "$2" ]] { if [[ "$2" =~ start ]] { setglobal STARTVM = 'true' } } if test -f ./proxy_setup.sh { source ./proxy_setup.sh } if test -z $CURL { echo "CURL is not defined" exit } setglobal DIR = "$[dirname $0]/vbox" pushd $DIR setglobal KEYFILE = 'bootstrap_chef.id_rsa' setglobal subnet = '10.0.100' setglobal node = '11' setglobal SSHCOMMON = '"-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o VerifyHostKeyDNS=no'" setglobal SSHCMD = ""ssh $SSHCOMMON"" for i in [bcpc-vm1 bcpc-vm2 bcpc-vm3] { setglobal MAC = $[$VBM showvminfo --machinereadable $i | grep macaddress1 | cut -d '"' -f 2 | sed 's/.\{2\}/&:/g;s/:$//] if test -z $MAC { echo "***ERROR: Unable to get MAC address for $i" exit 1 } echo "Registering $i with $MAC for $(subnet).$(node)" read -d %% REGISTERCMD << """ ip=$(subnet).$(node) ; read _ _ dev _ < <(ip route get '$'ip) || { echo "Could not determine device." >&2 ; exit 2 ; } ; sudo cobbler system remove --name="$i" ; sudo cobbler system add --name="$i" --hostname="$i" --profile=bcpc_host --ip-address=$(subnet).$(node) '\' --mac="$(MAC)" --interface='$'{dev} %% """ if hash vagrant !2 >/dev/null { vagrant ssh -c $REGISTERCMD } else { if hash sshpass !2 >/dev/null { echo ubuntu | sshpass -p ubuntu $SSHCMD -tt ubuntu@$1 $REGISTERCMD } else { ssh -t -i $KEYFILE ubuntu@$1 $REGISTERCMD } } let node=node+1 } setglobal SYNCCMD = '"sudo cobbler sync'" if hash vagrant !2 >/dev/null { vagrant ssh -c $SYNCCMD } else { if hash sshpass !2 >/dev/null { echo ubuntu | sshpass -p ubuntu $SSHCMD -tt ubuntu@$1 $SYNCCMD } else { ssh -t -i $KEYFILE ubuntu@$1 $SYNCCMD } } if [[ -n "$STARTVM" ]] { for i in [bcpc-vm1 bcpc-vm2 bcpc-vm3] { VBoxManage startvm $i } }