Skip to content

Instantly share code, notes, and snippets.

@alfg
Created April 7, 2021 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alfg/cac34a46cdaedd16bd063266ff952a5f to your computer and use it in GitHub Desktop.
Save alfg/cac34a46cdaedd16bd063266ff952a5f to your computer and use it in GitHub Desktop.
Working with Apple pkgs

Mac Packaging Cheatsheet

Create a component pkg from a DMG

pkgbuild --component /Volumes/ApplicationName/*.app --install-location \
    /Applications ApplicationName-Version.pkg

Install pkg from command line

installer -pkg pkgName.pkg -target / -verbose

Flatten A Component Package Within A Bundle

pkgutil --flatten component.pkg

Remove Receipt of Installations

pkgutil --forget com.identifier.name

Export Choice Changes Plist from a Package

installer -showChoiceChangesXML -pkg /path/to/pkg > choiceChangesOutput.plist

Apply Choice Changes During Package Install

installer -applyChoiceChangesXML /path/to/plist -pkg /path/to/pkg -target "/"

Generate a Distribution XML File

productbuild --synthesize --package first.pkg --package second.pkg

Script Arguments

Arg Meaning
$1 Full path to the installation package
$2 Full path to the installation destination
$3 Mountpoint of the destination volume
$4 Root directory for the current System folder

Environment Variable se by the installer process

Env Variable Meaning
$PACKAGE_PATH Same as the $1 argument
$SCRIPT_NAME The name of the script file
$COMMAND_LINE_INSTALL Set when installing with installer

Package Forensics

List Installed Packages

pkgutil --pkgs

List Installed Packages from Filter

pkgutil --pkgs=com.googlecode*

List Specific Package Information

pkgutil --info com.googlecode.munki.core

List Files A Package Installed

pkgutil --files com.googlecode.munki.core

List Files A Package Installed Based on *.app

pkgutil --file-info /Applications/Numbers.app

Inspect A Package

pkgutil --expand pkgName.pkg /to/path/for/inspection

Payload Files Are Typically XAR archives

tar xvf Payload

Read the contents of a Bom (Bill of Material) file

lsbom Bom

List Valid Identities on the Current System

security find-identity -p basic -v

Sign An Already Built Package

productsign --sign "Identity" unsigned.pkg signed.pkg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment