This repository has no description
1.2 kB
57 lines
1#!/bin/sh
2# needs in path:
3# curl gnugrep jq
4# creates and manages $PWD/state
5set -xeuf
6
7send_reaktor(){
8 # usage: send_reaktor "text"
9 echo "send_reaktor: $1"
10 curl -fsS "http://localhost:$REAKTOR_PORT" \
11 -H content-type:application/json \
12 -d "$(jq -n \
13 --arg text "$1" \
14 --arg channel "$IRC_CHANNEL" \
15 '{
16 command:"PRIVMSG",
17 params:[$channel,$text]
18 }'
19 )"
20}
21
22live=$(shuf -n1 <<EOF
23Binärgewitter Liveshow hat begonnen! http://stream.radiotux.de:8000/binaergewitter.mp3
24EOF
25)
26
27offline=$(shuf -n1 <<EOF
28Live stream vorbei
29EOF
30)
31error=$(shuf -n1 <<EOF
32something went wrong
33EOF
34)
35
36if curl -Ss http://stream.radiotux.de:8000 | grep -q 'Mount Point /binaergewitter'; then
37 state='live'
38else
39 state='offline'
40fi
41prevstate=$(cat state ||:)
42
43if test "$state" = "$(cat state)";then
44 #echo "current and last state is the same ($state), doing nothing"
45 :
46else
47 echo "API state and last state differ ( '$state' != '$prevstate')"
48 if test "$state" = 'live';then
49 send_reaktor "$live"
50 elif test "$state" = 'offline';then
51 send_reaktor "$offline"
52 else
53 send_reaktor "$error"
54 fi
55 echo 'updating state'
56 printf "%s" "$state" > state
57fi