Jump to content

User:CDanis (WMF)/Build your own IRCcloud

From Wikitech

What I wanted / what this setup gives you

  • A browser-based chat client
  • a fallback to something command-line running inside screen/tmux
  • an mobile app with a passable UI (not a terminal emulator on a tiny screen)
  • mobile push notifications for DMs and highlights, but only when I was inactive on desktop
  • as much open-source software involved as possible

The components

  • A high-uptime Linux machine/VPS somewhere, preferably with a proper domain name (for SSL certificates)
  • Weechat
  • Glowing Bear

For Android

For iOS

This information is outdated. I no longer recommend ZNC. Glowing-bear in a browser is the best iOS "client" at present. TODO document a notification mechanism

If you're using Android, skip the parts involving ZNC. If you're using iOS, you'll need ZNC if you want push notifications and/or a reasonable mobile client.

Setup

Below are some vague instructions. These are not as detailed as they should be -- lots of general systems knowledge is assumed, as well as some knowledge of IRC and ZNC. Please be bold and improve them!

  1. Have a place to run Weechat (and maybe ZNC), like a VPS or similar. I chose Google Compute Engine, as you can easily fit all of this within their always-free tier. I found reasonable instructions for setting up a GCE 'f1-micro' instance here (ignore the latter half of the doc about cjdns, but do everything up to there, including the part about assigning a static external IP).
  2. Assuming you're using GCE and their default Debian Stretch image, you'll also get the stretch-backports depot enabled by default. sudo apt install -t stretch-backports znc znc-dev weechat
  3. You'll almost certainly want to obtain SSL certs for your setup. Install and configure certbot for your machine. Also install the deploy hook at the bottom of the page, possibly running it by hand after creating some directories... (TODO: there are some ordering issues here, at least with the script as-is!)
  4. If using ZNC: configure ZNC to your liking. I started off with znc --makeconf to set basics (SSL enabled, IPv6 disabled, picked a port number, specified freenode & a list of channels to join) and then did the rest via its web UI. You'll definitely want to enable the sasl module and give it your nickserv auth soon after launching ZNC.
    1. I never got to the bottom of why, but with IPv6 enabled, my ZNC session cookies were not working.
    2. If using GCE: you'll need to open that port in GCE's firewall. Here's simple steps and full documentation.
    3. NB: by default, ZNC serves both HTTPS and IRC-over-TLS on the same port. I was fine with this, although I don't want to think too hard about the code involved here.
  5. If using ZNC: Pick a random password to use for authenticating yourself for ZNC. I had my password manager generate one.
  6. I set up Weechat next. You'll want to tell Weechat about ZNC's extended ircd capabilities, for instance -- follow the Weechat instructions on ZNC's wiki. Since you're using a cert from certbot for ZNC, tell Weechat to connect to your host's FQDN, not localhost.
  7. If you want to use Glowing Bear, you'll have to configure the Weechat relay.
    1. Tell Weechat to use SSL for its relay, generate another strong password, and turn on the relay:
      /relay sslcertkey
      /set relay.network.password your_strong_password_here
      /relay add ssl.weechat 9001
      
    2. Poke another hole in GCE's firewall for that port
    3. Now you can fire up Glowing Bear and point it at your weechat!
  8. If using iOS mobile: Now we'll set up Mutter and its push notifications. First, a few changes ZNC-side:
    1. Load the modpython znc module, either by going to the web UI and ticking the box, or /msg *status loadmod modpython
    2. Download the Mutter push ZNC module and put the mutter.py file in your ~/.znc/modules dir, then load module mutter
    3. Download the ZNC playback module, so that Mutter is able to fetch history for exactly the time range it cares about. Run znc-buildmod playback.cpp and mv the resulting playback.so file into your ~/.znc/modules dir, then load module playback
    4. Finally, install Mutter on your iOS device, and point it at your ZNC server.
      1. You should probably have Mutter authenticate to your ZNC with username: zncusername@iphone/freenode. The @iphone portion is an optional tag identifying each of znc's clients.
      2. You might also want to set up the 'clientbuffer' ZNC plugin and disable ZNC's "auto clear" options
    5. Since you probably want push notifications, set up Pushbullet, make an API token, and give it to Weebullet.

certbot deploy hook

Put this in a file inside /etc/letsencrypt/renewal-hooks/deploy/ and make it executable.

#!/bin/sh

set -euf

DOMAIN=bubbles.nucleosynth.space
MYUSER=cdanis

cd /etc/letsencrypt/live/$DOMAIN
if [ privkey.pem -nt /home/$MYUSER/.weechat/ssl/relay.pem ]; then
        cat cert.pem privkey.pem > /home/$MYUSER/.weechat/ssl/relay.pem
        cat fullchain.pem > /home/$MYUSER/.weechat/ssl/fullchain.pem
        su $MYUSER -c "echo '*/relay sslcertkey' > /home/$MYUSER/.weechat/weechat_fifo"
fi
if [ -d /home/$MYUSER/.znc -a privkey.pem -nt /home/$MYUSER/.znc/znc.pem ]; then
        cat privkey.pem fullchain.pem > /home/$MYUSER/.znc/znc.pem
fi

TODOs

  • systemd user units for launching all this automatically
  • deploy hook has never been tested on a new configuration, just an existing working one
  • look at thelounge, seems like the right 'real' answer.

Changelog

20190714

"Effective June 12th, 2019 - Mutter is end of life (EOL) and will no longer be maintained or supported. The Push Notification service will continue to operate until July 10th, 2019. Thank you to everyone who has supported Mutter over the years." Replaced Mutter push notifications with Pushbullet / weebullet.