Tuesday, February 10, 2015

Dpkg Time Machine

I wish there would be a standard tool to list all the packages installed since certain date. So that I could use that information to revert the system state to its original or even fresh-install state.

Luckily there is a log with every ever installed, upgraded or removed package. From time to time the log file is archived and the latest can be always found at /var/log/dpkg.log. I wrote a simple script that parses all the log files, including the archived onces, and extracts the packages names.

So one can simply do
$ sudo apt-get remove `./dpkg-since.py 2015-01-01`
to clean up the system from anything installed since the beginning of the year.

Thursday, September 18, 2014

How to pair a Low Energy (LE) Bluetooth device in dual boot with Windows & Linux

Those who dualboot know the pain of re-pairing your keyboard or mouse everytime you boot to a different OS. In this tutorial I will show how to pair a LE Bluetooth mouse in both Windows 8 and Debian simultaneously.

First pair the device in Debian, then reboot in Windows and pair the device there too. Yes, this will reset the paring in Debian, just carry on. Now we need to access the pairing keys in Windows. Download psexec.exe and open a command prompt with Administrator rights.
> cd Downloads
> psexec.exe -s -i regedit /e C:\BTKeys.reg HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\BTHPORT\Parameters\Keys
The keys should be now exported to C:\BTKeys.reg. You should get something like:
Windows Registry Editor Version 5.00
 
[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\BTHPORT\Parameters\Keys]
 
[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\BTHPORT\Parameters\Keys\7512a3185b2c]
 
[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\BTHPORT\Parameters\Keys\7512a3185b2c\84abd4a25ee1]
"LTK"=hex:6c,54,ee,80,40,47,6c,cb,fc,8e,f3,f1,c6,b2,04,9e
"KeyLength"=dword:00000000
"ERand"=hex(b):1e,12,aa,37,39,cc,af,34
"EDIV"=dword:00003549
"CSRK"=hex:38,d7,aa,c1,42,06,31,25,12,b8,5a,6d,c3,90,98,f2
7512a3185b2c is the MAC address of the Bluetooth adapter, which can also be written in standard format as 75:12:A3:18:5B:2C. 84abd4a25ee1 is the mouse address that was assigned during the pairing. We will need those numbers in the next steps.

Now boot again to Debian. The mouse wont paired automatically, because it is now assigned to a different address and with different keys. Let's fix it.
$ cd /var/lib/bluetooth/75:12:A3:18:5B:2C/
$ ls
cache 84:AB:D4:A2:5F:E1 settings
If you look closely, the mouse address is not the same as in Windows. In my case only the fifth group is different. We need the device addresses to match, so rename the file.
$ mv 84:AB:D4:A2:{5F,5E}:E1
$ cd 84:AB:D4:A2:5E:E1/
$ ls
attributes gatt info
Now open the info file for editing and update the keys values. The relation between Windows and Bluez keys format is as follows:
  • LTK goes into Key of the LongTermKey group. Change to uppercase and remove the commas.
  • KeyLength goes into EncSize. In my case I had to replace the original value 12 with 0.
  • ERand goes into Rand. This is the tricky part. First you need to write down the ERand value in reverse, so it becomes 34afcc3937aa121e. Then convert it to decimal to get 3796477557015712286.
  • EDIV goes to EDiv. Convert from HEX to decimal normally, no reverse this time.
  • CSRK goes to Key of the LocalSignatureKey group. Uppercased and no commas.
At the end you should get this.
[LocalSignatureKey]
Key=38D7AAC14206312512B85A6DC39098F2

[LongTermKey]
Key=6C54EE8040476CCBFC8EF3F1C6B2049E
Authenticated=0
EncSize=0
EDiv=13641
Rand=3796477557015712286
Save the changes and reboot. From now on Debian and Windows will connect the mouse automatically. Awesome!

Wednesday, February 26, 2014

Force Qt apps to use the currently selected Gnome 3 icon theme

Gconf, Dconf, Gsettings, too many settings storages for Gnome. Although the latest Gnome 3 uses GSettings only, Qt 4.x still relies on Gconf from Gnome 2.x. So changing the icon theme in Gnome 3 doesn't affect Qt apps. What you need is to copy the theme name from Gsettings to GConf via this command:

gconftool-2 --type=string --set "/desktop/gnome/interface/icon_theme" `gsettings get org.gnome.desktop.interface icon-theme | tr -d "'"`

and restart the Qt app.

Monday, February 17, 2014

How to paste from PRIMARY selection buffer via keyboard shortcut

In your desktop environment of choice, go to keyboard shortcuts setting and create a new shortcut with the command:
sh -c 'xsel | xvkbd -file - 2>/dev/null'
and set the desired key combination.

Thursday, August 8, 2013

Using Focusrite Scarlett 18i6 in Linux, Part II



Earlier I posted how to patch ALSA for Scarlett. Apparently it didn't work for everyone.

Didn't work quite well for me either. Every time I put my computer to sleep, after resume Scarlett lose the connection and there was nothing I could do to bring it back, except rebooting the computer. I got so tired of it that I even switched to internal sound card on my motherboard.

Recently I found another way that some may find suitable too. Digital inputs! That's right, if you're okay to use Scarlett for playback only and you value the sound quality, digital inputs is the way to go. Scarlett has two options in fact, ADAT via TOSLINK and S/PDIF via RCA.

Luckily my motherboard is equipped with S/PDIF as well, TOSLINK and internal S/PDIF connector. Some motherboards may have ready S/PSID RCA output on rear panel. At least I had to spend 30 min with soldering iron to get a bracket like this:


Boot to Windows and enable S/PDIF inputs in Scarlett MixControl panel, if they are not enabled for some reason yet. Scarlett will remember the settings, so no need to do it again. Enjoy!

Tuesday, March 26, 2013

Expanding wildcards with qmake

I was always wondering why doing something like this never worked
SOURCES += *.cpp
SOURCES -= excluded.cpp
excluded.cpp always stayed in SOURCES. The thing is that when you add a new value to the list, it's just a string. Thus using wildcard in files names is nothing more but an asteriks character. And therefore using -= operator will only remove exact strings. But today I found another undocumented function I've been looking for years!

$$files(glob) — Returns a list of files which match the specified glob pattern.

So now I can do
SOURCES += $$files(*.cpp)
SOURCES -= excluded.cpp
and it actually works.

Wednesday, March 20, 2013

Enable icons in menus and buttons for Qt apps in Ubuntu 12.04.2

Way too many things broken in recent Ubuntu releases, should have stayed on 10.04 forever perhaps. Anyways, there is a fix:
gconftool-2 --type boolean --set /desktop/gnome/interface/buttons_have_icons true
gconftool-2 --type boolean --set /desktop/gnome/interface/menus_have_icons true