Use ii to log IRC (for scripting purposes)

  _   _            
 | | | |  ___  ___ 
 | |_| | (_-< / -_)
  \___/  /__/ \___|
                   

  _   _ 
 (_) (_)
 | | | |
 |_| |_|
        

  _         
 | |_   ___ 
 |  _| / _ \
  \__| \___/
            

  _              
 | |  ___   __ _ 
 | | / _ \ / _` |
 |_| \___/ \__, |
           |___/ 

  ___   ___    ___ 
 |_ _| | _ \  / __|
  | |  |   / | (__ 
 |___| |_|_\  \___|
                   

   __   __             
  / /  / _|  ___   _ _ 
 | |  |  _| / _ \ | '_|
 | |  |_|   \___/ |_|  
  \_\                  

                  _          _     _               
  ___  __   _ _  (_)  _ __  | |_  (_)  _ _    __ _ 
 (_-< / _| | '_| | | | '_ \ |  _| | | | ' \  / _` |
 /__/ \__| |_|   |_| | .__/  \__| |_| |_||_| \__, |
                     |_|                     |___/ 

                                                  __  
  _ __   _  _   _ _   _ __   ___   ___  ___   ___ \ \ 
 | '_ \ | || | | '_| | '_ \ / _ \ (_-< / -_) (_-<  | |
 | .__/  \_,_| |_|   | .__/ \___/ /__/ \___| /__/  | |
 |_|                 |_|                          /_/ 

╔─*──*──*──*──*──*──*──*──*──*──*──*──*──*──*──*──*──*──╗
║1   ...............................................   1║
║2*  ...............................................  *2║
║3   ...............................................   3║
║1   ..............Posted: 2025-09-29...............   1║
║2*  Tags: sysadmin linux archival irc bash scripts   *2║
║3   ...............................................   3║
║1   ...............................................   1║
╚───────────────────────────────────────────────────────╝

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
```