Fixing bug in /etc/cron.daily/etckeeper on Ubuntu Lucid

I was getting an error like this:

/etc/cron.daily/etckeeper:
bzr: ERROR: exceptions.UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 34: ordinal not in range(128)

Traceback (most recent call last):
  File "/usr/lib/python2.6/dist-packages/bzrlib/commands.py", line 853, in exception_to_return_code
    return the_callable(*args, **kwargs)
  File "/usr/lib/python2.6/dist-packages/bzrlib/commands.py", line 1055, in run_bzr
    ret = run(*run_argv)
  File "/usr/lib/python2.6/dist-packages/bzrlib/commands.py", line 661, in run_argv_aliases
    return self.run_direct(**all_cmd_args)
  File "/usr/lib/python2.6/dist-packages/bzrlib/commands.py", line 665, in run_direct
    return self._operation.run_simple(*args, **kwargs)
  File "/usr/lib/python2.6/dist-packages/bzrlib/cleanup.py", line 122, in run_simple
    self.cleanups, self.func, *args, **kwargs)
  File "/usr/lib/python2.6/dist-packages/bzrlib/cleanup.py", line 156, in _do_with_cleanups
    result = func(*args, **kwargs)
  File "/usr/lib/python2.6/dist-packages/bzrlib/builtins.py", line 659, in run
    no_recurse, action=action, save=not dry_run)
  File "/usr/lib/python2.6/dist-packages/bzrlib/mutabletree.py", line 50, in tree_write_locked
    return unbound(self, *args, **kwargs)
  File "/usr/lib/python2.6/dist-packages/bzrlib/mutabletree.py", line 521, in smart_add
    for subf in sorted(os.listdir(abspath)):
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 34: ordinal not in range(128)

bzr 2.1.4 on python 2.6.5 (Linux-2.6.35.4-rscloud-x86_64-with-Ubuntu-10.04-lucid)
arguments: ['/usr/bin/bzr', 'add', '-q', '.']
encoding: 'ANSI_X3.4-1968', fsenc: 'ANSI_X3.4-1968', lang: None
plugins:
  bzrtools             /usr/lib/python2.6/dist-packages/bzrlib/plugins/bzrtools [2.1.0]
  etckeeper            /usr/lib/python2.6/dist-packages/bzrlib/plugins/etckeeper [unknown]
  launchpad            /usr/lib/python2.6/dist-packages/bzrlib/plugins/launchpad [2.1.4]
  netrc_credential_store /usr/lib/python2.6/dist-packages/bzrlib/plugins/netrc_credential_store [2.1.4]
  news_merge           /usr/lib/python2.6/dist-packages/bzrlib/plugins/news_merge [2.1.4]

*** Bazaar has encountered an internal error.  This probably indicates a
    bug in Bazaar.  You can help us fix it by filing a bug report at
        https://bugs.launchpad.net/bzr/+filebug
    including this traceback and a description of the problem.
etckeeper warning: bzr add failed
Committing to: /etc/
modified apache2/passwd.htdigest
modified apache2/sites-available/svn.jj5.net-ssl
Committed revision 87.

I’ve tried to fix it by adding:

export LANG=en_AU.UTF-8
export LANGUAGE=en_AU:en

As lines 2 and 3 in /etc/cron.daily/etckeeper.

Now I’ll wait a day or two and see if it worked…

KDE Plasma Desktop hacks

I managed to get my desktop settings so that files on the desktop were sorted automatically. But I didn’t want that. I edited the ~/.kde/share/config/plasma-desktop-appletsrc file and set the sortingStrategy=0 and that disabled automatic alphabetical desktop sorting.

I wanted to run an application on my desktop when I dropped some files on it. To do that I created a process.desktop file like this:

#!/usr/bin/env xdg-open
[Desktop Entry]
Icon=unknown
Name[en_US]=process
Name=process
Type=Application
Exec=/home/jj5/bin/tmp/process-test %F

Note the “%F” to receive the file list. More information here and here.

1000baseT for RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller

I have a Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (rev 06) in my new Ubuntu Trusty (14.04.1) server. As you can see here:

root@orac:/home/jj5# lspci
...
02:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (rev 06)
...

I was having a problem with the card only supporting 100baseT speeds. I downloaded and installed the Realtek driver (and rebooted):

# bunzip2 r8168-8.039.00.tar.bz2
# tar xf r8168-8.039.00.tar
# cd r8168-8.039.00
# ./autorun.sh
# reboot

That didn’t fix the problem.

I installed the ethtool package and ran it:

# apt-get install ethtool
# ethtool p2p1
Settings for p2p1:
        Supported ports: [ TP ]
        Supported link modes:   10baseT/Half 10baseT/Full 
                                100baseT/Half 100baseT/Full 
                                1000baseT/Full 
        Supported pause frame use: No
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full 
                                100baseT/Half 100baseT/Full 
                                1000baseT/Full 
        Advertised pause frame use: Symmetric Receive-only
        Advertised auto-negotiation: Yes
        Speed: 100Mb/s
        Duplex: Full
        Port: Twisted Pair
        PHYAD: 0
        Transceiver: internal
        Auto-negotiation: on
        MDI-X: Unknown
        Supports Wake-on: pumbg
        Wake-on: g
        Current message level: 0x00000033 (51)
                               drv probe ifdown ifup
        Link detected: yes

As you can see the speed is 100Mb/s, not 1000Mb/s. It says that 1000baseT full duplex is supported. I tried forcing the speed:

# ethtool -s p2p1 speed 1000 duplex full advertise 0 autoneg off

But that didn’t work. The ethtool program reported the card was still operating and 100Mb/s.

Then I tried plugging in a different cable… and that fixed the problem!

Making SSH client use line buffered stream

So I found out about stdbuf. To get it:

# apt-get install coreutils

If you want your ssh client to use line-buffered streams use -t -t.

So I ended up with:

# su -c "stdbuf -oL ssh -t -t /usr/bin/tail -f /var/input.log | stdbuf -oL tr -c '\\11\\12\\15\\40-\\176" myuser \
  | tee -a /tmp/input.log \
  | grep --line-buffered -v "...ignore..." \
  >> /tmp/output.log

Holy command-line Batman!

Mounting Windows SMB share from Debian Wheezy

Configuring an SMB mount from my Linux box to my Windows box. This was helpful.

Basically:

# apt-get install cifs-utils

Then create your credentials file:

# cat > /root/amanda.smbpass  <<EOF
username=jj5
password=SECRET
EOF

Then edit /etc/fstab and add:

//amanda.jj5.net/Users  /media/amanda cifs defaults,noauto,credentials=/root/amanda.smbpass 0 2

Then create /etc/network/if-up.d/mount-amanda like this:

#!/bin/bash
mount /media/amanda

And make sure it’s executable:

# chmod +x /etc/network/if-up.d/mount-amanda

Mounting can also be done from the command-line:

# mount -t cifs -o username=jj5,password=SECRET //amanda.jj5.net/Users /media/amanda

How to iteratively create PhoneGap contacts

I started a new project today to load the contacts from my personal database into my iPhone.

cd ~/Documents/pcrepo/aman-importer
phonegap create phonegap-test
cd phonegap-test
phonegap platform add ios
phonegap plugin add org.apache.cordova.contacts

There is documentation for the Contacts API.

The trouble I got into was iteratively creating contacts.

Code like this doesn’t work:

for ( var i in contact_data_list ) {
  var contact_data = contact_data_list[ i ];
  var contact = navigator.contacts.create();
  var name = new ContactName();
  name.givenName = contact_data.first_name;
  name.familyName = contact_data.last_name;
  contact.name = name;
  contact.save(
    function() { alert( 'saved!' ); },
    function() { alert( 'failed!' ); }
  );
}

The behavior is that contact.save fails and neither of the success or failure callbacks are invoked.

The way to iterate over the input data is like this:

var index = 0;
var saver = function() {
  if ( index === contact_data_list.length ) {
    // we're finished enumerating the array, we can report and exit:
    navigator.contacts.find( ['*'], report_contacts );
    return;
  }
  var contact_data = contact_data_list[ index++ ];
  var contact = navigator.contacts.create();
  var name = new ContactName();
  name.givenName = contact_data.first_name;
  name.familyName = contact_data.last_name;
  contact.name = name;
  contact.save(
    saver,
    function() { alert( 'failed!' ); }
  );
};
saver();

You can see it for real over here