AFP Shares in Self Service

TomDay
Release Candidate Programs Tester

My goal is to have users open a share via Self Service and all the digging I have done on JAMFnation point to it being pretty easy but I'm running in to road blocks. I've been fighting this off and on for a couple of weeks and need to lean on the Nation for some help! Shares in question are AFP shares, users must auth to them via their AD credentials which get passed upon logon to the computer. I tried the script from @franton][/url (thank you sir, its been very helpful) https://github.com/franton/Mount-Network-Share but I get an error "unknown user: /usr/sbin/jamf". Can anyone see my error or recommend an alternative way to accomplish this? My code is below:
#!/bin/bash

# Script to mount a specified server and share For Sedna Shares.
# This should use the AD credentials to log in.

# Author :r.purves@arts.ac.uk

# Version 1.0 : 03-27-2014 - Initial Version

# Parameters needed are as follows:

# 3 - Current username (supplied by Casper so we don't worry about this one)
# 4 - Server FQDN address
# 5 - Sharename
# 6 - Share type

# Check to see if the parameters have been populated properly and fail if not.

if [ "$4" == "plexmini.sch.org" ]; then echo "Error: Missing server name in policy. e.g. inf-server.arts.local" exit 1
fi

if [ "$5" == "PodCast" ]; then echo "Error: Missing share name in policy." exit 1
fi

if [ "$6" == "afp" ]; then echo "Error: Missing share type in policy. Valid types currently are: afp / smb" exit 1
fi

# All done, finally mount the share

sudo -u $3 /usr/sbin/jamf mount -server $4 -share $5 -type $6

8 REPLIES 8

TomDay
Release Candidate Programs Tester

Oh and if I go to the share in question in Finder, I get prompted for my password and I get right on to the share.

TomDay
Release Candidate Programs Tester

Quick update:

If I test this script manually with "sudo -u tom /usr/sbin/jamf mount -server plexmini.sch.org -share PodCast -type afp" it works fine with the message "Mounting to /Volumes/PodCast 1... Mounted file server ". Then testing to see if variables are working, I try "sudo -u $3 /usr/sbin/jamf mount -server plexmini.sch.org -share PodCast -type afp" but get the error "unknown user: /usr/sbin/jamf"

mpermann
Valued Contributor II

I don't think you $3 variable is set as the currently logged in user. I've seen other threads where people have used the following command to get the currently logged in user.

CurrentUser=/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'

Have you tried echoing the variables you are using in your policy so you can look at the log to see what those variables are actually set to? I think I remember reading something about policies executing as root in Self Service and needing to get the current logged in user using a command like the above one to get it rather than relying on $3.

TomDay
Release Candidate Programs Tester

@mpermann I'll work on the echo, I'm a shell newbie. Thank you

TomDay
Release Candidate Programs Tester

@mpermann I'll work on the echo, I'm a shell newbie. Thank you

TomDay
Release Candidate Programs Tester

I wound up taking $3 out of the equation by using user=ls -l /dev/console | cut -d " " -f 4 instead. Turns out my other variables don't pass properly either. If I use the following it works fine, but not with variables sudo -u $user /usr/sbin/jamf mount -server plexmini.sch.org -share PodCast -type afp

#!/bin/bash

# Script to mount a specified server and share For Sedna Shares.
# This should use the AD credentials to log in.

# Author :r.purves@arts.ac.uk

# Version 1.0 : 03-27-2014 - Initial Version

# Parameters needed are as follows:

# 3 - Current username (supplied by Casper so we don't worry about this one)
# 4 - Server FQDN address
# 5 - Sharename
# 6 - Share type

# Check to see if the parameters have been populated properly and fail if not.

user=ls -l /dev/console | cut -d " " -f 4

if [ "$4" == "plexmini.sch.org" ]; then echo "Error: Missing server name in policy. e.g. inf-server.arts.local" exit 1
fi

if [ "$5" == "PodCast" ]; then echo "Error: Missing share name in policy." exit 1
fi

if [ "$6" == "afp" ]; then echo "Error: Missing share type in policy. Valid types currently are: afp / smb" exit 1
fi

# All done, finally mount the share

sudo -u $user /usr/sbin/jamf mount -server $4 -share $5 -type $6

psherman
New Contributor

Hi Tommyday, did you ever get this to work?

TomDay
Release Candidate Programs Tester

Sorry @psherman this fell off the radar as the need was very low and other projects were of more importance, combined with the decreased use of file shares, I am no longer really working on getting this to work.

-Tom