#!/bin/bash
# Usage: slackpost "<username>" "<message>"
# ------------
webhook_url=$SLACKHOOK
channel=$SLACKCHANNEL

username=$1
if [[ $username == "" ]]
then
    echo "No username specified"
    exit 1
fi

# ------------
shift

text=$*
if [[ $text == "" ]]
then
    echo "No text specified"
    exit 1
fi

escapedText=$(echo $text | sed 's/"/\"/g' | sed "s/'/\'/g" )
json="{\"channel\": \"$channel\", \"username\":\"$username\", \"icon_emoji\":\"ghost\", \"attachments\":[{\"color\":\"danger\" , \"text\": \"$escapedText\"}]}"
curl -s -d "payload=$json" "$webhook_url"
