Posted on 06-26-2015 02:09 AM
Hello everyone, I noticed there are already several open/closed discussions regarding network volume mounting with JSS
I tried the script included in the Resource Kit but I don't like the idea of having a launch agent left on the client side, so I tried to put together something myself
Environment is an AD domain with network users
The very rough script below grabs the full path from JSS parameters, so that you can add several shares within a single policy
It works when executed locally (hard coding the path) but has issues with a login policy because it runs as the root user (predictable), not the logged one
The result is network shares are correctly being mounted but they're not accessible (locked), likely because the mountpoint has wrong permissions
I tried gathering the network user at login with
loggedInUser=/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'
But could not make it work within the script
Any help from the scritpting gurus out there will be highly appreciated...
Thank you all
Carlo
#!/bin/bash
# Automatic volume mounting with a valid kerberos ticket
# Network shares parameters are passed by Casper
# Variables being used are $4 to $11
##Cycling with variables passed by JSS for each volume to be mounted
for var in "$4" "$5" "$6" "$7" "$8" "$9" "$10" "$11"
do
if [ "$var" != "" ]; #check if Casper parameter is empty
then
#Gather path to the network shares
SHARE=${var:18} #Get network share
SHARE=${SHARE%/} #Delete forward slash
HOST=${var:6:11} #get host name
MOUNT=${var:6} #Share to be mounted
PROTOCOL=${var:0:3} #Protocol being used (afp or smb from full path declared in JSS)
VOL="/Volumes/$SHARE" #mountpoint from the share
ping -t 1 -c 1 $HOST > /dev/null
if [[ $? -eq 0 ]] #check if host is reachable with ping
then
if [ "$PROTOCOL" == "afp" ]; #check protocol being used
then
mkdir $VOL #create mountpoint for afp
mount_afp –i "afp://;AUTH=Client%20Krb%20v2@$MOUNT" $VOL #Mount Volume afp
else
mkdir $VOL #create mountpoint for smb
mount -t smbfs "smb://$MOUNT" $VOL #Mount Volume smb
fi
fi
fi
done
Posted on 06-26-2015 02:14 AM
@carlo.anselmi I have blogged my script here.
Posted on 06-26-2015 03:09 AM
For the username part of the script, I use this:
loggedInUser="$3"
if [ -z "$username" ]; then # Checks if the variable is empty (user running script from Self Service)
loggedInUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`
fi
This can then be used as a login script ($3), and if it is being triggered another way, it will check if the variable is empty and if it is, use "/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'"
For the actual drive mounting, I have moved away from the mount_afp and mount commands. For years I had trouble with the creation of the mount point, sometimes it would work, sometimes it would get left behind and then fail next time it tries to run, sometimes its owned by a different user so the next user can't mount the share, etc.
Instead I use an osascript command:
# Mount the drive
mount_script=`/usr/bin/osascript > /dev/null << EOT
tell application "Finder"
activate
mount volume "$PROTOCOL://${HOST}/${SHARE}"
end tell
EOT`
Hope this helps in your script.
BTW, the whitespace and alignment of the osascript command has to be as it appears above, otherwise it doesn't work (just in case).
Posted on 06-29-2015 03:36 AM
Hi @bentoms + @davidacland,
many thanks for your suggestions, I'll try perfecting my script with them
Have a great week
Carlo