#!/bin/sh

if type remctl >/dev/null 2>/dev/null; then
  remctl=remctl
else
  remctl="athrun remctl remctl"
fi

case $# in
  0)
    echo "Your VMs are:"
    echo "I dunno, we haven't exposed this to remctl yet" ;;
  1)
    if [ "$1" = "--help" ]; then
      cat << EOF
This is a silly wrapper around the remctl command.
Commands are:
  $0                    - lists all VMs you can access
  $0 <vm>               - lists status of the VM named <vm>
  $0 <vm> start         - boots up the VM (alias: create)
  $0 <vm> stop          - sends a shutdown request (alias: shutdown)
  $0 <vm> force-stop    - immediately powers down the VM (alias: destroy)
  $0 <vm> force-restart - runs force-stop and then start (alias: reboot)
EOF
    else
      $remctl remote.mit.edu control $1 list
      $remctl remote.mit.edu control $1 uptime
    fi ;;
  2)
    case "$2" in
      start|create)
        $remctl remote.mit.edu control "$1" create ;;
      stop|shutdown)
        $remctl remote.mit.edu control "$1" shutdown ;;
      force-stop|destroy)
        $remctl remote.mit.edu control "$1" destroy ;;
      force-restart|reboot)
        $remctl remote.mit.edu control "$1" reboot ;;
      *)
        echo "usage: $0 <vm> [start|stop|force-stop]" ;;
    esac ;;

  *)
    echo "usage: $0 <vm> [command]" ;;
esac
