Changing permissions

On Linux and OS X based systems, files have permissions. Permissions denote who can read and write a file. As such, they provide a form of access control which makes them useful for providing one aspect of security. Securing your music collection is essential.

Currently when bliss changes a file, for example embedding album art or correcting some incorrect information, the ownership of the file will revert to the user that bliss runs as. In some cases this is fine, but in others you want control over the ownership of the file to enforce a security policy.

I received an email from Nathan Truhan, a user of bliss on Synology:

bliss is currently running as root on my Synology. The problem I am having with that is the content in my media library is owned by the administrator user so it can be shared out properly. When bliss edits a tag, it changes the ownership of the directory structure and music file to root so I am getting access denied errors.

I replied to say bliss isn't currently able to change ownership and so Nathan took matters into his own hands, writing a script which can automatically update change the ownership of files.

Changing file ownership automatically

The first requirement is to install inotifywait. On Debian based Linux systems, this comes in the inotify-tools package. Once installed you're ready to try the script.

I've posted the script as a GitHub gist:

The usage of the script is pretty simple:

sudo inotify-change-ownership.sh /mnt/music/ bob music

This watches the /mnt/music/ folder and changes all changed files to be owned by the bob user, and in the music group.

The script will run until killed. You could conceivable run this at startup, although when Nathan installed it as a runlevel script he had trouble shutting down his Synology:

I ran into a problem with the entware script setup on the Synology that it would start the script, but it would not call the kill script. [...] This caused my NAS to hang every time it had to reboot, like while doing an update.

Nathan Truhan

I'd be interested to hear of other's experiences of this script, and if anyone can work around the hanging issues described above!

Thanks to Ksenia Makagonova for the image above.
tags: technical

The Music Library Management blog

Dan Gravell

I'm Dan, the founder and programmer of bliss. I write bliss to solve my own problems with my digital music collection.