Last active
October 29, 2015 13:07
-
-
Save felixhummel/82bd60575f148f840f03 to your computer and use it in GitHub Desktop.
~/bin/labbox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
vmname=$1 | |
PROXY=dns | |
DOMAIN=lab | |
vboxmanage clonevm node --snapshot cleanup --options link --name $vmname --register | |
vboxmanage guestproperty set $vmname hostname $vmname | |
vboxmanage guestproperty set $vmname hostname $vmname | |
# check if $PROXY is already running | |
vboxmanage list runningvms | grep $PROXY | |
vboxmanage startvm $vmname --type headless | |
fqdn=${vmname}.${DOMAIN} | |
cat <<EOF >> ~/.ssh/config | |
Host $vmname | |
Hostname $fqdn | |
User root | |
ForwardAgent yes | |
ProxyCommand ssh -qW %h:%p $PROXY | |
EOF | |
# add host key to OUR known_hosts | |
keyscan_timeout=30 # seconds | |
host_key='' | |
echo "Waiting for SSH to come up" | |
while [[ -z $host_key ]]; do | |
host_key=$(ssh $PROXY "ssh-keyscan -T $keyscan_timeout -H $fqdn 2>/dev/null" || echo '') | |
echo -n . | |
sleep 1 | |
done | |
echo # newline | |
echo $host_key >> ~/.ssh/known_hosts | |
echo OK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment