Transmission Unrar Permission Error

Hey guys,

I’ve got transmission installed and it works great. I’ve changed settings.json to run a sh script to extract completed torrents (/opt/Scripts/extract.sh). I’ve chmod everything so the permissions should work, but when it comes time to do the actual extract I’m getting a Permission denied error. Journalctl:

Nov 19 10:06:14 osmc transmission-daemon[778]: No files to extract
Nov 19 10:06:14 osmc transmission-daemon[778]: Cannot create FileOfDubiousIntent.nfo
Nov 19 10:06:14 osmc transmission-daemon[778]: Permission denied

Transmission is running as OSMC (ps auxf), and clearly transmission has write access to the folder or it couldn’t store the file. its running an unrar command:

find /$TR_TORRENT_DIR/$TR_TORRENT_NAME -name "*.rar" -execdir unrar e -o- "{}" \;

Based on the errors I’m thinking I messed up a permission somewhere along the way, but I’m having trouble figuring out where the problem might be. Any thoughts?

What’s the starting point of your find command? It should be a directory but I see /$TR_TORRENT_DIR/$TR_TORRENT_NAME Is $TORRENT_NAME always a directory?

Please show the ownership/permissions of the shell script, plus ownership/permissions of the torrent directory, and those of a rar file.

You could also add the command touch zzz command to your shell script to see if it creates the file zzz, as well as the creation userid.

$TR are enviromental variables that Transmission can pass to scripts it executes. so in theory its passing on:

find /mnt/hdd/torrents/file.rar -name "*.rar" -execdir unrar e -o- "{}" \;

(Scripts – Transmission)

Script:

osmc@osmc:/opt/Scripts$ ls -la
total 12
drwxr-xr-x 2 osmc osmc 4096 Oct  2 10:38 .
drwxr-xr-x 7 root root 4096 Oct  2 09:49 ..
-rwxrwxrwx 1 osmc osmc  351 Nov 19 11:38 extract.sh

Directory:

drwxrwxrwx  2 osmc osmc     32768 Nov 19 11:46 test

File:

osmc@osmc:/mnt/hdd/Media/Torrents/test$ ls -la
total 104896
drwxrwxrwx  2 osmc osmc     32768 Nov 19 11:46 .
drwxrwxrwx 51 osmc osmc     32768 Nov 19 10:05 ..
-rw-rw-rw-  1 osmc osmc 107330658 Nov 19 10:06 FileName.rar

I can see a few possible problems.

  1. A torrent might simply download a file, eg filename.rar or video.mkv or it might create a directory into which one or more files are downloaded.

  2. The file or directory name in $TR_TORRENT_NAME might contain spaces, so you need to enclose the variable name in double quotes.

  3. The find command takes a directory name as its starting point, so you can’t use $TR_TORRENT_NAME if it is a filename.

I see where you’re coming from, but I think I’m passed that stage already. JournalCTL:

Nov 19 10:06:14 osmc transmission-daemon[778]: Cannot create file.nfo
Nov 19 10:06:14 osmc transmission-daemon[778]: Permission denied
Nov 19 10:06:14 osmc transmission-daemon[778]: Cannot create file.exe
Nov 19 10:06:14 osmc transmission-daemon[778]: Permission denied

In this case file.nfo and file.exe are files that are in the RAR archive. So its getting far enough that its executing the unrar command against the correct file, it just can’t extract it due to a permission problem.

Hi,

What happens if you run the script from the command line with out transmission.

Thanks Tom.

It looks like you can scratch point 3. It seems like find can use a file as its starting point. It’s not something I ever tried before. :wink:

To debug it, you could you create a script that is executed by the find command. Someting along the lines of:

find /"$TR_TORRENT_DIR"/"$TR_TORRENT_NAME" -name "*.rar" -execdir /opt/Scripts/unrar.sh "{}" \;

and unrar.sh looks something like:

#!/bin/sh
echo Now in `pwd`
ls -l "$1"
unrar e -o- "$1"

plus any other debug tests you wish to add.

The script wouldn’t run without transmission due to the environmental variables the script uses. However, if I run

find File -name "*.rar" -execdir unrar e -o- "{}" \;

it works perfectly and gives no errors. only when Transmission executes the script does it have a permission problem.

Everything I know about linux I’ve learned from OSMC, so I’m still in diapers. Is there a permission gap that occurs between transmission executing the script, and passing that permission on to unrar as the script executes?

Hi,

I’ve not got transmission installed on my osmc boxes, it would interesting to see what user is transmission is running with, please post the output of:

cat /lib/systemd/system/transmission-daemon.service

Thanks Tom.

I always assumed that to be the case.

That’s what we need to determine. Generally speaking, a program or script will run under the user that called it. The debug shell script might shed some light on what’s happening.

Just to clarify one point: was transmission installed from the OSMC app store?

I’ve created the files for debugging as you’ve suggested. It still looks like it attempts to execute the unrar, but fails due to permission.

Nov 19 13:29:45 osmc transmission-daemon[778]: Permission denied
Nov 19 13:29:45 osmc transmission-daemon[778]: Cannot create file.nfo
Nov 19 13:29:45 osmc transmission-daemon[778]: Extracting from //mnt/hdd/Media/Torrents/test/TestFile.rar
Nov 19 13:29:45 osmc transmission-daemon[778]: UNRAR 5.21 freeware      Copyright (c) 1993-2015 Alexander Roshal
Nov 19 13:29:44 osmc transmission-daemon[778]: -rw-rw-rw- 1 osmc osmc 107330658 Nov 19 13:29 //mnt/hdd/Media/Torrents/test/TestFile.rar.
Nov 19 13:29:44 osmc transmission-daemon[778]: Now in /

Not sure what more I’m supposed to be looking at for debugging.

There’s your answer: Now in /

It’s trying to extract to the root directory.

@dillthedog Yes, I installed it from the AppStore.
@Tom_Doyle which is why I get the following:

osmc@osmc:/opt/Scripts$ cat /lib/systemd/system/transmission-daemon.service
cat: /lib/systemd/system/transmission-daemon.service: No such file or directory

Modified to cat /lib/systemd/system/transmission.service

osmc@osmc:/lib/systemd/system$ cat /lib/systemd/system/transmission.service
[Unit]
Description=Transmission BitTorrent Daemon
After=udisks-glue.service

[Service]
User=osmc
Group=osmc
Type=notify
ExecStartPre=/bin/sleep 10
ExecStart=/usr/bin/transmission-daemon -f --log-error --allowed *.*.*.*

[Install]
WantedBy=multi-user.target

Ah! I was wondering what that ‘pwd’ thing meant earlier… apparently its ‘current director’ or something similar.

Any idea on why its trying to extract to root? When I execute the command itself (not from transmission) it seems to work fine.

What happens if you try:

find /home/osmc/File.rar -name "*.rar" -execdir unrar e -o- "{}" \;

That yields nothing because that isn’t where the file is, but if you wanted me to run it from the torrent directory:

 find /mnt/hdd/Media/Torrents/test/File.rar -name "*.rar" -execdir unrar e -o- "{}" \;

That yields the same permission error.

I think you’re on to something. I can look at hard coding the extraction point as that should bypass the weird extract to root behavior.

I think the strange behaviour of -execdir is because you’re using a file as the starting point of the find.

If you use:

find /mnt/hdd/Media/Torrents/test -name "*.rar" -execdir unrar e -o- "{}" \;

I’m guessing that the permission problem will no longer occur.

Thank you for all the help, I know its not exactly what this board is for but sometimes its difficult to narrow down exactly where you should be asking the questions.

I’m going to explore the variables used by Transmission, but for the time being I solved the problem by just putting a

cd /$TR_TORRENT_DIR/$TR_TORRENT_NAME/

at the start of my shell script. This changes the directory within the script itself so its no longer executing at the root level. Seems to be working for the time being, despite feeling a bit kludgy.