Last active
April 19, 2016 09:29
-
-
Save 0xjac/513527f114d44c94c2b5d8c3255f41de to your computer and use it in GitHub Desktop.
acalab
This file contains hidden or 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
#!/usr/bin/env bash | |
HOSTNAME="aca-lab" | |
VMNAME="aca-lab" | |
HOST_PORT=3022 | |
SSH_PORT=22 | |
function cleanup { | |
# Poweroff the machine on exit or failure | |
VBoxManage controlvm "$VMNAME" poweroff | |
} | |
trap cleanup EXIT SIGINT SIGTERM | |
function config { | |
# Setup SSH port forwarding if not setup | |
VBoxManage showvminfo "$VMNAME" | grep -q \ | |
"Rule.*host\ port\ = $HOST_PORT.*guest\ port = $SSH_PORT"; | |
local port_unset=$?; | |
echo "Port: $port_unset" | |
if [[ $port_unset -eq 1 ]]; then | |
echo "Setting SSH port forwarding" | |
echo "VBoxManage modifyvm \"$VMNAME\" --natpf1 \"ssh,tcp,,$HOST_PORT,,$SSH_PORT\"" | |
VBoxManage modifyvm "$VMNAME" --natpf1 "ssh,tcp,,$HOST_PORT,,$SSH_PORT" | |
fi | |
} | |
function init { | |
# Start the VM | |
VBoxManage startvm "$VMNAME" --type headless; | |
local status=$? | |
if [ $status -ne 0 ]; then | |
echo "Failed to start the machine" >&2 | |
exit $status | |
else | |
echo "Booting up, this might take a while..." | |
fi | |
} | |
config; | |
init; | |
ssh $HOSTNAME |
This file contains hidden or 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
Host aca-lab | |
Hostname 127.0.0.1 | |
Port 3022 | |
User lab |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment