Help with script giving error message when ran through Self Service

jhuls
Contributor III

Any chance someone can explain to me why this gives me an error code of 1 on the lines that executes mysides towards the end? I won't proclaim to be the greatest scripter around so if you want to offer suggestions, I'm all ears.

Basically what this script does is a few things...

  1. It executes another policy that installs mysides which is an application I found that lets me automate adding a shortcut to the Finder sidebar.

  2. It mounts a share for the user.

  3. Lastly, now is when it creates the shortcut I mentioned above. On this line is where I get the error. It still does what it is suppose to do so I can't figure out why I'm getting the error message.

This is being run out of Self Service so I get an error message telling me that it cannot install item. Like I said though it is doing what it's suppose to do and if I run it manually in a shell, it works fine without an error. I can't help but think it's a Self Service bug at this point but thought I would ask the experts here because frankly I don't consider myself one when it comes to scripting. Thanks!

#!/bin/sh

Current_User=$(stat -f%Su /dev/console)
Home_Drive=/Volumes/Home
Current_Domain_Group="FakeDomainDomain Users"

Share_Path="smb://fakeserver.fakeserver.com/home2$/$Current_User"

sudo jamf policy -event addHomeDriveFinderToSidebar

mkdir $Home_Drive

chown $Current_User:"$Current_Domain_Group" $Home_Drive

sudo -u $Current_User mount -t smbfs $Share_Path /Volumes/Home

sudo -u $Current_User /usr/local/bin/mysides add $Current_User file://$Home_Drive

exit
6 REPLIES 6

chris_kemp
Contributor III

Try adding a zero to the exit line:

exit 0

apizz
Valued Contributor

I'd also put quotes around "/Volumes/Home" for your Home_Drive variable

jhuls
Contributor III

@chris.kemp I gave that a try. The first time I ran it, it crashed Self Service but the second and third times have ran perfectly. I'm not sure what to think about that one.

@aporlebeke Thanks! The current method seems to be working fine but I'll make the change if that's considered best scripting practices.

apizz
Valued Contributor

If you're setting the output of a command as a variable you can use $( command ) or command

For setting a particular string to a variable you definitely want to use quotes like you do for your 3rd variable - "stringy string"

rderewianko
Valued Contributor II

Speaking of best practices... shellcheck.net

apizz
Valued Contributor

cool beans @rderewianko like that a lot