macadmins / installapplications

A tool for dynamically using installapplication
Apache License 2.0
285 stars 62 forks source link

Reboot issues with macOS Sonoma #110

Open flammable opened 1 year ago

flammable commented 1 year ago

Is anyone else using the reboot functionality with IAs?

We're running an older build, and with IAs set to reboot at the end of bootstrapping, we're finding Macs running macOS Sonoma beta 7 do not reboot. IAs writes to the logs that the Mac is rebooting, then IAs cleans up after itself.

Here's the relevant code:

https://github.com/macadmins/installapplications/blob/main/payload/Library/installapplications/installapplications.py#L415-L419

Running /usr/bin/osascript -e delay 5 -e tell application "System Events" to restart manually doesn't seem to do anything on macOS Sonoma beta 7, either, so I don't think this is an IAs-specific issue.

Any objection to changing this to something like /sbin/shutdown -r now instead?

erikng commented 1 year ago

If you do that, I saw IAs not able to fully clean itself up. I moved to this method to combat issues around that.

flammable commented 1 year ago

Ah, thanks. That explains the 5 second delay. Hmm.

I submitted FB13135892, but now I'm second-guessing myself. Needs more testing. This works OK on beta 7:

/usr/bin/osascript -e 'delay 5' -e 'tell application "System Events" to restart'

(it looks like I was quoting things wrong - I don't usually use osascript)

Since that's exactly what IAs is doing, I'm not sure what's wrong here.

flammable commented 1 year ago

Because I needed to have something for today, here's what I settled on. I shoved this at the end of the script that finishes up and quits DEPNotify:

cut="/usr/bin/cut"
mv="/bin/mv"
shutdown="/sbin/shutdown"
sw_vers="/usr/bin/sw_vers"

major_os_version=$(${sw_vers} -productVersion | ${cut} -d. -f1)

if [ ${major_os_version} -ge 14 ]; then
    echo "This Mac is running macOS Sonoma or higher. Cleaning up, then rebooting."
    ${mv} "/Library/installapplications" "/tmp/"
    ${mv} "/Library/LaunchAgents/com.erikng.installapplications.plist" "/tmp/com.erikng.installapplications_agent.plist"
    ${mv} "/Library/LaunchDaemons/com.erikng.installapplications.plist" "/tmp/com.erikng.installapplications_daemon.plist"
    ${shutdown} -r now
fi

It's the last script that runs, so once the computer reboots, /tmp is cleared out, and the computer is all set up.