⚠️ This post is archived from my phlog in Gopherspace. Please read my post on the Gopher Protocol to get started!
I wanted to show the user the latest irc message via gopher so…
Install ii.
Tiny logger script
mkdir -p ~/.local/bin
then make file ~/.local/bin/ii-main-logger
#!/bin/sh
set -eu
BASE="${II_DIR:-$HOME/irc}"
SRV="${IRC_SERVER:-127.0.0.1}" # your IRCd is localhost
PORT="${IRC_PORT:-6667}" # plaintext (no TLS wrapper needed)
NICK="${IRC_NICK:-digestlog}"
CHAN="${IRC_CHAN:-#main}"
mkdir -p "$BASE"
# start ii
ii -s "$SRV" -p "$PORT" -n "$NICK" -i "$BASE" &
pid=$!
# wait for the input FIFO to appear, then join channel
for i in $(seq 1 100); do
[ -p "$BASE/$SRV/in" ] && break
sleep 0.1
done
printf 'JOIN %s\r\n' "$CHAN" > "$BASE/$SRV/in"
# keep the process in the foreground so systemd can supervise it
wait "$pid"
then
chmod +x ~/.local/bin/ii-main-logger
create systemd ~/.config/systemd/user/ii-logger.service
[Unit]
Description=ii logger for %E{IRC_CHAN:-#main} on %E{IRC_SERVER:-127.0.0.1}
After=network.target
[Service]
Type=simple
Environment=II_DIR=%h/irc
Environment=IRC_SERVER=127.0.0.1
Environment=IRC_PORT=6667
Environment=IRC_NICK=digestlog
Environment=IRC_CHAN=#main
ExecStart=%h/.local/bin/ii-main-logger
Restart=always
RestartSec=5
[Install]
WantedBy=default.target
then
systemctl --user daemon-reload
systemctl --user enable --now ii-logger.service
sanity check:
ls -R ~/irc
tail -n3 ~/irc/127.0.0.1/#main/out
change nick/channel later (systemctl –user edit ii-logger.service and override the Environment= lines, then):
systemctl --user daemon-reload
systemctl --user restart ii-logger.service
Also, logrotate so doesn’t keep track everything forever:
sudo tee /etc/logrotate.d/ii-logger >/dev/null <<'ROT'
# Rotate ii channel logs under your home. Adjust the path if needed.
# Keeps 14 compressed rotations; trims when file >256k or daily, whichever first.
# copytruncate avoids needing to restart ii.
/home/*/irc/*/#*/out {
daily
size 256k
rotate 14
compress
delaycompress
copytruncate
missingok
notifempty
}
ROT
# test it (dry run shows what would rotate)
sudo logrotate -d /etc/logrotate.conf
Original content in gopherspace: gopher://gopher.someodd.zip:70/0/phlog/ii-logger.gopher.txt