Mapping Home Folder

pkoch
New Contributor

I am wondering how everyone is handling mapping home folders in Yosemite and up. Previously the school used a custom Package that would run a script to mount student home folders. This broke after upgrading to Sierra.

Currently I have the option "Use UNC path from Active Directory to derive network home location" enabled. This puts the globe in the Dock and when they click on the globe, it will mount their Home folder on the Desktop. There are 2 issues with this currently. First, it mounts the root path of their home folder, so instead of mapping fileserverstudentsjsmith, it is mapping fileserver. I found a script to just hide this mount so that isn't as big of a deal. Second, every time the Macbook is restarted, the mount is missing from the Desktop and the student has to click the globe again and then it will reconnect and show up on the Desktop. Is there a way to just make that mount once and re-connect every time the student logs in rather than them having to click the globe and then go to the drive?

7 REPLIES 7

Look
Valued Contributor III

I use a script Casper on a login trigger that reads the location from AD and then mounts the drive with an applescript call. The other common way is to have a launch agent that does the same thing.

pkoch
New Contributor

Can you share the script with me by chance? Just so I can get idea of how to do this.

Look
Valued Contributor III

Sure.
If you don't pass it any share path it defaults to the users home drive.
I normally run a seperate policy for each share to be mapped and use the policy scoping to determine who it should run for.
Feel free to use as you please.
If you search around there are a few other ways to do this as well, I just like keeping it all within Casper personally especially as you can also make it available in Self Service to allow people to remount any lost ones or after waking the machine from being at home.

#!/bin/bash
#2017 Version Samuel Look
#All care no responsibility
#Mounts the requested share if it doesn't already exist if left blank it will attempt to mount AD SMBhome
#Accepts shares in the form smb://server/share
#Intended to be run as a Login policy from Casper on AD bound machines only and has only been tested in this context.

##### Start seperate process #####
(

##### SUBROUTINES #####

Share_Path_Valid() {
if [[ -z "$Share_Path" ]]; then
Machine_Domain=$(dscl /Active Directory/ -read . SubNodes | awk '{print $2}')
Share_Path="$(dscl "/Active Directory/$Machine_Domain/All Domains" -read /Users/$Current_User SMBHome | awk '!/is not valid/' | sed -e 's/SMBHome: /smb:/g' -e 's/\///g')"
fi
if [[ "$Share_Path" ]]; then
logger "Sharemount:$Share_Name Path check PASS $Share_Path"
return 0
else
logger "Sharemount:$Share_Name Path check FAIL"
return 1
fi
}

#####

User_Ready() {
Loop_End=$((SECONDS + 60))
Current_User=$(stat -f%Su /dev/console | awk '!/root/')
while [[ -z "$Current_User" ]] && [[ $SECONDS -lt $Loop_End ]]; do
sleep 10
Current_User=$(stat -f%Su /dev/console | awk '!/root/')
done
if [[ "$Current_User" ]]; then
logger "Sharemount:$Share_Name User check PASS $Current_User"
return 0
else
logger "Sharemount:$Share_Name User check FAIL"
return 1
fi
}

#####

Finder_Ready() {
Loop_End=$((SECONDS + 60))
while [[ -z "$(ps -c -u $Current_User | awk /CoreServicesUIAgent/)" ]] && [[ $SECONDS -lt $Loop_End ]]; do
sleep 10
done
if [[ "$(ps -c -u $Current_User | awk /Finder/)" ]]; then
logger "Sharemount:$Share_Name Finder check PASS"
return 0
else
logger "Sharemount:$Share_Name Finder check FAIL"
return 1
fi
}

#####

Not_Mounted() {
if [[ -z "$(mount | awk '/'$Current_User'/ && //'$Share_Name' /')" ]]; then
logger "Sharemount:$Share_Name Mount check PASS $Share_Name"
return 0
else
logger "Sharemount:$Share_Name Mount check FAIL already mounted"
return 1
fi
}

#####

Mount_Drive() {
True_Path=$(echo $Share_Path | sed 's//////'$Current_User'@/g')
logger "Sharemount:$Share_Name Attempting to mount $True_Path"
sudo -u $Current_User osascript -e 'mount volume "'$True_Path'"'
}

##### START #####

Share_Path=$4
Share_Name="$(echo $Share_Path | awk -F"/" '{print $NF}')"

if User_Ready && Finder_Ready && Share_Path_Valid && Not_Mounted; then
sleep 4
Mount_Drive
else
logger "Sharemount:$Share_Name Conditions not met to attempt drive mounting $Share_Path"
fi

##### End seperate process #####
) &

##### FIN #####

kerouak
Valued Contributor

We use a launchagent and script:

I packaged these 2 files:

  1. Put this plist file in /Library/Launchagents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN
http://www.apple.com/DTDs/PropertyList-1.0.dtd>
<plist version="1.0">
<dict> <key>Label</key> <string>login_test</string> <key>ProgramArguments</key> <array> <string>osascript</string> <string>/Library/Mount Users Home Folder.scpt</string> </array> <key>RunAtLoad</key> <true/>
</dict>
</plist>

  1. Put this script in /Library:

set loggedInUser to do shell script "whoami"
set accountType to do shell script "dscl . -read /Users/" & loggedInUser & " | grep UniqueID | cut -c 11-"
set nodeName to do shell script "dscl . -read /Users/" & loggedInUser & " | awk '/^OriginalNodeName:/,/^Password:/' | head -2 | tail -1 | cut -c 2-"
set ADGroups to do shell script "dscl " & quoted form of nodeName & " -read /Users/" & loggedInUser & " | awk '/^dsAttrTypeNative:memberOf:/,/^dsAttrTypeNative:msExchHomeServerName:/'"
set ADHome to do shell script "dscl " & quoted form of nodeName & " -read /Users/" & loggedInUser & "| grep SMBHome: | cut -c 10- | sed 's/\///g' "

if accountType is less than 1000 then tell me to quit
end if

try

mount volume "smb:" & ADHome

on error

end try

Upload package to JAMPro , create a policy for deployment.

Done

Mudalige
New Contributor III

@kerouak Hey mate can you able to explain how do you create package ? did you bundled up launch agent and the script into one Package through composer ?

kerouak
Valued Contributor

@Mudalige Well, I use something different, but, yeah, you could bundle it all up in 1 using composer.
G'Luck

Mudalige
New Contributor III

@kerouak Thanks mate. I will try