leif's blog

Raspberry Pi and XBMC

This is my first blog post regarding the Raspberry Pi, a neat little toy that I've had so much fun playing with the last few weeks. At the moment, I'm using it primarily as a cheap, low power XBMC media center. I have it connected over NFS to my media server, so there's no additional disks or storage near the media system. I installed the standard Raspbian image, and on top of that a custom build of XBMC from:

http://blog-selfprogramming.dyndns.org/index.php/2012/09/06/xbmc-for-raspberry-pi/

I'm not sure why Raspbian doesn't ship an XBMC out of their repo, hopefully soon. Using this, running XBMC without an X11 window manager, I had some issues with the boot screen (and login prompt) showing up for media with letterbox borders. I could not figure out how to get XBMC to handle this, or clear it, so I took a slightly different route:

  1. I created an account, xbmc, and modified /etc/inittab to boot into this user on startup
  2. Edit the xbmc users .bashrc to clear the background, set the cursor to be invisible, and then fire up xbmc in a loop (so it restarts during a crash or shutdown)

I created the xbmc account with

$ sudo useradd  -g users -G 4,20,24,29,44,46,60,1001 --shell /bin/bash xbmc

 

The inittab is simply

1:2345:respawn:/sbin/getty -a xbmc 38400 tty1

 

And the ~xbmc/.bashrc script is

clear
echo -e '\033[?1c'
PS1=""
while [ 1 ]; do
    /usr/lib/xbmc/xbmc.bin --standalone --fs
    sleep 10
done

 

For this to work well, you also have to set a 128M/128M split, using the raspi-config utility. In addition, I'd recommend running the medium overclock mode, again set using a (recently updated) raspi-config. In my case, I run with this from /boot/config.txt:

arm_freq=900
core_freq=333
sdram_freq=450
over_voltage=2

 

You can check temperature and arm frequency with e.g.

root@rpi-2:/home/leif# vcgencmd measure_temp
temp=62.7'C
root@rpi-2:/home/leif# vcgencmd measure_clock arm
frequency(45)=700000000

 

This shows standard CPU frequency, since the system running the XBMC menu system consumes a fairly small amount of CPU.

Update: If someone has a better solution to eliminate the framebuffer crap (login prompts etc.) from the XBMC letterbox borders, please post a comment!

Deleting a folder (or user) using cyradm with Cyrus IMAP

I decided to clean out some older users I have on my Cyrus IMAP server. The documentation says to do e.g.

> sam user.foo cyradm d
> dm user.foo

This however did not work for me, even though the "d" flag is what the docs says. Searching the Cyrus forums, I found out that the permission for the admin user has to be set to "c" for the user / folder to delete. So I did

> sam user.foo cyradm cd
> dm user.foo

And things works fine agin.

The most important Ubuntu / Unity command

Drumroll.... Here it is:

$ sudo apt-get remove indicator-appmenu

That's right, get rid of the damn "global" menu bar. This is just retarded, it's the one misfeature of OSX that I can't stand, since it effectively makes it impossible to do mouse follow focus. At least the Unity people have made the problem painfully visible, the question is, why do they still have this BS at all? No one knows ...

Changing Trash folder in Thunderbird

The company I work for uses Exchange, and Outlook is their preferred client. This means (apparently...) that the Trash folder is named "Deleted Items". This messes with Thunderbird, since it creates and uses a folder named "Trash". For some odd reason, the configuration pane in Thunderbird does not have an option to modify this, instead, you have to manually edit the prefs.js file, and add a line similar to this (make sure you use the correct server #):

user_pref("mail.server.server3.trash_folder_name", "Deleted Items");

Druapl 7 problems behind a proxy

I run Drupal behind an Apache Traffic Server caching proxy. In my setup, the proxy listens on port 80, and the real Apache HTTPD server listens on port 82 (which is firewall off). In my Traffic Server remap.config, I have a rule like

map http://www.boot.org  http://www.boot.org:82

Granted, in retrospect, this is not the best of setups, but it does however causes serious problems with Drupal 7, whereas it does not cause problems with Drupal 6. In D7, the favicon.ico and all JS and CSS URLs in the head are created to use absolute URLs. I don't set an explicit $base_url in my Drupal settings.php, more on that later, and this causes the URLs to get the wrong base! These URLs are all getting a form like

http://www.boot.org:82/misc/favicon.ico

Yikes! This obviously fails, since port 82 is not accesible from the outside. Browsing the forums, the "solution" seems to be to set the $base_url in the Drupal settings.php configuration file, e.g.

$base_url = 'http://www.boot.org';  // NO trailing slash!

This does indeed solve the problem, however, it now breaks when I want to use e.g. https://www.boot.org for admin access. Besides, why these URLs should be absolute, is a mystery to me, they certainly were not in D6.

The solution I'm ending up with is of course to change Apache Traffic Server to use what we call "pristine host headers", so that the Origin server (Apache HTTPD and Drupal) sees the original client Host: header. I could not get any help from the Drupal IRC, or forums, but if anyone has any insight on why D7 is doing this crazy stuff with absolute URLs, please post. In an ideal world, they really should change these to be relative, e.g. /misc/favicon.ico.

Hacking: 

Drupal, Traffic Server, HTTPS and CDNs

I use Drupal for most of my sites. It generally works well, despite all the weirdness it does (Drupal 7 is doing strange things behind a proxy, more later). One thing is, I've started using a CDN (NetDNA) for my site. With HTTPS, this generally doesn't work well, since I'm not enabling HTTPS for the CDN (at least not yet). The CDN module in Drupal generally works well, but I couldn't see an option to prevent it from using the CDN with HTTPS. This would generate those annoying warnings from Internet Explorer for example.

Since I'm also using an Apache Traffic Server proxy in front of Apache HTTPD, the protocol information was lost oncey it hit Apache, PHP and Drupal. Bummer. I browsed through the CDN code, and noticed they do indeed honor a header of X-Forwarded-Proto, which if set to "https" will prevent the CDN from being used. I added a plugin for my remap rules, with a config like

[SEND_REQUEST_HDR]
        X-Forwarded-Proto =https=

And I activated this for the https remap.config rules for Apache Traffic Server. With this, my Drupal site now stops using the CDN when Apache Traffic Server maps from https:// to the http://localhost URL.

Hacking: 

Mouse follow focus on OSX

I always configure my Linux window managers to use "focus follow mouse". Meaning, whichever window the mouse cursor is currently in, gets keyboard focus. This is not possible with most OSX applications, because of how they've designed the UI with one Menu bar etc. However, at least two apps. Terminal and the X11 server, can be configured to do just this. It's really easy:

$ defaults write org.x.X11 wm_ffm -bool true
$ defaults write com.apple.terminal FocusFollowsMouse -string YES

 

Hacking: 

xclip

I use more and more remote X11 applications now, and VNC, since I switched my desktop (and laptops) over to use OSX entirely. This works great. Sometimes, it can be a bit annoying to get the clipboards and selections to synchronize across windows, or even to just get a portion of a file from e.g. X11 into OSX. There's a very useful command for this, that can easily be scripted (and bound) to some key of your own preference. For example, to take the clipboard from an X11 app, and put it into the main selection buffer, you can do

$ xclip -o -selection clip | xclip -i

To put a portion of  a file into both the clipboard and the primary selection:

$ head -10 /etc/group | tee >(xclip) >(xclip -sel clip) > /dev/null

You can obviously make some convenience macros around this, or simple shell scripts.

Hacking: 

sharethis.com and web site performance

I started using the sharethis.com service a while ago. And, as much as I think it's neat, it really (I mean, really!) makes the site slow down noticeably. For now, I have changed my Drupal modules to not show the sharethis.com buttons on the front page (or any "teaser") page. Instead, they have a prominent place when you view an individual article. This is a reasonable compromise I think.

Pages

Subscribe to RSS - leif's blog