clouds/aws/pentest-ec2-manager/ec2-utils.sh
#!/bin/bash

EC2_NAME=pentestec2

#
# Will set the following aliases:
#   - ssh<vm> alias for quick ssh-connection
#   - get<vm> alias for quick vm's ip resolution
#   - start<vm> alias for starting up particular vm
#   - stop<vm> alias for stopping particular vm
#   - is<vm> alias for checking whether the vm is running.
#
# For instance, when EC2_NAME=pentestec2 - the following aliases will be defined:
#   sshpentestec2, getpentestec2, ispentestec2, and so on...
#
function setup_aliases() {
  name=${EC2_NAME,,}
  if [ -z $name ]; then
    echo "[!] You must set the EC2_NAME variable within that script first!"
    return 1
  fi

  alias start$name="startec2"
  alias stop$name="stopec2"
  alias terminate$name="terminateec2"
  alias ssh$name="sshec2"
  alias get$name="getec2"
  alias check$name="checkec2"
}

function startec2() {
  ruby ./aws-manager.rb "$@" start $EC2_NAME
}

function stopec2() {
  ruby ./aws-manager.rb "$@" stop $EC2_NAME
}

function terminateec2() {
  ruby ./aws-manager.rb "$@" terminate $EC2_NAME
}

function sshec2() {
  ruby ./aws-manager.rb "$@" ssh $EC2_NAME
}

function getec2() {
  ruby ./aws-manager.rb "$@" address $EC2_NAME
}

function checkec2() {
  ruby ./aws-manager.rb "$@" status $EC2_NAME
}

setup_aliases
