Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

16 Commits

Folders and files

Repository files navigation

stackql-mac-installer

Creates a multi arch (fat) pkg MacOS installer for stackql and StackQL Workbench, notarizes the package with Apple, staples the notarization ticket to the package and uploads it to the matching GitHub release.

What the package installs

stackql_darwin_multiarch.pkg is a product archive that holds two component packages:

Package Installs Notes
com.stackql.pkg /usr/local/bin/stackql Universal binary, on every supported macOS
io.stackql.workbench.pkg /Applications/StackQL Workbench.app Universal app, only on the macOS version the app needs (13 or later today) or newer

sudo installer -pkg stackql_darwin_multiarch.pkg -target / installs both. On a macOS older than the app needs, only stackql is installed.

The package runs no scripts at install time and writes nothing to a home folder. The app keeps its providers in ~/.stackql, the folder the stackql command uses when it is started in the home folder, and creates it itself as the user. Do not create it from an install script, it would belong to root.

Neither component package resets the owner or mode of a folder that already exists, so /usr/local/bin and /Applications are left as they are (see keep_folder_permissions in create-installer.sh).

Prerequisites

The script is designed to run on a dedicated packaging Mac. It needs:

  • Xcode command line tools (lipo, codesign, pkgbuild, productbuild, pkgutil, xcrun notarytool, xcrun stapler)
  • Apple Developer ID Application and Developer ID Installer certificates installed in the login keychain
  • GitHub CLI (gh), authenticated with an account that can read workflow artifacts and upload release assets in stackql/stackql (gh auth login, the default repo and workflow scopes are sufficient)
  • jq
  • Network access to github.com, where the StackQL Workbench release is downloaded from with curl (public)

Setup

Copy vars.sh.example to vars.sh and populate it. vars.sh is gitignored and holds the machine specific values: team id, Apple ID, signing identities, the login keychain password and the app specific password used for notarization.

cp vars.sh.example vars.sh

Usage

Pass the stackql build number and the StackQL Workbench release to bundle. The build number is the run number of the Build workflow in stackql/stackql and is the patch component of the version (for example build 669 is v0.11.669). The StackQL Workbench release can be given with or without the leading v.

bash create-installer.sh 669 v0.1.0

The script will:

  1. Check that the stackql/stackql-workbench release (v0.1.0 above) holds stackql-workbench_darwin_multiarch.app.tar.gz and its .sha256
  2. Unlock the login keychain and store the notarization credentials as the stackql notarytool profile
  3. Look up the Build workflow run for the build number and download the stackql_darwin_amd64 and stackql_darwin_arm64 artifacts to downloads/ (gitignored)
  4. Extract both binaries, combine them into a universal binary with lipo and read the version from stackql --version
  5. Look up the GitHub release for the version, if it does not exist the script stops with Release x.x.x does not exist, please create it first
  6. Check whether stackql_darwin_multiarch.pkg and its .sha256 sidecar are already assets of that release, and read the SHA-256 digest GitHub recorded for the package
  7. Download stackql-workbench_darwin_multiarch.app.tar.gz and its .sha256 from https://github.com/stackql/stackql-workbench/releases/download/<workbench release>/, check it with shasum -a 256 -c and unpack it with tar -xzf. The script stops if the app is not io.stackql.workbench, its CFBundleShortVersionString is not the release version, it is not universal, or it holds code other than its main executable
  8. Sign the stackql binary. Replace the ad hoc signature of the app with the Developer ID Application one (hardened runtime, timestamp), verify it with codesign --verify --deep --strict, notarize the app and staple its ticket
  9. Build the two component packages with pkgbuild, each from a folder under build/ (gitignored) that holds only what is installed, and check the payload of each one with pkgutil --payload-files
  10. Combine them into one product archive with productbuild, signed with the Developer ID Installer identity, then notarize it and staple the ticket
  11. Compute stackql_darwin_multiarch.pkg.sha256 (sha256sum format) from the stapled package, upload the package and the sidecar to the release and verify the digest GitHub recorded for the attached package, or, if the package already exists, leave it in dist/package/ for a manual update and upload the sidecar only if the attached package is byte-identical to the local one

Outputs are written to dist/package/stackql_darwin_multiarch.pkg, dist/package/stackql_darwin_multiarch.pkg.sha256 and dist/package/stackql_<version>_darwin_multiarch.pkg.

To try a change to the script without publishing anything, run it for a build whose release already holds the package. The script then uploads nothing and leaves the new package in dist/package/.

Package definition

File Purpose
config/component.plist Component plist of the app package. BundleIsRelocatable is false, so Installer puts the app in /Applications and not where it finds another copy of it
config/Distribution.xml Distribution file of the product archive. Sets hostArchitectures="x86_64,arm64" and selects the app package only on a macOS the app can run on. The version it compares against is filled in by the script from the LSMinimumSystemVersion of the app

The identifiers and file names of the two component packages are in create-installer.sh and in config/Distribution.xml, and the app name is also in config/component.plist. Change them together.

Configuration

The following can be overridden with environment variables if needed:

Variable Default Purpose
GH_REPO stackql/stackql Repo to read artifacts from and upload the release asset to
GH_WORKFLOW build.yml Workflow whose run number is the build number
GH_RUN_LOOKUP_LIMIT 500 How many recent workflow runs to search for the build number

Verifying a package

The script checks the signatures, the payloads, the stapled tickets and Gatekeeper acceptance while it builds. The checks below are for a Mac the package is installed on. Run them on Apple Silicon and on Intel. The folder check matters most on a Mac where a package manager owns /usr/local/bin.

Before installing:

PKG=dist/package/stackql_darwin_multiarch.pkg
pkgutil --check-signature "$PKG"
xcrun stapler validate "$PKG"
spctl -a -vv -t install "$PKG"
# only ., ./stackql and ./StackQL Workbench.app with its contents
pkgutil --payload-files "$PKG"

Install, and check that the owner and mode of the two folders are the same before and after:

stat -f '%Su:%Sg %Lp %N' /usr/local/bin /Applications
sudo installer -pkg "$PKG" -target /
stat -f '%Su:%Sg %Lp %N' /usr/local/bin /Applications

After installing:

/usr/local/bin/stackql --version
pkgutil --files com.stackql.pkg
pkgutil --files io.stackql.workbench.pkg
codesign --verify --deep --strict --verbose=2 "/Applications/StackQL Workbench.app"
spctl -a -vv "/Applications/StackQL Workbench.app"
xcrun stapler validate "/Applications/StackQL Workbench.app"
open "/Applications/StackQL Workbench.app"

The app opens with no Gatekeeper prompt. In its Settings the engine is /usr/local/bin/stackql, "installed with the app", and the data folder is ~/.stackql, owned by the user and not by root.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages