Apple Software update via package install?

mcparlandj
New Contributor

I'm trying to automate the reimage and deployment of machines. I'd like to automate as much as possible. I'm imaging the machines with DeployStudio and I can install a package that will run on first boot. Built the package with composer with nothing in it other than a postinstall script with the following in the script:
#########
#!/bin/sh
## postinstall /usr/sbin/softwareupdate -a -i && /sbin/reboot
#########

Testing this package on it's own in a vm. Just running the command in a script file only takes a few minutes. It updates safari, and itunes.

Then i roll back the snapshot and run the package it never finishes.

Can anyone see what i'm missing?

Does anyone know if i need to fill out or even keep the following which comes in the script? pathToScript=$0
pathToPackage=$1
targetLocation=$2
targetVolume=$3

6 REPLIES 6

rtrouton
Release Candidate Programs Tester

Since you're imaging the machines with DeployStudio, DeployStudio includes a Software Update workflow task that does exactly what you're trying to accomplish. I'd recommend taking a look at it and seeing how it best fits into your workflow.

mcparlandj
New Contributor

How did i not notice that! Thanks!

mm2270
Legendary Contributor III

@mcparlandj - Yeah, as mentioned, using the default workflow provided by DS will be the best way to do this.
However, to go back and hopefully provide a solution to your original issue, which is, "why the heck doesn't the 'postinstall' script in my pkg run?", I can tell you that, for reasons I just don't know, I've also run into a lot of problems getting postinstall scripts in flat Apple packages to run. For whatever reason, they just seem extremely flaky.
The solution is to use the older bundle style package format (you can switch to those in Composer's preferences) and use the "postflight" script format instead. These seem to work pretty much 100% of the time, assuming your syntax is correct of course. postflight is not supported with flat packages, so you do need to use the older bundle style for those.

If I knew why the postinstall didn't work with flat packages. I'd surely post about it here, but its a mystery to me. I can't tell if its a bug in Composer's implementation of it, or a problem Apple needs to address.

Also, you can safely leave all those pathTo variables in any scripts. They're there more for reminder purposes than anything else.

Anyway, hope that helps.

mcparlandj
New Contributor

That actually helped a lot! Time to tinker some more. Thanks!

rtrouton
Release Candidate Programs Tester

I have a tool for building payload-free packages, where I haven't seen issues with the postinstall script working properly. It's available from here:

https://github.com/rtrouton/Payload-Free-Package-Creator

gregneagle
Valued Contributor
I can tell you that, for reasons I just don't know, I've also run into a lot of problems getting postinstall scripts in flat Apple packages to run. For whatever reason, they just seem extremely flaky. ... If I knew why the postinstall didn't work with flat packages. I'd surely post about it here, but its a mystery to me. I can't tell if its a bug in Composer's implementation of it, or a problem Apple needs to address.

I've never had an issue with postinstall scripts running as expected in flat packages. I'd suspect either an issue with Composer, or operator error... (I exclusively use pkgbuild to build flat packages these days)