SelfService crashing upon executing jamfselfservice://content?entity=policy&id

Hermenegildah
New Contributor II

Script works properly when launched from terminal, but fails after being executed as a policy. Self Service tries to open, then crashes. App version is 10.35.0, the OS it gets executed from is 10.14.6, fully patched.

The same script fails on a manually upgraded Catalina as well. (Did it for testing purposes, just to see what happens; system is already running 10.15.7).

 

 

#!/bin/zsh
#
 
########################################
# Global Variables
########################################
loggedInUser=$( /bin/echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/ && ! /loginwindow/ { print $3 }' ) # Get the current user - shell agnostic (sh, zsh, bash, dash)
myJamfHelper="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper" # Path to the jamfHelper binary - not part of PATH by default
########################################
 
########################################
# XXXXXXX XXXX OIT Notification Variables
########################################
notificationLogName="AG-Notification-Sample" # Name of notification - for log filename
windowTitleText="Generic Notification" # Notification window title
headingText="macOS Catalina Upgrade" # Bold heading text in notification body
iconPath="/Library/Application Support/AGCustom/Generic_Vertical_Wordmark.ico" # Icon shown in notification window
button1RightText="Upgrade OS" # Text on button1, the right button
button2LeftText="Postpone" # Text on button2, the left button
declare -i timeout=300 # Timeout in seconds - must be an integer and not a string
 
# Message text below appears in the notification body. Use literal line breaks as seen in this sample.
messageText="Your computer is currently running an older and unsupported version of macOS. Please start the upgrade process at your earliest convenience. To start it now please select Upgrade OS from the options below.
 
Click '${button2LeftText}' to view the installer in Self Service. Click '${button1RightText}' to initialize the upgrade now.
 
This notification will time out in ${timeout} seconds.
 
########################################
 
########################################
# Logging
########################################
# Logs are written to our logfile and output to console for capture by Jamf policy logging
logPath="/Library/Logs/AG"
logFile="${logPath}/${notificationLogName}.log"
 
if [ ! -d "${logPath}" ]; then
/bin/mkdir -p "$logPath"
fi
 
WriteLog()
{
logTxt=$1cata
/bin/echo "$(/bin/date +%Y-%m-%d_%H:%M:%S) : ${logTxt}" | /usr/bin/tee -a "$logFile"
}
########################################
 
 
########################################
# Main Script
########################################
# If there is no actively logged in user, exit.
# _mbsetupuser is the account in use during Setup Assistant.
if [ "$loggedInUser" = "" ] || [ "$loggedInUser" = "root" ] || [ "$loggedInUser" = "_mbsetupuser" ]; then
WriteLog "WARN: No logged in user. Stopping."
exit 0
fi
 
# Pull down our logo file if it does not exist
if [ ! -f "$iconPath" ]; then
    /usr/local/bin/jamf policy -event agLogo
fi
 
WriteLog "INFO: Starting notification for user ($loggedInUser)."
 
# Call jamfHelper with our parameters
# 'utility' window types do not have window controls to close the window without interacting with our buttons
# 'button1' returns 0, 'button2' returns 2
# 'timeout' is in seconds and will run the defaultButton action when it is reached
# 'defaultButton' is the button returned on timeout, or if the user hits the return key
# 'cancelButton' is the button returned if the user hits the escape key
# For more info on jamfHelper, see https://apple.lib.utah.edu/jamfhelper/
notificationResponse=$("$myJamfHelper" -windowType utility -timeout $timeout -button1 "$button1RightText" -button2 "$button2LeftText" -defaultButton 1 -cancelButton 2 -icon "$iconPath" -iconSize 200 -title "$windowTitleText" -heading "$headingText" -description "$messageText")
 
# Button actions start here
# Check jamfHelper's return value and act accordingly
# Button 2 returns 2, Button 1 returns 0
if [ "$notificationResponse" -eq 2 ]; then
    sudo -u "$loggedInUser" /usr/bin/open "jamfselfservice://content?entity=policy&id=1609&action=view"
    WriteLog "INFO: (${loggedInUser}) clicked (${button2LeftText})."
elif [ "$notificationResponse" -eq 0 ]; then
    sudo -u "$loggedInUser" /usr/bin/sudo -u $loggedInUser /usr/bin/open /Applications/Install\ macOS\ Catalina.app
WriteLog "INFO: (${loggedInUser}) clicked (${button1RightText}) or notification timed out after ${timeout} seconds (see log timestamps)."
else
WriteLog "WARN: Notification ended with non-standard exit code $?"
exit 1
fi
 
WriteLog "INFO: Notification complete"
 
exit 0
########################################

 

 

 

8 REPLIES 8

YanW
Contributor III

Maybe try this...

currentUser=$(/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }')
uid=$(id -u "$currentUser")

Then run your 

policyID=set your policy ID

policyAction=set your policy action

policy="jamfselfservice://content?entity=policy&id=$policyID&action=$policyAction"

launchctl asuser $uid sudo -iu $currentUser open $policy

Hermenegildah
New Contributor II

Original script was ran with elevated privileges.

Hermenegildah
New Contributor II

Process:               Self Service [6093]

Path:                  /Applications/Self Service.app/Contents/MacOS/Self Service

Identifier:            com.jamfsoftware.selfservice.mac

Version:               10.35.0 (10.35.0-t1640197529)

Code Type:             X86-64 (Native)

Parent Process:        ??? [1]

Responsible:           Self Service [6093]

User ID:               1017136713

 

Date/Time:             2022-03-01 12:07:35.104 -0500

OS Version:            Mac OS X 10.14.6 (18G103)

Report Version:        12

Anonymous UUID:        F4591EB4-C5E6-A4DB-AFAD-3CB1B511C5E2

 

Sleep/Wake UUID:       5E3186F7-71FE-402D-8B3A-62E279644990

 

Time Awake Since Boot: 4900 seconds

Time Since Wake:       370 seconds

 

System Integrity Protection: enabled

 

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

 

Exception Type:        EXC_CRASH (SIGABRT)

Exception Codes:       0x0000000000000000, 0x0000000000000000

Exception Note:        EXC_CORPSE_NOTIFY

 

Application Specific Information:

abort() called

 

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread

0   libsystem_kernel.dylib        0x00007fff63df22c6 __pthread_kill + 10

1   libsystem_pthread.dylib       0x00007fff63eadbf1 pthread_kill + 284

2   libsystem_c.dylib             0x00007fff63d5c6a6 abort + 127

3   org.cocoapods.Sentry          0x000000010403b19b -[SentryCrashExceptionApplication _crashOnException:] + 58

4   com.apple.AppKit              0x00007fff3575c748 -[NSApplication reportException:] + 916

5   org.cocoapods.Sentry          0x000000010403b134 -[SentryCrashExceptionApplication reportException:] + 371

6   com.apple.AppKit              0x00007fff3535234c -[NSApplication finishLaunching] + 3110

7   com.apple.AppKit              0x00007fff353513c7 -[NSApplication run] + 250

8   com.apple.AppKit              0x00007fff35340ac8 NSApplicationMain + 777

9   com.jamfsoftware.selfservice.mac 0x00000001038a4ea9 0x10389f000 + 24233

10  libdyld.dylib                 0x00007fff63cb73d5 start + 1

 

Thread 1:

0   libsystem_pthread.dylib       0x00007fff63eaa3f0 start_wqthread + 0

 

Thread 2:

0   libsystem_pthread.dylib       0x00007fff63eaa3f0 start_wqthread + 0

 

Thread 3:

0   libsystem_pthread.dylib       0x00007fff63eaa3f0 start_wqthread + 0

 

Thread 4:

0   libsystem_pthread.dylib       0x00007fff63eaa3f0 start_wqthread + 0

 

Thread 5:

0   libsystem_pthread.dylib       0x00007fff63eaa3f0 start_wqthread + 0

 

Thread 0 crashed with X86 Thread State (64-bit):

  rax: 0x0000000000000000  rbx: 0x00000001108da5c0  rcx: 0x00007ffeec3604f8  rdx: 0x0000000000000000

  rdi: 0x0000000000000307  rsi: 0x0000000000000006  rbp: 0x00007ffeec360530  rsp: 0x00007ffeec3604f8

   r8: 0x0000000000000010   r9: 0x000000000000031c  r10: 0x0000000000000000  r11: 0x0000000000000206

  r12: 0x0000000000000307  r13: 0x000000010406fd86  r14: 0x0000000000000006  r15: 0x000000000000002d

  rip: 0x00007fff63df22c6  rfl: 0x0000000000000206  cr2: 0x00007fff9a546188

  

Logical CPU:     0

Error Code:      0x02000148

Trap Number:     133

sdagley
Esteemed Contributor II

@Hermenegildah Did you ever find a solution for this? I am seeing the same problem with Self Service 10.40.1 on macOS 12.5.1 where it crashes due to a SIGABRT when called from a script triggered by a LaunchDaemon. Running the same script from Terminal via sudo does successfully launch Self Service. And the script _should_ be doing all the needed things to open Self Service in the user context: 

/bin/launchctl asuser "$currentUserID" sudo -u "$currentUser" /usr/bin/open "jamfselfservice://..."

YanW
Contributor III

I notice your messageText="Your computer is currently running......

is missing the " at the end of ......in ${timeout} seconds.

I removed all the logging part and focus on the main script itself.

Self Service wouldn't launch with your if statement, but worked when I replaced your

sudo -u $loggedInUser /usr/bin/open jamfselfservice://content?entity=policy&id=1609&action=view

with mine

launchctl asuser $uid sudo -iu $currentUser open jamfselfservice://content?entity=policy&id=1609&action=view

Hermenegildah
New Contributor II

I have made appropriate chances, but the policy fails now. 

 

Script result: /Library/Application Support/JAMF/tmp/AG - Notification - macOS Catalina Upgrade:95: unmatched "

Error running script: return code was 1.

Hermenegildah
New Contributor II

Catalina_postpone.jpg

YanW
Contributor III

I'd suggest find a script that work here and customize it. Here is a stripped down version. I just use Monterey as example. 

#!/bin/zsh

# current logged in user
currentUser=$(/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }')
uid=$(id -u "$currentUser")

jamfHelper="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"
title="Notification" 
heading="macOS Monterey Upgrade" 
icon=/Applications/Install\ macOS\ Monterey.app/Contents/Resources/InstallAssistant.icns
windowType="utility"
button1="Upgrade OS" 
button2="Postpone" 
timeout=300 # activate default button after timeout, remove default button if you don't want to run the script after the timeout

message="Your computer is currently running an older and unsupported version of macOS. 
Please start the upgrade process at your earliest convenience. 
To start it now please select Upgrade OS from the options below.
 
Click '${button2}' to view the installer in Self Service. 
Click '${button1}' to initialize the upgrade now.
 
This notification will time out in ${timeout} seconds."

# Policy ID and Action
policyID="1609"
policyAction="view"	# view or execute
policy="jamfselfservice://content?entity=policy&id=$policyID&action=$policyAction"

#jamfHelper window
userChoice=$("$jamfHelper" \
-windowType "$windowType" \
-title "$title" \
-heading "$heading" \
-description "$message" \
-timeout "$timeout" \
-button1 "$button1" \
-button2 "$button2" \
-icon "$icon" \
-iconSize 200)

# Button 1 to view policy in Self Service
if [ "$userChoice" = 0 ]; then
    launchctl asuser $uid sudo -iu $currentUser open $policy
else
# Button 2 do whatever you want
	launchctl asuser $uid sudo -iu $currentUser open /Applications/Install\ macOS\ Monterey.app/
fi
exit 0