jamfHelper & LaunchDaemon

GaToRAiD
Contributor II

So, I'm having an issue where my LaunchDaemon is not running the script that I have built that uses jamfHelper.

Here is my plist that I have:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.MyCompany.UpdateTool</string>
    <key>ProgramArguments</key>
    <array>
        <string>/var/StartupUpdateTool.sh</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

Now, I'm pretty sure it is running, I've checked the plist with plutil. So I'm not sure what is going on. When I switch it to a LaunchAgent, it works fine, but I want to try and pause the login process so that I can make some changes prior to the user logging in.

Here is the script.

#!/bin/bash
install_dir="/Library/Application Support/JAMF/UpdateTool/"
icon="/System/Library/CoreServices/Software Update.app/Contents/Resources/SoftwareUpdate.icns"


#Check for Network Connection
CheckForNetwork(){

    local test

    if [[ -z "${NETWORKUP:=}" ]]; then
        test=$(ifconfig -a inet 2>/dev/null | sed -n -e '/127.0.0.1/d' -e '/0.0.0.0/d' -e '/inet/p' | wc -l)
        if [[ "${test}" -gt 0 ]]; then
            NETWORKUP="YES"
        else
            NETWORKUP="NO"
        fi
    fi
}

jamfHelper(){
    sudo killall jamfHelper
    /Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType fs -title "Updating" -icon /System/Library/CoreServices/Software Update.app/Contents/Resources/SoftwareUpdate.icns  -description "$1" -icon "$icon"

}

#unload login window
/bin/launchctl unload /System/Library/LaunchDaemons/com.apple.loginwindow.plist


#Unload Login Window allowing UpdateTool to start
#Sleep so loginlog can check up.
/bin/sleep 5
if [[ $NETWORKUP = "NO" ]]; then
    jamfHelper "This Mac is being updated. Please plug the power in. Do not interrupt or power off:
        Stage: Network
        Status: No Connection"
    /bin/sleep 3
else
    jamfHelper "This Mac is being updated. Please plug the power in. Do not interrupt or power off:
                Stage: Network
                Status: Connected, checking for Casper Policies."
    sudo jamf policy -verbose > /dev/null 2>&1
fi

if [ "$(ls -A "$install_dir")" ]; then
    jamfHelper "This Mac is being updated. Do not interrupt or power off:
     Stage: Updates
     Status: Found Updates to install."
    # Installing the packages found in 
    # the installers directory using
    # an array
    /bin/sleep 3
  # Save current IFS state

   OLDIFS=$IFS

  # Change IFS to
  # create newline

   IFS=$'
'

  # read all installer names into an array

  install=($(/usr/bin/find $install_dir -maxdepth 2 ( -iname *.pkg -o -iname *.mpkg )))

  # restore IFS to previous state

  IFS=$OLDIFS

  # Get length of the array

  tLen=${#install[@]}
  # Use for loop to read all filenames
  # and install the corresponding installer
  # packages
    jamfHelper "This Mac is being updated. Do not interrupt or power off:
    Stage: Updates
    Status: Found ${tLen} packages to install."

  for (( i=0; i<${tLen}; i++ ));
  do
    jamfHelper "This Mac is being updated. Do not interrupt or power off:
    Stage: Updates
    Status: Installing "${install[$i]}" on this Mac."
     /usr/sbin/installer -dumplog -verbose -pkg "${install[$i]}" -target /
    jamfHelper "This Mac is being updated. Do not interrupt or power off:
    Stage: Updates
    Status: Finished installing "${install[$i]}" on this Mac, now removing package." 
     /bin/rm -f "${install*}"
  done
    /bin/rm -rf "$install_dir"
    jamfHelper "This Mac is being updated. Do not interrupt or power off:
    Stage: Updates
    Status: Finished all installations, now cleaning up."
    /bin/sleep 5
    /sbin/reboot
else
    jamfHelper "This Mac is being updated. Do not interrupt or power off:
    Stage: Updates
    Status: No updates found to install, cleaning up and logging you in."
    /bin/sleep 5

fi
killall jamfHelper
/bin/launchctl load /System/Library/LaunchDaemons/com.apple.loginwindow.plist
exit 0
4 REPLIES 4

mm2270
Legendary Contributor III

Try adding -startlaunchd to the end of your jamfHelper line(s) In some cases it requires that to actually run, especially if you are calling it as part of a launchd process.

Also, just curious, but why do you have the -icon flag being set twice in the jamfHelper line? I don't think that's contributing to the issue, but I just noticed that and was just wondering why that is.

GaToRAiD
Contributor II

@mm2270 I didn't even notice the extra -icon flag

GaToRAiD
Contributor II

No go, did what you suggested, now it's just sitting at the apple loading screen.

mm2270
Legendary Contributor III

OK, I didn't really read or look close enough before, but I have a feeling the issue is the unloading of the loginwindow. I'm not sure if jamfHelper can run in that state. I know there were issues for a long while where it would not even load over an active login window, but JAMF eventually fixed that. But to have it run when there is no loginwindow process is probably not possible. I'm not 100% sure about that since I've never actually tried.

Can you go into more detail on what you're trying to get to? Have you looked at some of the existing tools and threads out there, like Patchoo!? Lachlan and others prior to him have come up with ways of doing this and not allowing user interaction with the Mac while not needing to unload loginwindow, if that's the end goal.