Sunday, October 7, 2012

Tweaking Samba Shares for XBMC

If you are like me, you're setting up your OMV server as a means of serving XBMC or something similar. However, in addition to feeding movies and music to my XBMC media player, I also like to browse my media collection via windows explorer (or the Finder on a Mac). The problem is that a lot of media players collect various supplementary files, like *.nfo files or *.jpg files for folder art. When browsing via samba, these tend to "mess" things up. I did a bit of research into samba to see if there was a neat way to configure things nicely.

The "hide" and "veto" options in samba

So when configuring a samba share, it is possible to make certain files "hidden" using the "hide files" instruction. This simulates checking the "hidden" attribute in windows. For example;

hide files = /*.tbn/*.nfo/*.jpg*/*.jpeg/

Note that each file or folder type to be hidden must be separated with a backslash (/) and that you also need backslashes at the start end end. In OMV, you can put this instruction in SMB/CIFS->Settings->Extra Options, and it will apply to ALL samba shares. Alternatively, if you want to only hide certain files per share, you can find a similar place under Edit Share->Extra Options. If you aren't using OMV you can still add this configuration, just place it in your smb.conf file (in /etc/samba/) either under [global] or under a specific share.

Nice.

However, if you browse the samba share via a Mac, this won't work since OSX doesn't use the same approach for hiding files and doesn't have a "hidden" attribute. So as an alternative, you can use the "veto files" command. This instruction is handled in a similar way, and can placed in the same spot when configuring samba in OMV. For example;

veto files = /*.tbn/*.nfo/*.jpg*/*.jpeg/

However, instead of simply hiding your files, they are no longer shared. Now when you go to your shares, you won't see these files at all. Though, they still exist on the server.

Getting funky

The problem with this approach is that your media player needs to see these files. So vetoing them is counter-productive. What we want is to veto certain files, but only at certain times. Hrm...

A reasonably simply approach to this might be to configure things on a per-user basis. This is a little bit trickier, but still relatively easy. In OMV, we go back to configuring our shares and remove any references to either "hide" or "veto". Instead, we insert into Extra Options the following;

include = /etc/samba/smb.conf.%U

Again, this can be done either globally, or on a per-share basis. Basically, this instruction asks samba to look for additional configuration details whenever a user, %U, accesses a samba share. For example, if you have a user called Joe Smith, with a username jsmith and you want additional samba configurations specific to Joe, then create a file called /etc/samba/smb.conf.jsmith and put your instructions there. If samba cannot find a user-specific configuration file, then it ignores the include instruction. If you are using guest accounts in samba, then %U will be guest (ie, smb.conf.guest).

In OMV, the only way to add this additional configuration is to ssh to your server and create the file by hand.

Putting it together

Most users log into my media server with a guest account. So I've created a file called /etc/samba/smb.conf.guest which includes a single configuration;

veto files = / *.tbn / *.xml / *.jpg* / *.jpeg / *.png / *.nfo / .actors / metadata / Thumbs.db / extrafanart / extrathumbs / *.srr / *.sfv / *.nfo-orig /

I've then added the following include;

include = /etc/samba/smb.conf.%U

For both my Movies and TV shares, but not for any other shares.In addition, I've created a user specifically for XBMC, with the username xbmc. This user has access to all the media folders and sees all the content in these folders. As such, there is no need for a specific smb.conf.xbmc file.

No comments:

Post a Comment