Skip to content

Instantly share code, notes, and snippets.

@schmonz
Created June 12, 2018 10:01
Show Gist options
  • Save schmonz/342670f4465c8df49c21323819028718 to your computer and use it in GitHub Desktop.
Save schmonz/342670f4465c8df49c21323819028718 to your computer and use it in GitHub Desktop.
#!/bin/sh
vbox_is_running() {
count=$(VBoxManage showvminfo "$1" | grep -c 'running (since')
[ 0 -lt $count ]
}
vbox_start_if_needed() {
vbox_is_running "$1" || VBoxManage startvm "$1" --type headless
}
ssh_retry_until_success() {
false
until [ 0 -eq $? ]; do
sleep 1
ssh -q "$@" true || false
done
ssh -q "$@"
}
main() {
case "$1" in
centos6)
vbox_start_if_needed 'CentOS 6'
ssh_retry_until_success centos6
;;
centos7)
vbox_start_if_needed 'CentOS 7'
ssh_retry_until_success centos7
;;
netbsd7)
vbox_start_if_needed 'NetBSD 7'
ssh_retry_until_success netbsd7
;;
tribblix)
vbox_start_if_needed 'Tribblix'
ssh_retry_until_success tribblix
;;
*)
echo "unknown VM" >&2
exit 77
esac
}
main "$@"
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment