Last active
April 19, 2016 09:29
-
-
Save 0xjac/513527f114d44c94c2b5d8c3255f41de to your computer and use it in GitHub Desktop.
Revisions
-
0xjac revised this gist
Apr 19, 2016 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ Host aca-lab Hostname 127.0.0.1 Port 3022 User lab -
0xjac created this gist
Apr 19, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ #!/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