June 15, 2009

Mounting Samba shares from Firefox

Ever since I dumped Gnome for pure WMs and heavy file managers for their lighter counterparts, my only problem was with samba shares. I used to mount them with Nautilus, Gnome's native file manager, but unfortunately, this doesn't work with Thunar or PCManFM.

A bit of googling reveals that many people asked the question:

How can I mount samba shares in thunar?
The solution usually boils down to one of these things:
None of these solutions really satisfied my requirements -- I went with manual mounting for a while, but that is a tedious task, mounting the whole network or running specializes application just seems impractical. Furthermore, I wanted to be able to mount shares just by clicking on smb:// links in firefox.

In the end, I wrote my own solution. See it in action.



It is a simple bash scripts which takes the URL and mounts all available shares. The current version of the smbmounter script can be found on github.

Download the script and place it somewhere. Then edit it and change the variable FM to your preferred file manager (default is thunar) and variable MOUNT_ROOT to the root directory where all shares shall be placed (default is /media/samba).

mount.cifs needs to run as root, so to be able to let the script run unattended (which is important if you want to use it from firefox) you need to set passwordless permission for either mount.cifs or this script. This can be done in /etc/sudoers. This is an example which will allow this for all members of group wheel.

%wheel        ALL=NOPASSWD: /sbin/mount.cifs

For an extra paranoia, modify the script to use gksudo instead of sudo.

Setting it as a protocol handler in firefox is a bit tricky. Following steps apply for Firefox 3.0.*, Firefox 2 configuration is slightly different and I never managed to set it in Firefox 3.5b4 (but hey, it's beta).

Open about:config and create new boolean property

network.protocol-handler.external.smb = true

and new string property

network.protocol-handler.app.smb

Leave this one empty -- for now. Now click the smb:// link, the format should be smb://hostname_or_ip/ The dialog will appear, asking for external application to launch. Select this script and check remember. Now go and mount.


2 comments:

Anonymous said...

It was certainly interesting for me to read the post. Thank you for it. I like such themes and anything that is connected to this matter. I would like to read a bit more on that blog soon.