Monday, 14 November 2011

Getting NHR to work on 10.6 and later

After a lot of grumbles, it turns out that there is a great need here to have NHR working again, specifically to redirect the ~/Library/Caches folders of the Active Directory networked users.

I've stated on many previous occasions when it hasn't worked with:

So I've finally got around to looking into why NHR hasn't been working with OS X 10.6.6.

So I installed it on a nice little MacBook Pro. Doesn't work. First I thought I'd check it installed alright and in Console I saw no errors.

Next I checked permissions and found I couldn't look in the folder /etc/hooks. I also couldn't run the script login.hook without using 'sudo'.

I logged in under root, reset the permissions so that everyone could read and write:
sudo chmod 777 /etc/login.hook
sudo chmod 777 /etc/logout.hook
sudo chmod 777 /etc/hooks
sudo chmod 777 /etc/hooks/*

Still wouldn't work.

When I tried to run the login.hook and Llcleanbasic.hook files it came up with:
LoginHook: Executing /etc/hooks/LIcleanbasic.hook...
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.
After looking in the Llcleanbasic.hook file I found the first line of script ran as follows:
Local=`dscl . -list /Users |grep -x $1`
Typing this in the terminal comes up with the same message, which persuades me that it is this which is throwing the whole script off. Basically this part of the script and an if statement below it, finds out if the user is listed in the local users list. It must have changed in the later versions of OS X.

I decided to not have this part of the script run as to me it doesn't matter if local users also have the script running as I'm only going to have it affect the Caches folder. As such, I commented it out as well as the if statement which ran after it. This is what it ended up looking like:

#Local=`dscl . -list /Users |grep -x $1`

#This script will re-direct several the Caches and Fonts folders from a user's network home location to the local machine to help with performance.

#if [[ "$1" == "$Local" ]]; then
#        exit 0

After doing this it ran perfectly!!!!

A couple of things left to do:

  1. Get the logout script to work
  2. try is running it with it's original permissions to see if that also helped.

So, I also had to change the logout script accordingly as well, commenting out the Local='dscl......... and the if statement below it. After this it all worked perfectly.

Also, a point to note is that when logged in as anyone other then root, when you add login and logout hooks it is important to understand user hooks, and all user hooks (not the correct terminology but hopefully describes what I want).

So, when logged in NOT as root, if you use the command:
defaults write LoginHook /private/etc/login.hook 

it'll only give this user the hook. To do it system wide.
sudo defaults write LoginHook /private/etc/login.hook 

No comments:

Post a Comment