1#!/bin/sh
2die() {	echo >&2 "$@"; exit 1; }
3notfound() { echo >&2 "$SOCKET not found, sending to the '$1'."; SOCKET=$SERVERBASE/$1/var/run/socket; }
4
5[ $# -ge 1 ] || die "Syntax: $0 <server version> [<message>]"
6
7SERVER=$1
8SERVERBASE=$HOME/servers/$SERVER
9SOCKET=$SERVERBASE/build/var/run/socket
10
11[ -d "$SERVERBASE" ] || die "Server '$SERVER' not found."
12shift
13if [ "$*" = "" ]; then
14	message="The server will get restarted now. Please don't forget to save your game!"
15	echo "Sending standard message: $message"
16else
17	message=$*
18fi
19
20[ -e $SOCKET ] || { notfound oldbuild; [ -e $SOCKET ] || notfound revertedbuild; }
21[ -p $SOCKET ] || die "$SOCKET is not a named pipe (fifo).
22Is the $SERVER server running?"
23
24echo "msg $message" > $SOCKET
25