Posted on 03-04-2013 05:23 AM
I am trying to be nice and use jamfhelper to allow users to postpone updates and such. I have a beautiful script that runs great except for one thing. I am doing some logic to see if they have a locally stored copy of the image I want to use in the message.
if [ -f /Library/Application Support/company/Logo.png ]; then
logo="/Library/Application Support/company/Logo.png"
else
logo="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/Resources/Message.png"
fi
and then I call the $logo in the jamfhelper script...
`"$jh" -countdown -timeout 60 -showDelayOptions "0, 90, 300, 900" -icon "$logo" -windowType $wt "$lock" -title "$title" -heading "$heading" -description "$MSG" -button1 "$button1" -button2 "$button2" -defaultButton 1 -cancelButton 2`
My problem is that the logo will NEVER show up. I have tried almost every way I know of to quote, bracket, and pull the value in there, just short of putting it in hardcoded. It never works! The crazy part is that I have even tried echoing the $logo value after and then copying and pasting it into a jamfhelper command, and it works!
The only thing I can see that MIGHT be causing the issue is that the logo path can not be quoted. Has anyone run into this issue before? Does anyone know or is currently using a way to have a dynamic logo chosen in their scripts without putting it into one of the passed variables (I would love to have a short variable option such as "company" or "update" or "firefox" to have the icon dynamically change, and this is standing in my way!!!)
I am aware of cocoadialog and I have used it, but this is question is about a jamfhelper. (just putting that out there, as almost all jamfhelper request for help come back with "user cocoadialog")
Here is the code you can use to test with (or use), it works, but the logo/icon is hard coded. At least it will be up here for others to use if they want (thanks to all who I have borrowed from, wish I had written down your names as I was working on this).
#!/bin/bash
jh="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"
title="$4" #4
heading="$5" #5
description1="$6" #6
description2="$7" #7
button1="Okay"
# Postpone is really whatever the frequency of the policy is.
button2="Postpone"
wt="$8" #8
## icon piece not working right now, issue with quoted forms in jamfhelper calls.
# if [ -f /Library/Application Support/company/logo.png ]; then
# logo="/Library/Application Support/company/logo.png"
# else
# logo="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/Resources/Message.png"
# fi
# This is the trigger you will have called on when the user clicks "Okay"
trigger="$9" #9
# Issue with spacing in combined test, so I throw in some mega spaces to get more space in the box.
spaces=" "
# if the windowtype is hud, then we'll want to lock it down (optional)
if [[ "$wt" == hud ]]; then
lock="-lockHUD"
else
lock=""
fi
# Combined Message on two lines, with spaces.
MSG=$( echo -e "$description1$spaces
$description2" )
# Action-thirty
####### SUPER IMPORTANT. I did not test the showDelayOptions with anything in the 200 seconds range, as it just isn't worth it to me.
return=`"$jh" -countdown -timeout 60 -showDelayOptions "0, 90, 300, 900" -icon /Library/Application Support/company/logo.png -windowType $wt "$lock" -title "$title" -heading "$heading" -description "$MSG" -button1 "$button1" -button2 "$button2" -defaultButton 1 -cancelButton 2`
## We have to get the length of the return so we can work with what jamfhelper gives us.
returnlen=$(echo $return | wc -c | sed -e 's/^ *//' -e 's/ .*//')
# Note: wc -c return an extra character... be mindful.
returnln=$(($returnlen-1))
# Knowing the first and last number is CRITICAL.
firstnum=$(echo $return | cut -c 1)
lastnum=$(echo $return | cut -c $returnln)
# left in for testing purposes.
#echo Number is $return
#echo Number length is $returnln
#echo First number is $firstnum
#echo Last numbers is $lastnum
if [ "$returnln" -eq "3" ] && [ "$firstnum" -eq "2" ] && [[ "$lastnum" -ne "0" && "$lastnum" -ne "2" ]];then
# echo "Three numbers, starting with a two and not ending with a 0 or a 2"
case $lastnum in
9) ## Exit
echo "Window Exited"
;;
0) ## Error
echo "Error Occurred"
;;
3) ## Time Out
echo "Window Timed Out with no buttons available"
;;
4) ## Cancel with delay option
echo "Cancel selected"
;;
5) ## Error
echo "Error Occurred"
;;
esac
## I had to add the 1,2,3 to the lastnum match as if you have the timer on it changes the values.
elif [ "$returnln" -eq "1" ] && [[ "$lastnum" -eq "0" || "$lastnum" -eq "1" || "$lastnum" -eq "2" ]];then
case $lastnum in
0)
echo "Button 1 selected"
jamf policy -trigger $trigger
;;
1)
echo "Button 1 selected"
jamf policy -trigger $trigger
;;
2)
echo "Button 2 selected"
;;
esac
elif [ "$returnln" -gt "1" ] && [[ "$lastnum" -eq "1" || "$lastnum" -eq "2" ]];then
# Get the time returned to the script.
timedelay=$(echo $return | cut -c 1-$(($returnlen-2)))
case $lastnum in
1)
echo "Button 1 selected with time delay of $timedelay"
sleep $timedelay
jamf policy -trigger $trigger
;;
2)
echo "Button 2 selected with time delay of $timedelay"
;;
esac
fi
I have always had problems pulling in the 10th and 11th variable. If anyone knows how to make them work properly, I would love to be able to use them as well. Otherwise I will most likely drop the window type option in place for a logo type option when I figure out the logo issue.
- Chris
P.S. I added all the comments on the web form, so it should work. If it doesn't I'll fix it.
Posted on 03-04-2013 06:20 AM
chris, try quoting positional parameters > 9 with brackets: "${10}"
it would probably be easier to manage if you keep the arguments below 10. that's an indicator you might want to look at passing data in a different way.
reference:
http://tldp.org/LDP/abs/html/othertypesv.html
http://stackoverflow.com/questions/4912733/how-to-handle-more-than-10-parameters-in-shell
Posted on 03-04-2013 06:49 AM
Thanks Nate! Hope your new gig is going awesome! Sorry I didn't see you before you left.
Posted on 03-04-2013 08:06 AM
thanks, chris! i've been meaning to drop you an email. hope all's well in your hood.