draptik

mostly tech stuff

Listing Environment Variables (Linux)

Just a note to self: Get a list of all linux environment variables and their values using the export command.

Here is an example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
pi@rpidev ~ $ export
declare -x HOME="/home/pi"
declare -x JAVA_HOME="/opt/java/jdk1.7.0_25"
declare -x LANG="en_GB.UTF-8"
declare -x LOGNAME="pi"
declare -x LS_COLORS="rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:"
declare -x MAIL="/var/mail/pi"
declare -x OLDPWD="/home/pi/myinstall_notes"
declare -x PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/opt/java/jdk1.7.0_25/bin"
declare -x PWD="/home/pi"
declare -x SHELL="/bin/bash"
declare -x SHLVL="1"
declare -x SSH_CLIENT="192.168.179.32 39295 22"
declare -x SSH_CONNECTION="192.168.179.32 39295 192.168.179.148 22"
declare -x SSH_TTY="/dev/pts/0"
declare -x TERM="xterm"
declare -x USER="pi"

ReorderList Demo for AjaxControlToolkit

AjaxControlToolkit’s ReorderList provides drag and drop functionality within a list.

ReorderListDemo.aspxSource Article
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<div class="CssReorderList">
    <!-- ClientMode="AutoID" is required for certain versions of AjaxControlToolkit  -->
    <ajaxToolkit:ReorderList ID="MyReorderList" runat="server"
                             DataKeyField="MyId"
                             SortOrderField="MyPosition"
                             PostBackOnReorder="False"
                             ClientIDMode="AutoID"
                             DragHandleAlignment="Left"
                             ItemInsertLocation="Beginning"
                             AllowReorder="true"
        >
        <ItemTemplate>
            <div style="background-color: yellow;" class="CssItemArea">
                <asp:HiddenField runat="server" ID="hdfMyId"
                  Value="<%# ((DummyViewModel)Container.DataItem).MyId %>" />
                <asp:Label runat="server" ID="lblName"
                  Text="<%# ((DummyViewModel)Container.DataItem).MyName %>"/>
                <asp:Label runat="server" ID="lblPosition"
                  Text="<%# ((DummyViewModel)Container.DataItem).MyPosition %>"/>
            </div>
        </ItemTemplate>
        <DragHandleTemplate>
            <div class="CssDragHandle"><strong>DRAG ME</strong></div>
        </DragHandleTemplate>
    </ajaxToolkit:ReorderList>
<div>

I’ve placed a working example project on github.

RPi/XBMC: Keeping Content in Sync

If you have multiple Rasperry Pi/XBMC clients and want to

  • keep your “history” in sync (watch a movie in room1, stop, start the same movie in room2 and resume)
  • do not want to individually update every RPi/XBMC client if the content of your data storage changes

then this post might be for you.

The XBMC Wiki decribes this in detail. This post just describes an actual implementation using Raspberry Pi clients and server.

To do this you will need a MySQL database on a machine in your network which is always accessible from your Raspberry Pi/XBMC clients (called RPI-Client from now on). Since I didn’t have a machine like this in my network I decided to buy another RPi for this purpose (referred to as RPi-Server from now on).

The content of the MySQL database only contains metadata for each entry, not the actual data (information like (a) the file path and (b) the last timestamp within the movie you were watching).

Here is a diagram showing my network setup for two Rasperry Pi clients running XBMC:

network
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
+---+
|   |   |---------------------------------|
|   |---| RPi-Client-1 (XBMC living room) |
|   |   |---------------------------------|
|   |
| L |   |------------------------------|
| A |---| RPi-Client-2 (XBMC bed room) |
| N |   |------------------------------|
|   |
|   |   |-----------------------|
|   |---| RPi-Server (Raspbian) |
|   |   |-----------------------|
|   |
|   |   |-----|
|   |---| NAS |
|   |   |-----|
+---+
  • The clients RPi-Client-X are default OpenELEC installations.
  • The server RPi-Server is a default Raspbian installation.

RPi-Server Setup

The RPi-Server has to provide a MySQL database which can be accessed from each RPi-Client-X. Just follow the simple setup instructions on the XBMC-Wiki.

This is how you can check the status of your MySQL server:

rpi-server$ sudo /etc/init.d/mysql status

RPi-Client Setup

Each RPi-Client-X needs to be configured to use the RPi-Server database.

RPi-Server: 192.168.179.36

advancedsettings.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<advancedsettings>
  <videodatabase>
        <type>mysql</type>
        <host>192.168.179.36</host>
        <port>3306</port>
        <user>xbmc</user>
        <pass>xbmc</pass>
  </videodatabase>
  <musicdatabase>
        <type>mysql</type>
        <host>192.168.179.36</host>
        <port>3306</port>
        <user>xbmc</user>
        <pass>xbmc</pass>
  </musicdatabase>
</advancedsettings>

Note: The location of the file advancedsettings.xml might very depending on your XBMC installation. For OpenELEC the file is located at /storage/.xbmc/userdata/advancedsettings.xml.

XBMC Library Update (optional)

Once the above setup works you can install the XBMC Addon:Library Auto Update. This plugin provides a GUI to setup a cron job to sync the content your RPi-Client-X has acces to (i.e. your NAS) with your MySQL database. Just install it on one of your RPi-Client-X.

MySQL Backup (optional)

A bit overkill, but I also backup the MySQL Database from the RPi-Server to my NAS using automysqlbackup.

Mapping Missing Context Menu in OpenELEC With Remote Control HAMA MCE

Remote control HAMA MCE The IR remote control HAMA MCE works out of the box with XBMC. Except that XBMC’s context menu is not mapped to any key.

An alternative solution to the one provided here is using your smart phone or tablet as a remote control with the excellent Yatse app.

Setup

Problem

Remote control does not have a key which is mapped to the context menu.

For the impatient

  • Login to your Raspberry Pi with SSH
  • Create file /storage/.xbmc/userdata/Lircmap.xml.
  • Add following content:
/storage/.xbmc/userdata/Lircmap.xml
1
2
3
4
5
  <lircmap>
      <remote device="devinput">
          <title>KEY_INFO</title>
      </remote>
  </lircmap>
  • Restart Raspberry Pi

Solution

File locations

  • OpenELEC’s system location for keymap related configs are located here: /usr/share/xbmc/system/ (I found this information in the openelec forum)
  • System default keymaps folder: /usr/share/xbmc/system/keymaps/
  • System default Lircmap.xml: /usr/share/xbmc/system/Lircmap.xml
  • Root user’s keymaps folder (empty by default): /storage/.xbmc/userdata/keymaps/
  • Root user’s Lircmap.xml does not exist by default. It has to be created: /storage/.xbmc/userdata/Lircmap.xml

Workflow

Get device name and name of desired button on remote control (‘irw’)

  • Adapted from Guide To Test a Remote and Remap Keys
  • Login via SSH
  • Type command irw
  • Press the button on remote control where you would like to map the context menu (I pressed the button with the ‘right mouse click’ symbol). This will output something like:
1
2
3
root# irw
17b 0 KEY_INFO devinput
17b 0 KEY_INFO_UP devinput

KEY_INFO is the key name, devinput is the device name.

The next sentence in the guide was not clear to me (userdata SMB share is /usr/share/xbmc/system/…):

Make sure you have a proper remote.xml in your keymaps folder which is inside your userdata SMB share (or located at /storage/.xbmc/userdata/keymaps/remote.xml)

With OpenELEC the location of userdata SMB share is /usr/share/xbmc/system/Lircmap.xml.

Get function name for context menu

The function name can be read from /usr/share/xbmc/system/Lircmap.xml. Search for ContextMenu. This should look like:

/usr/share/xbmc/system/Lircmap.xml
1
2
3
...
<title>ContextMenu</title>
...

The function name for context menu is title.

Create customized Lircmap.xml

Create /storage/.xbmc/userdata/Lircmap.xml:

1
$ nano /storage/.xbmc/userdata/Lircmap.xml

and add the following content (adapt to your needs):

/storage/.xbmc/userdata/Lircmap.xml
1
2
3
4
5
<lircmap>
  <remote device=”devinput”>
      <title>KEY_INFO</title>
  </remote>
</lircmap>

That’s it. Restart Raspberry Pi and the context menu should now work.

Pygments and Python

Frameworks like Octopress and Jekyll use the Python library Pygments for syntax highlighting.

Currenty (2013-05-23) Pygments does not work flawlessly with Python3 (see this post and this issue on pygment’s issue tracker).

This is a problem because many operating systems already provide Python3 as the default python installation.

To circumvent this issue, I found 2 different solutions:

  1. Rewire your system to always use python version X (i.e. 2.7) when python is called: See this post for an example solution.

  2. Sandbox Python installations.

Personally I prefer the approach of having a sandbox system. This way I don’t change the system’s default setting. Whenever I require a different Python version I can just switch it (this is similar to the Ruby Version Manager rvm).

This blog post explains some further details on how to install Octopress in Arch Linux. It comes down to installing python-virtualenvwrapper and configuring a new custom environment blog_env which uses Python 2.7:

Paraphrazing the original post:

To switch to the newly created blog_env, run workon blog_env. To exit a virtualenv, run deactivate.

Why I Switched From Ubuntu to Arch Linux

Ubuntu is a great GNU/Linux distribution. I have been using it since 2004, and except for one LTS (long term support) upgrade a couple years back everything was fine. That LTS upgrade a couple years back screwed up the X system, leaving me with the bash shell. Don’t get me wrong: I enjoy dabling with my Linux system, but an LTS upgrade should be safe.

Well, this was years ago.

After upgrading from Ubuntu 11.10 to 12.04 the same thing happened again: No X system.

I have a cheap Nvidia card with dual head setup (dual head means you can plug in 2 monitors). Worked fine with Ubuntu since 2009. So I upgraded to Ubuntu 12.04. And I’m back to: No X system.

I was not amused.

It was not a hardware problem: The old OS (Ubuntu 11.10) worked fine. It was not the fault of Nvidia. I am talking about a video card for 20-50 bucks! Not one of those high-end video cards.

Instead of switching to another deb or rpm based system I decided to switch to one of those “rolling” distributions like Gentoo or Arch. I picked the later and have so far not regrated the decision.

Arch Linux is my home production system of choice.

Impressions During Developing My First Application With Mono and Gtk# (GtkSharp)

Why Mono? Why Gtk?

Over the past couple of years I have been developing C# ASP.NET enterprise applications. So I am quite comfortable with the Microsoft stack.

That answers the first question: Mono gives me C# and the .NET stack.

On the other hand I have been using linux as a desktop environment on my home machine for over a decade. I am comfortable with using linux as my primary OS.

That answers the second question: Mono gives me access to Gtk, the graphics library of gnome, which is the default “desktop” in many linux distributions.

The App

I want to synchronize different Git repositories semi-automatically using a Gui.

  • Default behaviour of the automation can be loaded via a Json file.

  • Each entry describes a repository set to be synchronized.

The app is located at https://github.com/draptik/RepoSync

I also published a small demo application for gtk# and treeview: https://github.com/draptik/GtkSharpTreeViewDemo

Impressions

Monodevelop vs Visual Studio

I’ll keep it brief: If you’re used to Visual Studio and ReSharper, Monodevelop does not come close. On the other hand Monodevelop is a full C# IDE which works with linux. And Monodevelop can be used cross-plattform.

Gtk# API

The Gtk# API is not your typical .NET library. You will very soon notice that the origins are C/C++. This takes some getting used to if you have a .NET background.

Typically there are no return values. Instead Gtk# methods very often use the “out” keyword in .NET because that comes closer to the C++ implementation using pointers.

Here is an example:

Mono Gtk# Code
1
2
3
4
5
6
7
bool someBool = false;
if (listStore.GetIterFirst (out iter)) {
  do {
      someBool = (bool) listStore.GetValue (iter, 0);
  } while (someBool && listStore.IterNext (ref iter));
}
return someBool;
Pseudo-C# Code
1
return listStore.ToList().Any(s => s.MyBoolProp);

From the .NET side, I don’t like the Gtk# API. I prefer methods having return values. I guess it is a matter of tast. If it would really bother me, I would write some wrappers around… ;–)