2008/06/08

UPnP client under Ubuntu: djmount

While there are quite a few UPnP servers for Linux out there (MediaTomb, Rhythmbox Coherence Plugin,...), I couldn't find any serious UPnP client (or UPnP-renderer in UPnP-speak) for Linux. I did find some promising libraries like the C++ Platinum UPnP library (used in XBMC) or the Java UPnpLib., but as far as I know no Linux MediaPlayer (like Rhythmbox or Amarok) uses those. There is also a UPnP 'controller', Cidero written in Java, but it has no playback capabilities. Cidero is very useful for debugging your UPnP setup, however.

The only relevant linux UPnP-client is djmount, also used in GeexBox. It is quite primitive: the UPnP devices are mounted as a filesystem. There are no debian packages available for djmount; you have to build it from the sources. The best copy/paste scenario for installing djmount on ubuntu is http://linuxowns.wordpress.com/2008/06/05/accessing-upnp-server-from-ubuntu/.

Unfortunately the last step '6', ie. autorunning djmount at logon doesn't work -- at least under Ubuntu 8.04. If you have a wlan, djmount fails when no network is up. As a comment by 'anonymous' points out, the Ubuntu NetworkManager fires the /etc/NetworkManager/dispatcher.d/01ifupdown script that runs (with run-parts) all scripts in /etc/network/if-up.d under root.

The following steps do work for autostarting djmount under ubuntu:
cd /etc/network/if-up.d
gksudo gedit ./djmount
contents of script:
#!/bin/sh

# Not for loopback!
[ "$IFACE" != "lo" ] || exit 0

modprobe fuse
fusermount -u /media/upnp
djmount -o allow_other /media/upnp

sudo chmod 755 ./djmount
sudo chown root ./djmount
sudo chgrp root ./djmount
Djmount is now (re)mounted whenever the network is up. As stated previously, djmount is a very rudimentary solution because Rhythmbox for example will parse and analyse all mp3s again. Maybe the linux mediaplayers will integrate some of the existing UPnP Libraries in the future. This would be a welcome addition. I'm still hesitating between using djmount or using regular samba-mounts on my laptop.

update 7/7/2008 : This fixed version runs djmount after the network is connected. No need for setuid or "sleep 30" anymore. (*)

(*) to remove the old version of the scripts this post in its first form suggested, you must:
  • remove the upnp action from the System/Preferences/Sessions
  • sudo rm -f /usr/local/bin/djmount.sh
  • sudo chmod u-s /usr/local/bin/djmount
  • sudo chmod g-s /usr/local/bin/djmount

2 comments:

Anonymous said...

look at/etc/NetworkManager/dispatcher.d/01ifupdown for network event hooks

Michaël said...

Great tip. I suspect I'll have to put the djmount script in /etc/network/if-up.d/.

I'll try it out & report back.