Posted on 05-06-2015 06:14 PM
Hi all,
Trying to get Casper to run a script on the user login which needs to create a blank DMG and place it in the logged in user's Pictures folder in their profile. This is the script I've got:
hdiutil create -size 75m -fs HFS+ -volname Adobe_LightRoom ~/Pictures/Adobe_LightRoom.dmg
Once the user logs in, I check the logs and get the following error message:
Executing Policy Create Adobe LightRoom5 volume...
Running script Create Adobe LightRoom file...
Script exit code: 1
Posted on 05-06-2015 06:53 PM
Best way I have found to do this is with a LaunchAgent that calls the script and then tidies up after it has run.
Posted on 05-06-2015 08:03 PM
~ probably unreliable as a method of getting currently logged in user.
Posted on 05-06-2015 08:14 PM
~ doesn't parse correctly when run from Casper I believe.
You need to specify the user.
There are a couple of methods to do it, I prefer using the LaunchAgent myself, then ~ should parse correctly.
Another way would be to use a variable to define the user
e.g.
user=`ls -l /dev/console | cut -d " " -f 4`
hdiutil create -size 75m -fs HFS+ -volname Adobe_LightRoom /Users/"$user"/Pictures/Adobe_LightRoom.dmg
Edit:
Actually, you should be able to use $3 if it's a log in policy. $3 is a pre-defined variable of the current user, I believe this only works either on log-in or from Self Service..
hdiutil create -size 75m -fs HFS+ -volname Adobe_LightRoom /Users/"$3"/Pictures/Adobe_LightRoom.dmg
Posted on 05-07-2015 01:05 AM
Thanks for the help everyone. Ended up having to write up some Applescript and get it to run via the LaunchAgent
Posted on 05-07-2015 06:22 AM
When I need to perform operations like this I'd generally do something along the lines of:
CURRUSER=$(who | grep console | head -n 1 | awk '{print $1}')
sudo -u "$CURRUSER" hdiutil create -size 75m -fs HFS+ -volname Adobe_LightRoom /Users/"$CURRUSER"/Pictures/Adobe_LightRoom.dmg
This actually runs the hdiutil command as the user and so deals with permissions on the DMG at the same time.
Posted on 05-07-2015 06:09 PM
When I run that script in terminal as the logged on user, it works however I run that script as a logon script via casper as still get 'Script result: hdiutil: create failed - Invalid argument'
Posted on 05-07-2015 06:21 PM
I tested my post above and can confirm using $3 does work.
Creating a script with
hdiutil create -size 75m -fs HFS+ -volname Adobe_LightRoom "/Users/$3/Pictures/Adobe_LightRoom.dmg"
Then adding it to the policy with a login trigger does successfully create the .dmg
Posted on 05-07-2015 10:30 PM
So it does seem to work when I try to create that DMG on the Shared folder under Users but not working for the user's Pictures location as I have that folder as well as Movies, Music, etc all Sym linked to an AFP share.
Why would that be the case? Could it be related to permissions?
Posted on 05-11-2015 01:39 AM
@SMC I was wondering if 'hditutil' has a problem with symlinks, but then I suddenly thought about that AFP share.
How is this being mounted and when? I suspect that it is not yet mounted by the time the script runs and therefore the symlink is broken.
You'd need to test for the share being mounted before trying to create the DMG
Posted on 05-11-2015 04:26 PM
You're definitely correct on that one! I'm thinking I might have to incorporate that into my Applescript LaunchAgent.
Posted on 05-12-2015 01:23 AM
@SMC Out of curiosity, why are you symlinking them? From experience symlinks can confuse the hell out of some badly coded applications (Avid for instance, although I have not tested it recently). Layer this on top of the file system being a network one and possibly 'going away' unexpectedly and you may have a slightly painful experience on your hands.
Is this a newly architected solution? Any reason not to just use network or synced mobile homes instead?
Posted on 05-12-2015 04:07 PM
@danf_burberry I wanted to keep Microsoft and Mac data separate and I also don't have the file server capacity to support the new Mac environment data storage. I had to use an existing NAS which I've mounted as a iSCSI LUN drive to the mac server and share from that.
When considering the end users are high school students, I wanted to make the setup as easy as possible and reminding students to continually backup their data manually is pretty much out of the question.
I did initially have a few issues with some applications but I've gotten around these and so far so good for the main applications that the students use.
Posted on 05-13-2015 01:10 AM
@SMC What happens when they use the machine offsite/offnetwork and fire up say Lightroom or iPhoto?
Posted on 05-13-2015 12:26 PM
Anytime I need to run something as the user from Casper I use the below framework. It's worked for me in almost every case.
loggedInUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`
declare -x LoginWindowPID="$(/bin/ps -axww | /usr/bin/grep loginwindo[w] | /usr/bin/awk '/console/{print $1;exit}')"
/bin/launchctl bsexec "${LoginWindowPID:?}" /usr/bin/sudo -u "$loggedInUser" COMMAND GOES HERE
Posted on 05-13-2015 03:39 PM
@danf_burberry The lab machines are always connected to the network either via Ethernet or wireless.