Reject DOS line-endings at Git pre-commit

All *nix devs seethe with rage when DOS line-endings (CRLF) end up in your beautiful source code, right? If you use Git for your version control you’re in luck, use this local pre-commit hook to kick those CRLFs to the kerb before they can even make it into your local commit.

Install by copying the pre-commit file to the .git/hooks directory of your checkout. Ask your Windows using colleagues nicely to do the same.

addiction

I quit Facebook for a month, you’ll never guess what happened next …

One day in January 2016 I checked my Facebook “news” feed to discover that it contained no actual news from any of my friends. There were no status updates, no news or pictures of friends and their lives. What it was crammed full of was shares, likes and re-posts (usually clickbait or viral marketing stuff) none of which I cared about. I decided I’d had enough, I would go on a one month Facebook detox.

I posted a status telling everyone that I was going to leave Facebook for a bit, uninstalled the app from my phone and deactivated my account on the site. I went Facebook “cold turkey” for a month and here’s what happened. Continue reading

Fixing Telegram’s notification icon in Mate

I like Telegram a lot for cross platform instant messaging. It’s basically a WhatsApp clone but superior (for my purposes) because it has native (Windows, Mac & Linux) clients as well as mobile apps.

A while back I noticed that a Telegram update had caused the notification/indicator icon to go missing on my Ubuntu MATE desktop:

Telegram notification icon missing

Telegram notification icon missing

I eventually tracked the problem down to an environment variable: XDG_CURRENT_DESKTOP which Telegram uses to determine which desktop environment you’re running. In Mate it’s set to “MATE”, setting it to “GNOME” (which is what MATE actually is) works around the problem and the icon comes back:

Telegram notification icon present

Telegram notification icon present

I now use the following script to launch Telegram when I logon:
#!/bin/bash
export XDG_CURRENT_DESKTOP=GNOME
${HOME}/bin/telegram/Telegram "$@"

GDB attach to a running process in batch mode

Ever needed to attach to a running process in a gdb batch mode script but didn’t know the process’ PID in advance? You can use GDB’s built-in Python interpreter to do the heavy lifting for you. Put the following in your batch-mode script:
python gdb.execute("attach " + os.popen('pgrep <process name>').read().rstrip())
<gdb commands go here>
detach
quit

Then run as follows:
gdb --batch -x <script>

Magic!

My email to Chris Skidmore MP regarding the Syrian refugee crisis

I’m not normally a political person but the unfolding Syrian Refugee crisis has really affected me. Men, women and (worst of all) innocent children are dying whilst trying to cross into Europe to escape the conflict in their own country.

Britain has a proud history of helping those in need and I feel ashamed that we are not taking a more proactive role in taking in more of these poor people. Germany have said that they will be accepting more refugees from Syria. This is a lead we should have taken but since we haven’t we should at least follow.

In my opinion our Prime Minister, David Cameron, has brought shame on our country by denying that taking in more refugees would help:

“I don’t think there is an answer that can be achieved simply by taking more and more refugees.”

I’ve just written the following email to my local MP, Chris Skidmore, requesting that he stand up for Britain taking an official stance of accepting more Syrian refugees:

Dear Mr Skidmore

My name is Simon Aldrich, I am one of your constituents living in Kingswood with my wife and one year old son.

I would not describe myself as a political man. I have never before written to my Member of Parliament but I feel compelled to do so now regarding Britain’s position on the humanitarian crisis which is currently unfolding in Europe and at its borders. I won’t go into further details as I’m sure that you are fully aware of the appalling situation. As a father yourself I’m sure that you could not help but be affected by the harrowing images that have appeared in the media over the last few days and weeks.

I’m fully aware that Britain has already responded to the situation in Syria with aid and civilian expertise but I contend that this is no longer enough. It is my strongly held belief that Britain urgently needs to follow the lead set by Germany and have an official policy of taking in more refugees from Syria.

As your constituent I ask and hope that you will make the people of Kingswood proud by using your influence in parliament and in the media to demand that Britain does the right thing.

I look forward to hearing from you and will be following your actions with interest

Yours sincerely

Simon Aldrich

<Address and Telephone Number included>

I will update this if & when I receive a response from Mr Skidmore

Removing a disk from a RAID 1 array

I’m in the process of building a new NAS server to replace our existing one which is getting a bit long in the tooth. As usual I’ve opted to install Ubuntu Server LTS as the OS. In my current NAS I’ve got the system partition RAID 1’d across all the drives, this means that should one fail I’ve still got 4 copies.

Setting up the new NAS I’ve put the system partition on a separate SSD from the main data drives. I’ve currently only got the one SSD but I wanted the option of RAID 1’ing the system drive for redundancy should I decide to get another SSD in future.

The Ubuntu installer will quite happily let you create a RAID 1 MD device with 2 disks but only select a single drive to belong to it. This would be the equivalent of the following mdadm command:

mdadm --create /dev/md2 --level=1 --raid-devices=2 /dev/loop1 missing

However, when you boot the OS will consider that array degraded:

mdadm -D /dev/md2
/dev/md2:
Version : 1.2
Creation Time : Fri Jan 16 21:24:44 2015
Raid Level : raid1
Array Size : 32704 (31.94 MiB 33.49 MB)
Used Dev Size : 32704 (31.94 MiB 33.49 MB)
Raid Devices : 2
Total Devices : 1
Persistence : Superblock is persistent

Update Time : Fri Jan 16 21:26:58 2015
State : clean, degraded
Active Devices : 1
Working Devices : 1
Failed Devices : 0
Spare Devices : 0

Name : lupin:2 (local to host lupin)
UUID : eccabf13:879f4196:1c47de11:3059e0b8
Events : 6

Number Major Minor RaidDevice State
0 7 1 0 active sync /dev/loop1
1 0 0 1 removed

It seems that you can’t remove the “missing” disk from the array even with

mdadm /dev/md2 -r detached

I eventually found the solution to this problem. It seems (counter-intuitively) that to remove a device from the array you have to “grow” that array as follows:

mdadm /dev/md2 --grow --force --raid-devices=1

This resulted in the missing / removed / non-existent device being removed from the array and it being considered clean:

mdadm -D /dev/md2
/dev/md2:
Version : 1.2
Creation Time : Fri Jan 16 21:24:44 2015
Raid Level : raid1
Array Size : 32704 (31.94 MiB 33.49 MB)
Used Dev Size : 32704 (31.94 MiB 33.49 MB)
Raid Devices : 1
Total Devices : 1
Persistence : Superblock is persistent

Update Time : Fri Jan 16 21:32:17 2015
State : clean
Active Devices : 1
Working Devices : 1
Failed Devices : 0
Spare Devices : 0

Name : lupin:2 (local to host lupin)
UUID : eccabf13:879f4196:1c47de11:3059e0b8
Events : 11

Number Major Minor RaidDevice State
0 7 1 0 active sync /dev/loop1

This took me a while to figure out so I hope this might help someone else out there who’s trying to achieve the same thing.

Dropbox on Ubuntu Server

I’ve been using the Dropbox Linux client on my server for a while now, it’s very handy for sync’ing files to & from my various systems.

I recently installed a new server and hit the problem that following the usual instructions:


cd ~ && wget -O - "https://www.dropbox.com/download?plat=lnx.x86_64" | tar xzf -
~/.dropbox-dist/dropboxd

resulted in Dropbox not starting.

The problem (according to its crash log) was that it was trying to link against libgtk which I didn’t have installed on my (headless) Ubuntu Server 14.04 installation.

After a bit of messing around I realized that the problem was that I had enabled ForwardX11 on my PuTTY sessions and so dropboxd thought that I had an X11 session available. When I disabled X11 forwarding the problem went away & dropboxd ran as normal.

Unrar – Delete archive(s) after extraction

Due to lack of disk space on a server I needed a mechanism for automatically deleting RAR archives after their contents had been extracted. I couldn’t find any particularly neat way to do this with a shell script so I knocked up the following quick & dirty patch for unrar.

The patch applies cleanly to version 5.1.6 of the unrar source as follows:

wget 'http://www.rarlab.com/rar/unrarsrc-5.1.6.tar.gz'
tar -xvzf unrarsrc-5.1.6.tar.gz
cd unrar
wget 'http://simon.aldrich.eu/download/unrar/unrar-deleteOnExtract.patch'
patch -p1 < unrar-deleteOnExtract.patch
make

The compiled unrar binary will have the following extra option:

de  Delete archive(s) after extracting

Which you can use with the -e or -x commands e.g.:

unrar x -de test.part01.rar

Hopefully this might be useful to someone other than just me. Although, obviously, if extraction fails for any reason you will have deleted all the earlier volumes in the archive set. My suggestion would be to use the -t command to test your archive(s) first. I take no responsibility for any screw-ups you may cause yourself if you use this patch – caveat emptor!

Hacking the Motorola Blink 1 Baby Monitor (Part 2)

Ok, so it’s been quite some time since I posted my first efforts at “hacking” the Motorola Blink 1 Baby Monitor. Suffice to say we’ve been quite busy for a while & I’ve only just gotten around to actually plugging it in again now that our son is with us & at an age where we’re starting to think about being able to put him down in his crib & go into another room.

Anyway, I powered it on for the first time since August today and it asked to perform a firmware upgrade. I though ‘Aha! I’ll capture what it’s up to and see if I can work out where it downloads new firmware from’ but I inadvertently messed-up my tcpdump session & didn’t actually capture anything while it was upgrading. Furthermore, as I should have known from reading the comments here it seems that Motorola have disabled the landing page for the onboard web-server in the new firmware version (08-050) and it now just gives you a 404.

Well obviously this couldn’t be allowed to stand. Suffice to say if you capture all network traffic from the Blink when it powers on you’ll see it makes some web requests to a Monitor Everywhere ‘OTA’ server. It seems this is how it determines if there’s a firmware upgrade to be downloaded & with a bit of jiggery-pokery you too can download bmfwromfs_08_050.tar.gz which contains the latest firmware.

Unpacking the gzip’d tarball you’ll see there is a binary file ‘conprog.bin’ which I’m pretty sure is the kernel image  (2.6.17.14 since you ask) and a file ‘rootfs.bin’ which is a romfs image file containing the root file system for the camera.

You can mount this under Linux using the command:

mount -t romfs -o loop <path to rootfs.bin> <mount-point>

I’ve only just got this going tonight so I’ve yet to have a real poke around in there but for everyone who’s looking for the web interface point your brower at:

http://<camera-ip>/blinkhome.html

– or –

http://<camera-ip>/index2.html

to get it back. Incidentally the pages aren’t quite the same, so worth looking at both!