Unable to create a simple installable package

Hi, I am a newcomer in macOS development, and I am struggling to create a package with the XCode command line tools that is installable on other computers. In its minimal version, the package shall install a simple program to usr/local/:

hello.c:

#include <stdio.h>
int main(void) {
  printf("Hello World\n");
  return 0;
}

distribution.plist:

<installer-gui-script minSpecVersion="1">
    <product id="net.world" version="1.0"/>
    <title>Hello World</title>
    <choices-outline>
      <line choice="net.world.hello"/>
    </choices-outline>
    <choice id="net.world.hello" title="Hello">
      <pkg-ref id="net.world.hello">h1.pkg</pkg-ref>
    </choice>
</installer-gui-script>

build.sh:

#!/bin/sh
cc -o hello hello.c
mkdir -p local/bin
cp hello local/bin/
codesign -s - -i net.world.hello local/bin/hello
pkgbuild --identifier net.world.hello \
         --root local \
         --install-location /usr/local \
         h1.pkg
productbuild --distribution distribution.plist --resources . hello.pkg

The build scrips produces a package hello.pkg. However, when I try to install it, I get

<Debug>: Product archive /Users/foo/hello.pkg trustLevel=100
<Error>: PKInstallRequest: failed to initialize. Error: Error Domain=PKInstallRequestErrorDomain Code=2 "Specifier Description:<PKPackageSpecifier>:
	{
	    URL = "file:///Users/foo/h1.pkg";
	    identifier = "net.world.hello";
	    options = 0;
	    version = 0;
	}" UserInfo={NSLocalizedFailureReason=Specifier Description:<PKPackageSpecifier>:
	{
	    URL = "file:///Users/foo/h1.pkg";
	    identifier = "net.world.hello";
	    options = 0;
	    version = 0;
	}}
<Debug>: External component packages (1) trustLevel=100 (trust evaluation failed)
<Debug>: -[IFDInstallController(Private) _buildInstallPlanReturningError:]: location = file://localhost
<Debug>: -[IFDInstallController(Private) _buildInstallPlanReturningError:]: file://localhost/Users/foo/h1.pkg
<Error>: Failed to locate package at path /Users/foo/h1.pkg (h1.pkg -- file://localhost/Users/foo/hello.pkg)
<Error>: Install failed: The Installer can’t locate the data it needs to install the software. Check your install media or internet connection and try again, or contact the software manufacturer for assistance.

The package build runs on Github Action (macOS 11/Xcode 13.2).

What is wrong with this setup, and how can I create a distributable package that installs in /usr/local/?

Replies

Your package is failing trust evaluation:

<Debug>: External component packages (1) trustLevel=100 (trust evaluation failed)

If you’re installing with the installer tool, there’s a command-line option (-allowUntrusted) to disable trust evaluation. However, the correct solution here is to sign your code and then sign, notarise, and staple your package with Developer ID signing identities. See:

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

  • I tried to add -allowUntrusted, but it didn't help. And the "correct solution" has the requirement to yearly pay, which is a bit much for an unpaid volunteer who maintains a package that will see probably less than one update per year. I rely here on that the user taking the inconvenience to install an untrusted package, which seems usual in my field (astronomy).

  • I already tried -allowUntrusted but it didn't help.

Add a Comment

After a number of attempts, I found that it pragmatically works if the components get a version assigned, i.e. pkgbuild --version 1.2.3 … or in the distribution.plist. This is somehow surprising, as the documentation doesn't state that a version is required (it says that the version is then set to 0 and it cannot decide whether it is an upgrade or a downgrade).