$_ BSDHowTo.ch
How To... Why not..? Scripts Patches RSS logo

How to use IRC client sic

Last update: 2020-08-30

Introduction

You can find some great tools on suckless.org. Recently I've discovered sic - simple irc client. After staying away from IRC for a while because of too much frustration with the common IRC clients like irssi and weechat I gave sic a shot. In this post I show you how I have integrated sic with base tools to make IRC usable again.

Ingredients

OpenBSD has a package available for sic:

$ doas pkg_add -i sic

Beside the client I will use

First connection test

For the first test I run a clear text connection to the IRC server:

$ sic -n userid -k password -h irc.example.net -p 6667

If transmitting your IRC password in plain text over the Internet is a concern for you you fast forward to the chapter about adding transport encryption to the setup.

If the connection is successful you will get the usual messages from the IRC server, just without the formatting of other IRC clients.

Transport encryption (TLS)

sic is so simple that it “lacks” the feature of transport encryption. But there is no need to implement that in sic because there are already tools that handle TLS.

OpenBSD comes with a tool for this in base: relayd(8). With a few lines in relayd.conf(5) you can encrypt the communication to your IRC server of choice:

table <freenode> { irc.freenode.net }

relay "freenode" {
    listen on localhost port 6667
    forward with tls to <freenode> port 6697
}

Now you can enable and start relayd:

$ doas rcctl enable relayd
$ doas rcctl start relayd

Repeat the test from above, this time with transport encryption to hide your password:

$ sic -n userid -k password -h localhost -p 6667

Filtering some noise

One of the first tasks you usually perform during the configuration of a new IRC client is filtering out the noise of /JOIN and /QUIT commands in the channels. A UNIX veteran comes to our rescue here: sed(1). Just pipe the output of sic to sed(1) like this:

$ sic | sed -E "/(JOIN|QUIT)/d"

All lines that contain the words JOIN or QUIT will be removed from the stream by sed(1). Of course you can filter out other things by writing a regular expression according to re_format(7). But you might want to test it carefully, else you could miss parts of the actual conversation.

Logging the output

Some people like to log IRC channels for different reasons. If you feel the need to do so you use another basic UNIX tool: tee(1). Just plumb it in in your existing IRC pipe. If you want your log unfiltered you should put tee(1) right after sic:

$ sic | tee irc.log | sed -E "/(JOIN|QUIT)/d"

Of course you can swap tee(1) and sed(1) to have the noise removed in the log file too:

$ sic | tee irc.log | sed -E "/(JOIN|QUIT)/d"

Keep it running

You may want to make sure sic keeps running, e. g. because you use it to log your favorite IRC channel. Or because you run it on a remote host and connect over an unstable link. A terminal multiplexer like tmux(1) comes to the rescue. Do yourself a favor and put the command pipe to start sic into a dedicated shell script. This way you save yourself the hassle of escaping all the single and double quotes the right way. You can then start sic like this in tmux(1):

$ tmux new -s irc -n \#openbsd bin/irc.sh

This starts tmux and creates a new session called irc with a new window called #openbsd. You can start other instances of sic in additional windows and connect to different channels. This gives you a multi-window interface close to what most text-based IRC clients provide these days.

Make it autojoin a channel

You can even make sic automatically log in to the channel #openbsd with the help of tmux(1). Just send the necessary key strokes to the tmux(1) session with a little delay to give sic the chance to log in to the server. Your bin/irc.sh script could look similar to this example:

#!/bin/ksh

sleep 2 && tmux send -t irc ":j #openbsd" Enter &
sic -n user -k pass -h localhost -p 6667 | tee irc.log | sed -E "/(JOIN|QUIT)/d"

Credit goes to @prx@bsd.network who brought up the idea to use tmux(1) to send the necessary key strokes to sic. More great ideas for sic came up at @bsd.network.

Using a bouncer

If you spawn too many connections to the same IRC server it may block you because it looks like a DoS attack coming from your IP address. You should clarify if the IRC server tolerates simultaneous connections from the same IP and how many of them before you do this.

If you really want to use this setup to connect to many channels it might be a good idea to use an IRC bouncer like bnc as a connection multiplexer. The bouncer acts as a proxy between sic and the IRC server, using one connection to the IRC server and providing many connections to the clients. Most bouncers come with TLS support, so you can replace relayd(8) from above by the bouncer.