]> git.armaanb.net Git - bin.git/blob - scoop-cgi
rss: implement parallel downloads
[bin.git] / scoop-cgi
1 #!/usr/bin/env sh
2 # CGI script to get irc logs from scoop. Powers https://irclogs.armaanb.net.
3
4 channel=$(echo "$PATH_INFO" | awk -F / '{print $2}')
5 if [ -z "$channel" ]; then
6                 echo "Content-type: text/plain
7
8 =================
9 acheam's IRC logs
10 =================
11
12 logged channels
13 ---------------
14 $(awk '{print "  * " $0}' /etc/scoop-cgi/channels)
15 $(awk '{print "  * " $0}' /etc/scoop-cgi/logbot)
16
17 url format
18 ----------
19 /channel/date
20 date is optional, and defaults to the current day
21
22 source
23 ------
24 https://git.armaanb.net/bin/tree/scoop-cgi
25 it's in the public domain!"
26                 exit 0
27 fi
28
29 time=$(echo "$PATH_INFO" | awk -F / -v date="$(date -I)" '
30 {($3 != "" ) ? outp = $3 : outp = date; print outp}' | xargs date -I -d)
31
32 all=$(cat /etc/scoop-cgi/channels /etc/scoop-cgi/logbot)
33 channel=$(echo "$all" | grep -x "$channel")
34 if [ -z "$channel" ]; then
35                 echo "Status: 404"
36                 printf "Content-type: text/plain\n\n"
37                 echo "404. Channel not logged."
38                 exit 0
39 fi
40
41 printf "Content-type: text/plain\n\n"
42
43 if grep -qx "$channel" /etc/scoop-cgi/channels; then
44                 db=$(cat /etc/scoop-cgi/database)
45                 PAGER=/dev/tty scoop -d "$db" -p "$channel" -D "$time" \
46                                  -F "%Y-%m-%d %H:%M:%S" \
47                                 | awk '{$1=""; print substr($0, 2, length($0) - 1)}'
48 elif grep -qx "$channel" /etc/scoop-cgi/logbot; then
49                 awk -v date="$time" 'substr($1, 0, 11) == date {outp = substr($1, 12);
50 for (i = 3; i <= NF; i++) outp = outp " " $i; print outp}' \
51                                 "/srv/www/scoop-cgi/$channel"
52 fi