]> git.armaanb.net Git - bin.git/commitdiff
scoop-cgi: add script. prints irc logs from scoop
authorArmaan Bhojwani <me@armaanb.net>
Sat, 29 May 2021 22:03:18 +0000 (18:03 -0400)
committerArmaan Bhojwani <me@armaanb.net>
Sun, 30 May 2021 04:43:47 +0000 (00:43 -0400)
scoop-cgi [new file with mode: 0755]

diff --git a/scoop-cgi b/scoop-cgi
new file mode 100755 (executable)
index 0000000..3b2aef5
--- /dev/null
+++ b/scoop-cgi
@@ -0,0 +1,28 @@
+#!/usr/bin/env sh
+# CGI script to get irc logs from scoop. Powers https://logs.armaanb.net.
+
+channel=$(echo "$PATH_INFO" | awk -F / '{print $2}')
+if [ -z "$channel" ]; then
+               echo "Content-type: text/plain\n"
+               echo "Logged channels:"
+               cat /etc/scoop-cgi/channels
+               echo "
+url format: /channel/date
+date is optional, and defaults to the current day"
+               exit 0
+fi
+
+channel=$(grep -x "$channel" /etc/scoop-cgi/channels)
+if [ -z "$channel" ]; then
+               echo "Status: 404"
+               echo "Content-type: text/plain\n"
+               echo "404. Channel not logged."
+               exit 0
+fi
+
+time=$(echo "$PATH_INFO" | awk -F / '{print $3}' | xargs date -I -d)
+db=$(cat /etc/scoop-cgi/database)
+
+echo "Content-type: text/plain\n"
+scoop -d "$db" -p "$channel" -D "${time:-now}" -F "%Y-%m-%d %H:%M:%S" \
+               | awk '{$1=""; print substr($0, 2, length($0) - 1)}'