Files

43 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
BCBODY=`cat`
function die_err() {
echo "$0: $*" >&2
exit 1
}
OldPWD=$(pwd)
BaseDir=$(git rev-parse --show-toplevel)
cd "$BaseDir" || exit 1
CURLCRED="vnctalk:ohtai2Eicai4aiting7bec2am6Aih"
if [ -f "tools/broadcast.cfg" ]; then
echo "found config"
else
cd "$OldPWD" || exit 1
die_err "no broadcst config - bailing out"
fi
RECEIPIENTS=$(cat tools/broadcast.cfg | grep "^BCRECEIPIENTS" | awk -F "=" '{print $2}' | tr ',' '\n' | awk '{print "<to>" $0 "</to>"}' | sed 's/ //g' | grep -v "<to></to>");
BROADCASTSENDER=$(cat tools/broadcast.cfg | grep "^BROADCASTSENDER" | awk -F "=" '{print $2}');
BROADCASTID=$(cat tools/broadcast.cfg | grep "^BROADCASTID" | awk -F "=" '{print $2}');
BCTITLE=$(cat tools/broadcast.cfg | grep "^BCTITLE" | awk -F "=" '{print $2}');
MSGID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
BCRESTURL=$(cat tools/broadcast.cfg | grep "^BCRESTURL" | awk -F "=" '{print $2}');
echo "<message xmlns=\"jabber:client\" type=\"normal\" id=\"$MSGID\" to=\"$BROADCASTID\" from=\"$BROADCASTSENDER\">" > "/tmp/$MSGID.xml"
echo "<body>$BCBODY</body>" >> "/tmp/$MSGID.xml"
echo "<vncTalkBroadcast xmlns=\"xmpp:vnctalk\" title=\"$BCTITLE\">" >> "/tmp/$MSGID.xml"
echo "$RECEIPIENTS" >> "/tmp/$MSGID.xml"
echo " </vncTalkBroadcast>
</message>" >> "/tmp/$MSGID.xml"
echo "raw message:"
cat "/tmp/$MSGID.xml"
curl -u "$CURLCRED" -H "Content-Type: text/xml" -X POST --data-binary "@/tmp/$MSGID.xml" "$BCRESTURL"