about summary refs log tree commit diff
path: root/modules/server/owncast-integration/hook.cgi.sh
blob: a11891a384bce581c10772a688793397ae87bc7c (plain) (blame)
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
#!/bin/sh -e

echo "Content-Type:text/plain"

if [ "$REQUEST_METHOD" != POST ]; then
    echo "Status:405 Method Not Allowed"
    echo
    exit
fi

# case and printenv are used here to ensure there isn't a test
# subprocess with the secret visible in its argv.
case "$(printenv HTTP_AUTHORIZATION | sed -n 's/^basic //ip' | base64 -d)" in
    "$(cat -- "$CREDENTIALS_DIRECTORY/owncast-inbound")")
	;;
    *)
	echo "Status:401 Unauthorized"
	echo
	exit
	;;
esac

echo "Status:204 No Content"
echo

if [ "$(jq -r .type)" = STREAM_STARTED ]; then
    nc -N ::1 18770 <<EOF
📺 Development stream started on https://live.qyliss.net/!
EOF

    (
	sleep 3600
	(
	    printf "Authorization: Bearer "
	    cat -- "$CREDENTIALS_DIRECTORY/owncast-outbound"
	) | curl -sSH @- \
		 --json '{"body":"My work is mostly funded through individual donations.  Please consider supporting development of Spectrum and related projects via https://github.com/sponsors/alyssais or https://liberapay.com/qyliss.  Thank you!"}' \
		 --fail-with-body \
		 https://live.qyliss.net/api/integrations/chat/system
    ) &
fi