Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ jobs:
- run: sudo sh rei/tests/test_gateway.sh unready rei/reiwimsy
- run: sudo sh rei/tests/test_gateway.sh stalled rei/reiwimsy
- run: sudo sh rei/tests/test_gateway.sh fix-cards rei/reiwimsy
- run: sudo sh rei/tests/test_gateway.sh both rei/reiwimsy
- run: sudo sh rei/tests/test_gateway.sh tracer tracer/tracer
- run: sudo sh rei/tests/test_gateway.sh tracer-all tracer/tracer
- run: sudo sh rei/tests/test_gateway.sh tracer-zombie tracer/tracer
Expand Down
27 changes: 17 additions & 10 deletions dist/freebsd/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,30 @@ done

# The programs, built and tested from a copy, so the checkout keeps no objects
cp -R "$top/rei" "$top/accordwimsy" "$top/tracer" "$work/"
(cd "$work/rei" && make -s clean && make -s test && make -s CONCORD="$work/concord-prefix")
(cd "$work/accordwimsy" && make -s clean && make -s test)
# its log summary demangles through the C++ runtime, libc++'s in base
# Tracer's log summary demangles through the C++ runtime, libc++'s in base; reiwimsy runs Tracer too
(cd "$work/tracer" && make -s clean && make -s test CXXRT=-lc++ && make -s CONCORD="$work/concord-prefix" CXXRT=-lc++)
(cd "$work/rei" && make -s clean && make -s test && make -s CONCORD="$work/concord-prefix" CXXRT=-lc++)

# Tracer's site files (the pieces each start copies into its site, and the themes), as a package installs them under
# share/<folder>: the tracer package's, and reiwimsy's own, so that each works alone in a jail
site_files() {
install -d "$1"
install -m 644 "$work/tracer/site/style.css" "$work/tracer/site/site.js" "$work/tracer/site/tracer.svg" "$1/"
sh "$top/scripts/tracer-themes.sh" "$1/sws" "$top"
chmod 644 "$1/sws/"*
}

s=$work/stage/reiwimsy/usr/local
install -d "$s/libexec" "$s/etc/rc.d"
install -m 755 "$work/rei/reiwimsy" "$s/libexec/reiwimsy"
install -m 555 "$here/reiwimsy.rc" "$s/etc/rc.d/reiwimsy"
install -m 644 "$here/reiwimsy.env.sample" "$s/etc/reiwimsy.env.sample"
# an assignment: a dependency missing stops the script, which an argument's $(...) would not
rdeps=$(deps curl ca_root_nss)
package reiwimsy "ScarletNX's Discord bot: links issues and pull requests, keeps cards" net-im/reiwimsy "$rdeps"
site_files "$s/share/reiwimsy/tracer"
# an assignment: a dependency missing stops the script, which an argument's $(...) would not; libarchive is base's
rdeps=$(deps curl ca_root_nss sqlite3)
package reiwimsy "ScarletNX's Discord bots: ReiWimsy's links and cards, and Tracer's game reports" net-im/reiwimsy \
"$rdeps"

s=$work/stage/accordwimsy/usr/local
install -d "$s/bin" "$s/etc/accordwimsy" "$s/share/examples/accordwimsy"
Expand All @@ -143,11 +154,7 @@ install -m 755 "$work/tracer/tracer" "$work/tracer/tracer-mcp" "$s/libexec/"
install -m 555 "$here/tracer.rc" "$s/etc/rc.d/tracer"
install -m 555 "$here/tracer-mcp.rc" "$s/etc/rc.d/tracer_mcp"
install -m 644 "$here/tracer.env.sample" "$s/etc/tracer.env.sample"
install -m 644 "$work/tracer/site/style.css" "$work/tracer/site/site.js" "$work/tracer/site/tracer.svg" \
"$s/share/tracer/"
# the stylesheet in each theme and each theme's Wimsy, which the site's nginx gives by the reader's pick
sh "$top/scripts/tracer-themes.sh" "$s/share/tracer/sws" "$top"
chmod 644 "$s/share/tracer/sws/"*
site_files "$s/share/tracer"
install -m 644 "$here/tracer-nginx.conf" "$s/share/examples/tracer/nginx.conf"
# libarchive is base's
tdeps=$(deps curl ca_root_nss sqlite3 libmicrohttpd)
Expand Down
3 changes: 3 additions & 0 deletions dist/freebsd/reiwimsy.desc
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ ReiWimsy answers a Discord message that names an issue or a pull request of a Gi
repository with a link to each, its title, state and labels, and keeps a card on Discord
for each open pull request, each open issue and each nightly build, edited as GitHub
changes. It runs as the service reiwimsy, its settings in /usr/local/etc/reiwimsy.env.
With TRACER_TOKEN in its env file it runs Tracer beside it, in one process and as a bot
of its own: the ScarletNX game reports people send on Discord, kept and drawn as a static
site (Tracer's package holds tracer-mcp, and Tracer alone).
5 changes: 5 additions & 0 deletions dist/freebsd/reiwimsy.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ REIWIMSY_REPO=scarletnx/ScarletNX
# REIWIMSY_CARDS_NIGHTLY=id the channel of the nightlies' cards
# REIWIMSY_CHANNELS=id,id the channels its replies answer in (all it sees without it)
# REIWIMSY_NIGHTLY=OWNER/NAME where the nightlies are when not OWNER/nightly
# Tracer beside ReiWimsy, in this process and as a bot of its own: its keys (Tracer's page, Settings), read only with
# TRACER_TOKEN; the service gives it TRACER_DB, TRACER_SITE and TRACER_ASSETS from rc.conf (reiwimsy_tracer_db,
# reiwimsy_tracer_site, reiwimsy_tracer_assets)
# TRACER_TOKEN=... Tracer's Discord bot's token, another application's than ReiWimsy's; then
# TRACER_URL and its other keys, as tracer.env.sample lists them
17 changes: 17 additions & 0 deletions dist/freebsd/reiwimsy.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,20 @@ libexec/reiwimsy
etc/rc.d/reiwimsy
@mode 644
etc/reiwimsy.env.sample
share/reiwimsy/tracer/style.css
share/reiwimsy/tracer/site.js
share/reiwimsy/tracer/tracer.svg
share/reiwimsy/tracer/sws/sepia-auto.css
share/reiwimsy/tracer/sws/sepia-light.css
share/reiwimsy/tracer/sws/sepia-dark.css
share/reiwimsy/tracer/sws/wimsy-auto.css
share/reiwimsy/tracer/sws/wimsy-light.css
share/reiwimsy/tracer/sws/wimsy-dark.css
share/reiwimsy/tracer/sws/fuddles-auto.css
share/reiwimsy/tracer/sws/fuddles-light.css
share/reiwimsy/tracer/sws/fuddles-dark.css
share/reiwimsy/tracer/sws/default.css
share/reiwimsy/tracer/sws/logo-sepia.svg
share/reiwimsy/tracer/sws/logo-wimsy.svg
share/reiwimsy/tracer/sws/logo-fuddles.svg
share/reiwimsy/tracer/sws/logo-default.svg
14 changes: 13 additions & 1 deletion dist/freebsd/reiwimsy.rc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
#
# The ReiWimsy Discord bot, run by daemon(8) as the reiwimsy user, started again when it stops; its output in syslog.
# Its tokens and channels are in reiwimsy_env_file (root's, mode 600), which rc.subr exports to it; what it keeps of
# its replies and its cards, in reiwimsy_state (its own folder, which only it reads).
# its replies and its cards, in reiwimsy_state (its own folder, which only it reads). With TRACER_TOKEN in that file it
# runs Tracer beside it: Tracer's database in reiwimsy_tracer_db's folder, which only it reads, the site it draws in
# reiwimsy_tracer_site, which anyone may read (a web server's jail mounts it read-only), its files from
# reiwimsy_tracer_assets.
#
# service reiwimsy fixcards says what reiwimsy --fix-cards would do of the nightly channel's cards that still
# say "Building", as the reiwimsy user, with the env file; changes nothing
Expand All @@ -20,6 +23,9 @@ load_rc_config $name
: ${reiwimsy_enable:=NO}
: ${reiwimsy_env_file:=/usr/local/etc/reiwimsy.env}
: ${reiwimsy_state:=/var/db/reiwimsy/state.json}
: ${reiwimsy_tracer_db:=/var/db/tracer/tracer.db}
: ${reiwimsy_tracer_site:=/var/db/tracer-site}
: ${reiwimsy_tracer_assets:=/usr/local/share/reiwimsy/tracer}

pidfile=/var/run/${name}.pid
command=/usr/sbin/daemon
Expand All @@ -37,6 +43,12 @@ reiwimsy_precmd()
fi
install -d -o reiwimsy -g reiwimsy -m 700 "$(dirname "${reiwimsy_state}")"
export REIWIMSY_STATE="${reiwimsy_state}"
if grep -q '^TRACER_TOKEN=.' "${reiwimsy_env_file}"; then
install -d -o reiwimsy -g reiwimsy -m 700 "$(dirname "${reiwimsy_tracer_db}")"
install -d -o reiwimsy -g reiwimsy -m 755 "${reiwimsy_tracer_site}"
export TRACER_DB="${reiwimsy_tracer_db}" TRACER_SITE="${reiwimsy_tracer_site}" \
TRACER_ASSETS="${reiwimsy_tracer_assets}"
fi
}

reiwimsy_fixcards()
Expand Down
2 changes: 1 addition & 1 deletion dist/status/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ for e in c["external-endpoints"]:
if e["group"] == "Bots":
assert f'span[title="{e["name"]}"]::before{{background-image:url(data:image/png;base64,' in css, e["name"]
key = e["group"].lower() + "_" + re.sub(r"[ /_,.#+&]", "-", e["name"]).lower()
assert re.search(rf"^\s*(bot|push|site) {key} ", push, re.M), ("push.sh never pushes", key)
assert re.search(rf"^\s*(bot|push|site|tracer) {key}(\s|$)", push, re.M), ("push.sh never pushes", key)
print(len(bots), "bots:", ", ".join(bots))
assert set(c["ui"]["favicon"]) == {"default", "size16x16", "size32x32"}, c["ui"]["favicon"]
for e in c["endpoints"]:
Expand Down
18 changes: 15 additions & 3 deletions dist/status/push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
# Every minute, from /usr/local/etc/cron.d/status-scarletnx on the host (as root): whether each
# bot is up, pushed to status.scarletnx.dev's Gatus at http://192.168.24.1:8080 (its external endpoints, group
# Bots). Gatus marks one down when no push came for 5 minutes, so this script stopping shows there too.
# ReiWimsy, Tracer: up when its rc variable in its jail (discordbots, tracer) says YES and its program
# has run there for a minute or more (a bot daemon(8) restarts every 30 s reads as down).
# ReiWimsy: up when reiwimsy_enable says YES in the jail discordbots and its program has run there for a
# minute or more (a bot daemon(8) restarts every 30 s reads as down).
# Tracer: it runs inside ReiWimsy when ReiWimsy's env file holds TRACER_TOKEN: up when it does and ReiWimsy is up.
# AccordWimsy: up when `noirjail.sh jail fresh` passes (each mirror had a good pass within its time).
# git.scarletnx.dev: up when forgejo_enable says YES in the jail gitscarlet and its forgejo has run a minute or
# more, read from the host (its guard keeps everything else off that jail and its tunnel's).
Expand Down Expand Up @@ -52,6 +53,17 @@ bot() {
fi
}

# Pushes Tracer <key>: it runs inside ReiWimsy, so down when ReiWimsy's env file in the jail discordbots holds no
# TRACER_TOKEN, else as ReiWimsy is.
# Usage: tracer <key>
tracer() {
if ! grep -q '^TRACER_TOKEN=.' "$jails/discordbots/root/usr/local/etc/reiwimsy.env" 2> /dev/null; then
push "$1" false "turned off: no TRACER_TOKEN in discordbots' reiwimsy.env"
return
fi
bot "$1" discordbots reiwimsy_enable /usr/local/libexec/reiwimsy
}

# Pushes site <key>: up when the web jail tracerweb's nginx answers <url> from inside the jail, else down with
# fetch's words.
# Usage: site <key> <url>
Expand All @@ -67,7 +79,7 @@ if [ ! -r "$header" ]; then
exit 78
fi
bot bots_reiwimsy discordbots reiwimsy_enable /usr/local/libexec/reiwimsy
bot bots_tracer tracer tracer_enable /usr/local/libexec/tracer
tracer bots_tracer
bot web_git-scarletnx-dev gitscarlet forgejo_enable "/usr/local/sbin/forgejo web"
site web_issues-scarletnx-dev http://127.0.0.1:8080/
esc=$(printf '\033')
Expand Down
18 changes: 15 additions & 3 deletions dist/status/push.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
# Every minute, from /usr/local/etc/cron.d/status-scarletnx on the host (as root): whether each
# bot is up, pushed to status.scarletnx.dev's Gatus at @GATUS_PUSH_URL@ (its external endpoints, group
# Bots). Gatus marks one down when no push came for 5 minutes, so this script stopping shows there too.
# ReiWimsy, Tracer: up when its rc variable in its jail (discordbots, tracer) says YES and its program
# has run there for a minute or more (a bot daemon(8) restarts every 30 s reads as down).
# ReiWimsy: up when reiwimsy_enable says YES in the jail discordbots and its program has run there for a
# minute or more (a bot daemon(8) restarts every 30 s reads as down).
# Tracer: it runs inside ReiWimsy when ReiWimsy's env file holds TRACER_TOKEN: up when it does and ReiWimsy is up.
# AccordWimsy: up when `noirjail.sh jail fresh` passes (each mirror had a good pass within its time).
# git.scarletnx.dev: up when forgejo_enable says YES in the jail gitscarlet and its forgejo has run a minute or
# more, read from the host (its guard keeps everything else off that jail and its tunnel's).
Expand Down Expand Up @@ -52,6 +53,17 @@ bot() {
fi
}

# Pushes Tracer <key>: it runs inside ReiWimsy, so down when ReiWimsy's env file in the jail discordbots holds no
# TRACER_TOKEN, else as ReiWimsy is.
# Usage: tracer <key>
tracer() {
if ! grep -q '^TRACER_TOKEN=.' "$jails/discordbots/root/usr/local/etc/reiwimsy.env" 2> /dev/null; then
push "$1" false "turned off: no TRACER_TOKEN in discordbots' reiwimsy.env"
return
fi
bot "$1" discordbots reiwimsy_enable /usr/local/libexec/reiwimsy
}

# Pushes site <key>: up when the web jail tracerweb's nginx answers <url> from inside the jail, else down with
# fetch's words.
# Usage: site <key> <url>
Expand All @@ -67,7 +79,7 @@ if [ ! -r "$header" ]; then
exit 78
fi
bot bots_reiwimsy discordbots reiwimsy_enable /usr/local/libexec/reiwimsy
bot bots_tracer tracer tracer_enable /usr/local/libexec/tracer
tracer bots_tracer
bot web_git-scarletnx-dev gitscarlet forgejo_enable "/usr/local/sbin/forgejo web"
site web_issues-scarletnx-dev http://127.0.0.1:8080/
esc=$(printf '\033')
Expand Down
6 changes: 5 additions & 1 deletion docs/BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ installed into a folder of its own. GNU make builds it (`gmake`, which is `make`

## ReiWimsy

make -C rei CONCORD="$HOME/concord" # rei/reiwimsy
make -C rei CONCORD="$HOME/concord" # rei/reiwimsy, with Tracer (tracer/libtracer.a) beside it
make -C rei test # its tests: no Discord, no network, no Concord
make -C rei test-gateway CONCORD="$HOME/concord" # reiwimsy against a fake Discord: Linux (Testing)

`reiwimsy` runs [Tracer](./REIWIMSY.md#tracer-beside-it) too: its make builds `make -C tracer libtracer.a`, the bot
without ReiWimsy's pieces, and links it, with SQLite, libarchive, zlib and the C++ runtime (`CXXRT=-lc++` on FreeBSD,
as for Tracer). Its tests need none of them.

## Tracer

Concord as above, then:
Expand Down
8 changes: 5 additions & 3 deletions docs/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ CI runs. Building: [Build](./BUILD.md); the tests: [Testing](./TESTING.md).

| Folder | What it holds |
|---|---|
| `rei/src/` | ReiWimsy: `main.c` (its settings, the gateway and its threads), `event.c` (the gateway's events, from their JSON), `watch.c` (the gateway's watch), `refs.c` (what a message asks for), `link.c` (the replies), `cards.c` (the cards), `look.c` (how an issue or a pull request reads), `github.c` (GitHub's REST and GraphQL APIs), `rest.c` (Discord's REST API), `http.c` (libcurl), `state.c` (the state file), `util.c` (strings, cJSON's lookups, the log, the clock) |
| `rei/src/` | ReiWimsy: `main.c` (the program: ReiWimsy, and Tracer beside it with `TRACER_TOKEN`), `bot.c` (ReiWimsy's settings, its gateway and its threads), `event.c` (the gateway's events, from their JSON), `watch.c` (the gateway's watch), `refs.c` (what a message asks for), `link.c` (the replies), `cards.c` (the cards), `look.c` (how an issue or a pull request reads), `github.c` (GitHub's REST and GraphQL APIs), `rest.c` (Discord's REST API), `http.c` (libcurl), `state.c` (the state file), `util.c` (strings, cJSON's lookups, the log, the clock) |
| `rei/tests/` | `test_rei.c`; `test_gateway.sh` and `fake_discord.py`, the bots against a fake Discord |
| `rei/third_party/cjson/` | cJSON 1.7.19, as its release has it, and the files' `SHA256SUMS` |
| `tracer/src/` | Tracer: `main.c` (its settings, the gateway), `message.c` (what a message asks), `report.c` (what it does with one), `files.c` (logs, pictures and videos), `worker.c` (the worker that reads them), `fetch.c` (the downloads), `store.c` (the SQLite database), `site.c` (the pages), `issues.c`, `age.c`, `titles.c`, `channels.c`; `mcp.c` and `mcp_main.c`, tracer-mcp |
| `tracer/src/` | Tracer: `main.c` (Tracer alone), `bot.c` (its settings, the gateway, the thread of its events), `follow.c` (the issues followed), `message.c` (what a message asks), `report.c` (what it does with one), `files.c` (logs, pictures and videos), `worker.c` (the worker that reads them), `fetch.c` (the downloads), `store.c` (the SQLite database), `site.c` (the pages), `issues.c`, `age.c`, `titles.c`, `channels.c`; `mcp.c` and `mcp_main.c`, tracer-mcp |
| `tracer/site/` | the site's `style.css`, `site.js` and `tracer.svg` |
| `tracer/third_party/logscan/` | ScarletNX's log summary, its commit in `COMMIT` |
| `tracer/tests/` | `test_tracer.c` |
Expand All @@ -23,7 +23,9 @@ CI runs. Building: [Build](./BUILD.md); the tests: [Testing](./TESTING.md).
| `scripts/` | `install.sh`, `make-titles.py`, `sync-logscan.sh`, `check-docs.py`, and the tests of the first and the last |

Tracer builds ReiWimsy's `util.c`, `http.c`, `rest.c` and `watch.c` again as its own, and AccordWimsy builds
ReiWimsy's cJSON: a change there is a change to all of them, and every program's tests run it.
ReiWimsy's cJSON: a change there is a change to all of them, and every program's tests run it. `reiwimsy` links
Tracer's objects (`tracer/libtracer.a`, which leaves those out) and runs both bots: a log line names the bot its file
is built for (`REI_NAME`), and the gateway's watch follows each Concord client of the program.

## Rules

Expand Down
Loading