diff options
author | June McEnroe <june@causal.agency> | 2020-07-14 16:34:44 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-07-14 16:34:44 -0400 |
commit | 002a80a782c030c70414944c93f58d370eb81ed7 (patch) | |
tree | db626e48188f3a29149387d0cf1c5b83922daa6d | |
parent | Set span.irc to pre-wrap (diff) | |
download | scooper-002a80a782c030c70414944c93f58d370eb81ed7.tar.gz scooper-002a80a782c030c70414944c93f58d370eb81ed7.zip |
Allow setting things by env vars
-rw-r--r-- | scooper.1 | 35 | ||||
-rw-r--r-- | server.c | 23 |
2 files changed, 53 insertions, 5 deletions
diff --git a/scooper.1 b/scooper.1 index c00974a..0bd63b0 100644 --- a/scooper.1 +++ b/scooper.1 @@ -28,6 +28,11 @@ provides a CGI or FastCGI web interface for the .Xr litterbox 1 IRC log database. +To use FastCGI, +run +.Nm +under +.Xr kfcgi 8 . . .Pp The arguments are as follows: @@ -72,6 +77,36 @@ The path to the database. .El . +.Sh ENVIRONMENT +In addition to the standard CGI environment variables, +.Nm +reads the following: +.Pp +.Bl -tag -width "SCOOPER_STYLESHEET" -compact +.It Ev SCOOPER_DATABASE +The path to the +.Xr litterbox 1 +database. +.It Ev SCOOPER_GAP +Equivalent to +.Fl g . +.It Ev SCOOPER_LIMIT +Equivalent to +.Fl l . +.It Ev SCOOPER_OVERLAP +Equivalent to +.Fl o . +.It Ev SCOOPER_PUBLIC +Equivalent to +.Fl p . +.It Ev SCOOPER_RECENT +Equivalent to +.Fl r . +.It Ev SCOOPER_STYLESHEET +Equivalent to +.Fl s . +.El +. .Sh SEE ALSO .Xr kfcgi 8 , .Xr litterbox 1 diff --git a/server.c b/server.c index c384020..0ed1c9c 100644 --- a/server.c +++ b/server.c @@ -77,25 +77,38 @@ static enum kcgi_err dispatch(struct kreq *req) { } } +#define ENV "SCOOPER_" + int main(int argc, char *argv[]) { + const char *path = NULL; bool test = false; + const char *val; + if ((val = getenv(ENV "DATABASE"))) path = val; + if ((val = getenv(ENV "GAP"))) eventsGap = strtol(val, NULL, 10); + if ((val = getenv(ENV "LIMIT"))) eventsLimit = strtol(val, NULL, 10); + if ((val = getenv(ENV "OVERLAP"))) eventsOverlap = strtol(val, NULL, 10); + if ((val = getenv(ENV "PUBLIC"))) contextsPublic = (val[0] != '0'); + if ((val = getenv(ENV "RECENT"))) contextsRecent = strtol(val, NULL, 10); + if ((val = getenv(ENV "STYLESHEET"))) htmlStylesheet = val; + for (int opt; 0 < (opt = getopt(argc, argv, "cg:l:o:pr:s:"));) { switch (opt) { - break; case 'g': eventsGap = strtol(optarg, NULL, 10); - break; case 'o': eventsOverlap = strtol(optarg, NULL, 10); break; case 'c': test = true; + break; case 'g': eventsGap = strtol(optarg, NULL, 10); break; case 'l': eventsLimit = strtol(optarg, NULL, 10); + break; case 'o': eventsOverlap = strtol(optarg, NULL, 10); break; case 'p': contextsPublic = true; break; case 'r': contextsRecent = strtol(optarg, NULL, 10); break; case 's': htmlStylesheet = optarg; break; default: return EX_USAGE; } } - if (optind == argc) errx(EX_USAGE, "database path required"); + if (optind < argc) path = argv[optind]; + if (!path) errx(EX_USAGE, "database path required"); - int error = sqlite3_open_v2(argv[optind], &db, SQLITE_OPEN_READONLY, NULL); - if (error) errx(EX_NOINPUT, "%s: %s", argv[optind], sqlite3_errmsg(db)); + int error = sqlite3_open_v2(path, &db, SQLITE_OPEN_READONLY, NULL); + if (error) errx(EX_NOINPUT, "%s: %s", path, sqlite3_errmsg(db)); atexit(finalizeAll); sqlite3_stmt *check; |