#!/bin/bash # # Quick script to take snapshots after OS build. # TODO: Rewrite me in ruby... the whole thing. hash -r proc wait_for_ssh{ local hostname="$1" local min=$(2:-1) max=$(3:-10) if test -z $(hostname) { return 1 ; } exec !3 > !2 exec !2 >/dev/null while true { if echo > /dev/tcp/$(hostname)/22 { return 0 } sleep $shExpr(' $RANDOM % $max + $min ') } exec !2 > !3 exec !3 > !- } proc wait_for_snapshot{ local ip="$1" if test -z $(ip) { return 1 } local vmname="$[ip_to_name $(ip)]" || return 2 echo "Waiting to snapshot $(vmname) at $(ip)..." wait_for_ssh $(ip) VBoxManage snapshot $(vmname) take build_completed --description "Base OS installed" } # This is highly presumptive proc ip_to_name{ if test -z $1 { return 1 ; } local l="$(1##*.)" setglobal l = $shExpr('l-10') echo "bcpc-vm$(l)" } for ip in []10.0.100.{11..13} { eval "wait_for_snapshot $(ip) &" ; } wait