View previous topic :: View next topic |
Author |
Message |
mazes80 n00b


Joined: 24 Feb 2011 Posts: 11 Location: toulouse - france
|
Posted: Tue Apr 12, 2011 10:27 pm Post subject: Per directory umask with bash |
|
|
Add this to your .bashrc
Code: | function cd {
builtin cd "$@"
[ -f ~/.umaskrc ] && umask $(awk 'BEGIN {pwd=ENVIRON["PWD"]; a=length(pwd); cmax=0} {if($1==pwd) {MASK=$2;exit}; c=length($1); if(c>a) {next}; if(substr(pwd,0,c)==$1 && c > cmax) {cmax=c; MASK=$2}} END {print MASK}' ~/.umaskrc) > /dev/null
} |
Edit .umaskrc
Code: | #path #umask
/ 022 #default umask
/my/website/directory 022
/dev/team/shared/data 026
/plan/to/conquer/world 066
/umask/from/the/hell 666
|
Rules for setting the umaskrc
There should always be a default umask (associated with /)
Entries should never end with / (do not set /tmp/ but /tmp, only the "root entry" can end with /).
It's better to keep subdirectories ordered, but not mandatory
/
/home/user
/home/user/public_html
Use cases
I have paranoid umask for my root user.
However when I compile the latest kernel, I need to have a softer umask. Else emerge will fail to compile some modules because some files aren't readable for portage.
When I edit as root a new config file in /etc, I hope most of the times that all users can read it.
I sometimes use apache with a per-user website, each time I go to this directory I need to have a less agressive umask
I use this since a while, in some situations, it is really helpful. And less complicated than using ACL for the same purpose.
Limitations
Assume you want to copy a file to your public_html, if you want to take benefits from the per - directory umask, you have first to move to the directory, then copy the files from the old directory to the current directory. That's not the case with ACL.
---------------------------------------------------------------------------------------------------------------------------------------------
gawk gawk gawk |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|