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/?

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"

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).

Unable to create a simple installable package
 
 
Q