Skip to main content

We are trying to redirect locally created home folders on our 10.10 (Yosemite) workstations to a shared folder we have setup. I have attached the script we are trying to use below. The folder creation part of the script works fine. I am getting “Access Denied” when trying to delete the user folders and then trying to create the symbolic link to the share. I changed the variable $USER to $3 when pushing out through JSS.

I remember doing this with MCX in the days of OS X 10.6 but I know this is no longer supported in 10.10. Can anyone assist?

!/bin/sh

-------------- Define Directories ----------------

MYHOMEDIR=“/Volumes/HomeFolders/2016-2017/$USER”
MYDOCDIR=“/Volumes/HomeFolders/2016-2017/$USER/Documents”
MYPICDIR=“/Volumes/HomeFolders/2016-2017/$USER/Pictures”
MYMUSDIR=“/Volumes/HomeFolders/2016-2017/$USER/Music”
MYMOVDIR=“/Volumes/HomeFolders/2016-2017/$USER/Movies”
MYDESDIR=“/Volumes/HomeFolders/2016-2017/$USER/Desktop”
MYLIBDIR=“/Volumes/HomeFolders/2016-2017/$USER/Library”

----------------- Checking Folders ---------------

if [ -d "$MYHOMEDIR" ]; then
echo "$MYHOMEDIR is Available!"
else
mkdir /Volumes/HomeFolders/2016-2017/$USER
fi

if [ -d "$MYDOCDIR" ]; then
echo "$MYDOCDIR is Available!"
else
mkdir /Volumes/HomeFolders/2016-2017/$USER/Documents
fi

if [ -d "$MYPICDIR" ]; then
echo "$MYPICDIR is Available!"
else
mkdir /Volumes/HomeFolders/2016-2017/$USER/Pictures
fi

if [ -d "$MYMUSDIR" ]; then
echo "$MYMUSDIR is Available!"
else
mkdir /Volumes/HomeFolders/2016-2017/$USER/Music
fi

if [ -d "$MYMOVDIR" ]; then
echo "$MYMOVDIR is Available!"
else
mkdir /Volumes/HomeFolders/2016-2017/$USER/Movies
fi

if [ -d "$MYDESDIR" ]; then
echo "$MYDESDIR is Available!"
else
mkdir /Volumes/HomeFolders/2016-2017/$USER/Desktop
fi

if [ -d "$MYLIBDIR" ]; then
echo "$MYLIBDIR is Available!"
else
mkdir /Volumes/HomeFolders/2016-2017/$USER/Library
fi

ECHO ----------------- Redirecting Folders ---------------

Wait for OS X to Create Local Homes

sleep 4

rm -Rf "/Users/$USER/Documents"
ln -sFfh "/Volumes/HomeFolders/2016-2017/$USER/Documents" "/Users/$USER"

rm -Rf "/Users/$USER/Desktop"
ln -sFfh "/Volumes/HomeFolders/2016-2017/$USER/Desktop" "/Users/$USER"

rm -Rf "/Users/$USER/Pictures"
ln -sFfh "/Volumes/HomeFolders/2016-2017/$USER/Pictures" "/Users/$USER"

rm -Rf "/Users/$USER/Movies"
ln -sFfh "/Volumes/HomeFolders/2016-2017/$USER/Movies" "/Users/$USER"

rm -Rf "/Users/$USER/Music"
ln -sFfh "/Volumes/HomeFolders/2016-2017/$USER/Music" "/Users/$USER"

rm -Rf "/Users/$USER/Library"
ln -sFfh "/Volumes/HomeFolders/2016-2017/$USER/Library" "/Users/$USER"

ECHO ----------------- Completed Script -------------------

HI Paul,

I get it working on the local admin account with the bash script manually and it mounts everything automatic.
now i tried to doit on a normal user and I get the error: “You are not in the sudoers file

If I add the script in iHook it hangs because I guess the "normal" user is not allowed to run the command.

I added chmod +x plus chmod 777

any idea how to solve that problem :)? We are getting nearer ;-)


Hi Christian,

I've never used iHook, so it may not run under the root context as LoginHooks do.

Try removing the

sudo -u $user

bit and try again?


okay!

Manually trying the script with bash scriptname everything is working wonderful.
Now when I put it on Login Hook, it puts the Folders to the Finder, but it's not mounting the volume.. i tried to put it in as the last script but it didn't help.
I guess it's executing it to early.

How could we handle that, running the whole thing with an apple script?

something additional: Can I add an other line to the script that if a admin logs in it's not mounting anything?
if thats possible, what should I do.

or maybe there are other/better possibilities to run the .sh script instead of iHook

Thanks for your help. very very kind!

Cheers Christian


all good! I made a LaunchAgent service with the plist file, everything works like a charm now!

Just would be cool if we could make this login for all users except: User: admin for example..

can we extend that script for that?

thanks and cheers Christian


Hi Christian,

Excellent news!

We can skip admins, no problem. After the script works out who the user is, but before the mount line add;

exclude=("root" "admin" "ladmin")

#Check to see if user is in the exclude list, if so exit
for x in "${exclude[@]}"; do
    if [ "$x" == "$user" ]; then
        logger "$user is a local user. Exiting..."
        exit 0
    fi
done

Just amend the exclude array to any user you don't want to run this for.

Paul


Okay, Will check that out. Thank you.

It looks like sometimes the script is still executing to early. Is there a option in LaunchAgent so that it loads the script after a few seconds later?

I tried doing sleep in the script it self, but doesn't seem to help, as we use iHook for some other things aswell.

Or would you recommend doit by automator or apple script or so?

Christian


Hi Paul,

I've made an automator workflow and let it start when the User Logs in. That also works!

BUT: When I create a brand new User on the server which also has to creates his localhome for te first time on the Mac,
than the automator doesn't run. I've tried with sleep of 10 + 20seconds but it doesn't help. I can see the automator script in the start items on the User already the first time.. (i made a profile for that). Of course it works when I klick on the automator app, but I would like it all automatically :-)

But it's not running it...and because students always change their workstation I would need a solution for that..
any suggestions for this issue?

Thanks Paul
Cheers


Correction!!!

I got it working now! the .plist file in LaunchAgent had a Permission Issue, i made 777 but it has to have 644!
Now everything is fine and also with brand new users it's working ;-)

thanks a lot u made my day :-)


Awesome news!


HI psmac

any idea to get this working:

I would like to exclude all accounts with this script from: dscl localhost -list /Local/Default/Users

i tried but can't gett it working.
many thanks for your help


Hi Christian,

If you change your exclude line to the below it should work;

exclude=(`dscl localhost -list /Local/Default/Users`)

Let me know how you get on!

Paul


Hey Man !!!!

I was very close with:

exclude=`dscl localhost -list /Local/Default/Users`

I forgot the ( )

Thanks!

I own you something! can I make a donation?


you can also use the below to exclude system accounts. It's worth noting that if you have users who have usernames starting with an underscore this will exclude them too, but hopefully that won't affect too many people.

exclude=(`dscl localhost -list /Local/Default/Users | grep -v ^_`)

No worries Christian, hope it helps mate.

Donations to the beer fund of your choice.