Erethon’s corner

Random thoughts of mine

On Proper Git Commit Messages and Frequent Git Pushes

Note: this is a rant on how people use git.

When I was introduced to git, I was told I should read this great post on git commit messages by Tim Pope. Ever since, I’ve been trying to follow that system in all of my commits across all projects.

Yesterday, I decided to switch from awesome to dwm. I tried to apply one of the available dwm patches, only to notice it doesn’t work with the latest version of dwm. So, I decided to have a look at the source and try to troubleshoot it myself. Running git log I was faced with this commit history:

cdec978 - applied Lukas' focus suggestion at startup, thanks (1 year, 7 months ago)
...
d83454f - applied Peters two patches, please test hg tip, if nothing breaks this is 5.9 (3 years, 9 months ago)
27b0142 - applied Garys patch in a slightly modified way (3 years, 9 months ago)
867ba36 - applied Nicolas Capit's patch as interim solution until the multiscreen support is reworked in 6.0 (3 years, 9 months ago)

This is just an excerpt, but these commits messages provide no information on what was changed, how it affects the code base or any valuable input of any kind.

In the end, I’ll probably use git bisect to troubleshoot this issue, but it would be nice and helpful if I could get some extra information from the commit history.

Update: for the record, the bug was in my config.h after all.

Another common pitfall I see often, is that people don’t realise that git is decentralized. Being decentralized means, you can code on your computer, use git add - git commit, test everything and once you’re satisfied with the output and are SURE that everything works as expected, then AND ONLY then, push to the upstream repo. Otherwise, you end up with multiple commits for something that could be squashed in a single commit.

On big projects like the Linux kernel or QEMU, you’ll often see patches that are sent multiple times before being merged, just to address the above issues. Unfortunately, this doesn’t seem to be a big deal for a lot of newer and smaller projects.

NotMuch Is Awesome

In one of my previous posts, I explained my email setup in detail. Since then I’ve added one more piece of software on the “stack”. It’s called NotMuch and it’s an email indexer.

After email is saved locally, thanks to offlineimap, it gets indexed by NotMuch in order to be searchable. NotMuch supports tags, uses Xapian for searches which means it supports stemming and is super quick and lightweight.

I’ve integrated mutt with NotMuch using the notmuch-mutt package on Debian, mutt-notmuch-py (although this can be done in many - simpler - ways) and a couple of lines on my .muttrc. I use / to search all of my emails when I’m on the index view of mutt and I to display a whole thread once I find the particular email I’m looking for.

Give NotMuch a try, after all it’s not much of an effort to set it up :)

My Mail Setup Using Mutt/OfflineIMAP/imapfilter

Update 17/03/2015: I’m also using NotMuch now, for more info check out this post.

This is part of a series of posts where I describe my workflow and OS setup.

I use email a lot both in work and my daily life, so I want/need to have a lot of control on my mail. I use IMAP for getting my email for all my accounts and SMTP to send mails.

My mail client of choice is Mutt, which is a fully featured text based (terminal) MUA. Mutt has a nice interface (supports colors), it can read the maildir mailbox format (more on that later), uses an external editor for writing email (I use Vim), supports gpg/pgp, etc. In short, it’s not lacking any features compared to a GUI client.

You can use Mutt to connect to an IMAP server and have Mutt fetch your mail, but I prefer to use OfflineIMAP which is written in Python. OfflineIMAP syncs my mails from multiple remote servers to the local filesystem in maildir format. It also supports syncing between IMAP servers but I don’t need that kind of functionality. The configuration file of OfflineIMAP is simple, clean, powerful and intuitive if you’ve used Python before.

Depending on the machine I’m working on, I only sync specific IMAP folders. Here is the part of my .offlineimaprc file responsible for selecting the folders to be sync’ed.

1
2
3
4
5
6
folderfilter = lambda folder: folder in ['INBOX',
                                         'synnefo',
                                         'synnefo-devel',
                                         ...
                                         'ganeti',
                                         'ganeti-devel']

As always you can find my dotfiles on my GitHub account.

There is one more piece of software involved on my email setup and that is imapfilter, a utility to filter/sort emails on the remote IMAP server. It’s written in a combination of C and Lua and its configuration file is using Lua too. You can filter mails based on a number of different fields like CC, To, From, Subject, etc. There is not much more to say about it actually, it does one job and it does it well and fast.

Here is a diagram of the above setup (created with asciio):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
                       Mutt sends mail using SMTP
          .------------------------<-------------------------------
          |                                                       ^
          |                                                       |
          v                                                       |
     .-,(  ),-.                                                   |
  .-(          )-.        .-------------.     .--------.      .------.
 (  Mail Servers  )<----->. OfflineIMAP .---->. ~/mail .<-----. Mutt .
  '-(          ).-'       '-------------'     '--------'      '------'
      '-.( ).-'        Fetch mails on ~/mail                 Read mails
          ^            and sync their status                 from ~/mail
          |            with the remote server
          |
          |
   .------------.
   . imapfilter .
   '------------'
imapfilter constantly filtering mails

Deploying Kippo With Ansible

I’ve been running some instances of Kippo for quite some while now with great results. I recently wrote an Ansible playbook to automate the process of deploying Kippo hosts and also make it scalable. You can find the playbook on my GitHub page, specifically here.

In a nutshell, the playbook will deploy a central database for all the Kippo hosts to log incoming attacks and then deploy a number of Kippo hosts. You can specify which repo to clone Kippo from or do ad-hoc file modifications to files in the repo. For example, I’ve modified some commands like wget.

A couple of weeks ago, GitHub announced its Student Pack, giving 100$ of credit on DigitalOcean, which I promptly grabbed. Two nights ago, I decided to use the credit on building a small cluster of SSH honeypots, consisting of twelve Kippo hosts. Of course, the whole project was orchestrated using Ansible.

My Tmux Config and a Small Tmux Primer

It’s been a little over a month since I started using tmux. Below, I’ll try to explain most of my .tmux.conf, a bit of my current workflow using awesome + tmux and various cool stuff you can do with tmux. My latest .tmux.conf can be found on my dotfiles repo on GitHub.

Tmux config file

1
2
unbind C-b
set -g prefix C-a

As most people, I’m using C-a as my bind key.

1
bind-key a send-prefix

Updating Tmux Without ‘Killing’ Active Sessions

I’ve been using tmux for a while, and even though I didn’t like it at first, now I’m in love with it. I’m mostly using it as a GNU Screen alternative, but I don’t use some of its fancy features like tabs, mainly because my window manager takes care of multiple terminal windows for me.

After a while, I got bored of starting a tmux session and configuring it every time, so I decided to give tmuxinator a try. The tmuxinator docs clearly stated that tmux >= 1.8 was needed, but I was using tmux version 1.6. I downloaded the latest stable tmux version from upstream, compiled it, installed it and tried to run it. I was greeted with this message:

protocol version mismatch (client 8, server 6)

What happened is that I had some tmux sessions still running using the 1.6 version. The obvious, and only, solution that came to my mind was to kill all running tmux sessions. Problem was, one of those sessions had my Irssi stuff open and, since I have yet to properly setup an irssi config file, I would have to reconnect to all servers, re-authenticate, rejoin all open channels, etc. Ain’t nobody got time for that.

Enter reptyr. Copying reptyr’s description:

reptyr is a utility for taking an existing running program and attaching it
to a new terminal. Started a long-running process over ssh, but have to
leave and don't want to interrupt it? Just start a screen, use reptyr to
grab it, and then kill the ssh session and head on home.

So, all I had to do was open a screen, detach the irssi processes from tmux, reattach them to screen using reptyr, kill all running tmux processes, restart the tmux server and, finally, reattach the irssi processes to tmux. Much to my surprise, it worked out flawlessly.

Now all that’s left, is to populate my ~/.tmuxinator config files and push them to my dotfiles.

Making a RS-232/UART Adaptor

A couple of months ago I wanted to experiment with the serial console of an old router I had laying around. Not wanting to buy a UART to RS-232 adaptor, I decided to make one myself. After all, I had some spare MAX3232 left over from a previous project (for which I still haven’t blogged).

I just followed the schematic provided by the datasheet and 15 minutes of soldering later, this was the end result.

images

images

Gotta love these cute little perfboards!

I’ve tested it both with a RapPI and the aforementioned router and it works great. I was able to get a serial console on the router using the serial headers on the pcb. The manufacturer had even marked the TX/RX pin holes, so there was no need for me to go serial hunting.

Now, I’m waiting for some FTDI FT232-RL chips to arrive to make a USB adaptor instead of a RS-232 one. I know you can buy one on ebay for 3 bucks, but where is the fun in that?

Octopress Here I Come!

I decided to port my blog to Octopress and move away from Wordpress after all these years. The reason for this is twofold:

  • I’ve really gotten used to working with vim, git, github and the surrounding workflow.
  • Static site generators are all the rage currently, so who am I to miss out?

Why Octopress and not something based on Python like Pelican or Nikola? I simply decided to do something that will get me out of my comfort zone and also teach me something new. I already know how to use venv, let’s see what RVM has to offer.