#!/bin/bash

version="Cloud Messenger: cloudmsg v1.0"

usage="
$version

USAGE: $0 [OPTIONS] [MESSAGE]

-e EMAIL	Email address associated with your account.
-h			Prints out this help message.
-m MESSAGE	The message body. Default is 'Task Complete.'
-p PIN		The PIN number associated with your account. Default is 0000.
-t TITLE	Title for the message. Default is the system hostname.
-v			Version of this bash script.

"

url="http://cloud.phazor.ca/?"

# Default values
email=faizvisram@gmail.com
pin="0000"
title=`hostname`
msg="Task complete."

while getopts "e:hp:t:v" optname
  do
    case "$optname" in
      "e")
		title=$email
        ;;
      "h")
		echo $usage
		exit
        ;;
      "p")
		pin=$OPTARG
        ;;
      "t")
		title=$OPTARG
        ;;
      "v")
		echo $version
		exit
        ;;
      "?")
        echo "Unknown option $OPTARG"
        echo $usage
        exit
        ;;
      ":")
        echo "No argument value for option $OPTARG"
        echo $usage
        exit
        ;;
      *)
      # Should not occur
        echo "Invalid argument -$OPTARG"
        echo $usage
        exit
        ;;
    esac

    done

#msg=${@:$OPTIND}
#
#if [ -z $msg ]; then
#	msg="Task complete."
#fi

url="${url}email=${email}&pin=${pin}&title=${title}&message=${msg}"
wget -qO- "$url"

echo $url

exit
