67 lines
1.6 KiB
Bash
Executable File
67 lines
1.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# File: ravensend
|
|
#
|
|
# Description: This file sends a message to the Raven API
|
|
#
|
|
# Package: AniNIX/ravensend
|
|
# Copyright: WTFPL
|
|
#
|
|
# Author: DarkFeather <ircs://aninix.net:6697/DarkFeather>
|
|
|
|
# Default variables
|
|
unset channel
|
|
unset message
|
|
unset passphrase
|
|
export file="/usr/local/etc/TheRaven/raven.conf"
|
|
unset port
|
|
export host="localhost"
|
|
|
|
# Show help
|
|
function usage() {
|
|
echo "Usage: $0 -c chan -m msg [ -f file -t host -p port ]"
|
|
echo " $0 -h" echo "Add -v to increase verbosity"
|
|
echo "Passphrase is pulled from Raven config, set to ${file}"
|
|
}
|
|
|
|
function getAPIConfigValue() {
|
|
# Get the api config value
|
|
# param attr: the attribute to look for
|
|
# returns: the attribute's value
|
|
egrep -A 10 '^\[ API \]$' "$file" | egrep -m 1 '^'"$1"'=' | sed 's/^'"$1"'=//'
|
|
}
|
|
|
|
# Parse arguments
|
|
while getopts 'c:f:hm:p:t:v' OPTION; do
|
|
case "$OPTION" in
|
|
c) channel="${OPTARG}" ;;
|
|
f) file="${OPTARG}" ;;
|
|
h) usage; exit 0 ;;
|
|
m) message="${OPTARG}" ;;
|
|
p) port="${OPTARG}" ;;
|
|
t) host="${OPTARG}" ;;
|
|
v) set -x ;;
|
|
*) usage; exit 1 ;;
|
|
esac
|
|
done
|
|
if [ -z "$port" ]; then
|
|
port="$(getAPIConfigValue port)"
|
|
fi
|
|
|
|
# Check inputs.
|
|
if [ -z "$channel" ] || [ -z "$message" ] || [ -z "$file" ] || [ -z "$port" ] || [ -z "$host" ]; then
|
|
usage;
|
|
exit 1;
|
|
fi
|
|
|
|
# Try to get the passphrase.
|
|
passphrase="$(getAPIConfigValue password)"
|
|
if [ -z "$passphrase" ]; then
|
|
echo Couldn\'t identify passphrase.
|
|
exit 2;
|
|
fi
|
|
|
|
|
|
# Send format to socket
|
|
printf "%s %s %s" "$passphrase" "$channel" "$message" | ncat "$host" "$port"
|