FIX: newperms working with spaces in folders


Recommended Posts

Hi all,

 

I got quite frustrated when the newperms script didn't work when calling it manually to assign new permissions on a folder that contained spaces so I decided to fix it. I use SABnzbd extensively and a few other apps that create files on the array and they're always being created as root with messed up permissions. I couldn't use the new perms script since anything with a space in it would fail.

 

Well, all is good, here it is.. Quite simple fix really.

 

#!/bin/bash

# Usage: newperms [dir]
# Recursively changes the ownership and permissions of the directory and all files/subdirs
# within the directory.  If dir is omitted, then operates on /mnt/cache and /mnt/disk*
# This was created to fix ownership/permissions for unRAID version 5.x

function process {
  if [ -e "$1" ] ; then
    echo "processing $1"
    echo "... chmod -R go-rwx $1"
    chmod -R go-rwx "$1"
    echo "... chmod -R u-x $1"
    chmod -R u-x "$1"
    echo "... chmod -R g+u $1"
    chmod -R g+u "$1"
    echo "... chmod -R ug+X $1"
    chmod -R ug+X "$1"
    echo "... chgrp -R users $1"
    chgrp -R users "$1"
    echo "... chown -R nobody $1"
    chown -R nobody "$1"
  fi
}

if [ -n "$1" ] ; then
  process "$1"
else
  process /mnt/cache
  for disk in /mnt/disk* ; do
    process $disk
  done
fi

 

Link to comment

Actually the character between owner and group does not matter if it's ":" or ".". In Slackware distros, such as unRAID the "." works perfectly fine because of backwards compatability. Even though "." is still supported, it is deprecated and considered to be bad form to still use it.

 

Directly from the "chown" invocation info pages

  Some older scripts may still use `.' in place of the `:' separator. POSIX 1003.1-2001 (*note Standards conformance::) does not require support for that, but for backward compatibility GNU `chown' supports `.' so long as no ambiguity results.  New scripts should avoid the use of `.' because it is not portable, and because it has undesirable results if the entire OWNER`.'GROUP happens to identify a user whose name contains `.'.

Link to comment

The correct syntax would be

 

chown -R nobody:users "$1"

 

note it's a ":" and not a "." that concatenates the user and the group.

 

Caveat, I'm new to unRAID so perhaps there are quirks I am unaware of.

 

Not true. Using a '.' works just fine, in fact any character would do the trick to split the two parts.

I've been using '.' for 10+ yeats in Unix/Linux.  I always use this format to avoid also using chgrp command.

 

 

 

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.