summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/winpopup/winpopup-send.sh
blob: 9a80b20b7e6d3f49f17fb5745d27cda9edd8bc54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/sh
PATH=/bin:/usr/bin/:/usr/local/bin

# Check input
[ -z "$1" -o -z "$2" ] && exit 1

# Check if file is indeed a file and readable
[ ! -f "$1" -o ! -r "$1" ] && exit 1

KOPETE_RUNNING=x`ps -A|grep -e "kopete$"`

if [ "$KOPETE_RUNNING" = "x" ]; then

    if [ -z "$3" ]; then
        THIS_SERVER=`uname -n`
    else
        THIS_SERVER="$3"
    fi

    if [ "$2" != "$THIS_SERVER" ]; then
        echo -e "Kopete is currently not running.\nYour message was not delivered!" \
            | smbclient -N -M $2
    fi

else

    # Create a unique filename
    filename="/var/lib/winpopup/`date +%s_%N`"

    # the time...
    TIME=`date --iso-8601=seconds`

    # the message
    MESSAGE=`cat "$1"`

    # Put it into the file
    echo -e "$2\n$TIME\n$MESSAGE" > $filename


fi

# Remove the message from samba
rm -f "$1"