1

I'm creating a mpkg for OS X 10.6 - OS X 10.9. I want to create a post-install script that checks the OS version and runs a command based on the result

My pseudo code is:

if the OS version is equal to or less than 10.6.8 then
--command A--
else
--command B--
fi
exit 0

I'd be grateful for any help you can offer.

John Bachir
  • 22,495
  • 29
  • 154
  • 227
rogerFernand
  • 119
  • 3

1 Answers1

1

You can get the OS version with sw_vers -productVersion -- that'll print something like "10.8.5". However, this may not be straightforward to compare. When Apple releases the successor to Mavericks, it'll probably be numbered 10.10, and "10.10" is textually less than "10.6.8" (because "1" < "6"). You could parse the version string into its components and compare elements numerically (see this previous question), but that's rather messy.

It's probably easier to check the Darwin version with uname -r -- that'll print something like "12.5.0", which actually does correspond to the OS version, but in a nontrivial way:

  • Darwin 10.x = OS X 10.6.x (and iOS 4)
  • Darwin 11.x = OS X 10.7.approxamatelyx (and iOS 5)
  • Darwin 12.x = OS X 10.8.approxamatelyx
  • Darwin 13.x = OS X 10.9.x (and iOS 6)
  • Darwin 14.x = iOS 7

... but that's actually easier for major version comparison, since you can just look at the first number to get the major version:

darwin_version=$(uname -r)
if (( ${darwin_version%%.*} < 11 )); then  # %%.* removes the first period and everything following that
    # do OS X 10.6 stuff
else
    # do OS X 10.7-10.9 stuff
fi
Community
  • 1
  • 1
Gordon Davisson
  • 118,432
  • 16
  • 123
  • 151
  • Thank you for your help. All I need is major version, like 10.6, I don't need the minor portion. I'll see how this works out for me. – rogerFernand Jan 19 '14 at 19:01