I have a Raspberry Pi running Transmission. The main data partition is on a USB drive. The partition is formatted as HFS+ (hfsplus) in case I need to plug it into my Mac. The Mac connects to the data partition via Samba.

Transmission has a feature to run a script when the download completes. But this does not recognize that the download may still be seeding. Instead, I have a cron job running under my username "myuser". This job triggers a script which will check for a completed download, determine whether it is still seeding, and if not, process the download.

The cronjob was setup using `crontab -e` under myuser:

```
*/5 * * * * /media/Data/torrents/torrent-clean

```

The script will make a new directory if needed and move the file to that directory. Most of the script is involved in formatting the name of the new file and directory and accessing the torrent daemon. The pertinent lines are:

```
mkdir "${target}/${folder_title}"
mv "$the_video" "${target}/${folder_title}/${video_title}"

```

The whole script: <http://pastebin.com/JqqRMRp8>

The directory gets created by the script with user/group "myuser users" and the file gets created with "myuser myuser". (Why?)

```
drwxr-xr-x 1 myuser users 3 Nov 28 10:33 some.directory
-rw-rw-r-- 1 myuser myuser 48477071 Nov 28 10:06 some.file.ABC.mp4

```

When I access the new file from the Mac and try to change its name, strange things happen:

* If I delete the uppercase "C" from the name, I succeed.
* If I add a lowercase "c" back to the name, sometimes it accepts the lowercase "c" and sometimes it changes it back to an uppercase "C". (Why?)
* If I change the uppercase "ABC" to a lowercase "abc", I get a permissions error. (Why?)

During the successful changing of the name, the permissions get changed:

```
-rw-rw-r-- 1 myuser myuser 48477071 Nov 28 10:06 some.file.ABC.mp4
-rwxrwxr-x 1 myuser myuser 48477071 Nov 28 10:06 some.file.ABC.mp4 (Why?)

```

Similar, but slightly different things happen when changing the name of the directory:

* If I add the uppercase "A" to the name, I succeed.
* If I change the uppercase "A" to uppercase "E", I succeed.
* If I change the uppercase "E" to a lowercase "e", it accepts it, but changes it back to uppercase "E".
* If I again change the uppercase "E" to a lowercase "e", I get a permissions error. (Why?)

During the successful changing of the name, the permissions get changed:

```
from: drwxr-xr-x 1 myuser users 3 Nov 28 10:33 some.directory
to: drwxrwsr-x 1 myuser users 3 Nov 28 10:33 some.directoryE  (Why?)

```

Some of this may be caused by SMB. The relevant parts of my smb.conf:

```
[Pi2_Data]
path = /media/Data
valid users = @users
force group = users
create mask = 0775
force create mode = 0775
security mask = 0775
force security mode = 0775
directory mask = 2775
force directory mode = 2775
directory security mask = 2775
force directory security mode = 2775
browseable = yes
writeable = yes
guest ok = no
read only = no

```

Thanks for any insight.