Skip to content

Instantly share code, notes, and snippets.

@akkornel
Created February 16, 2017 01:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akkornel/94604ccf2d99396e81230da9b7c14c79 to your computer and use it in GitHub Desktop.
Save akkornel/94604ccf2d99396e81230da9b7c14c79 to your computer and use it in GitHub Desktop.
Using MacPorts to package software for distribution

Hello!

This document talks about how to use MacPorts to make a macOS installer packages that will install multiple MacPorts ports onto a system.

MacPorts is a project which takes open-source software and builds it for macOS. It takes care of the work of identifying and patching any macOS-specific problems, working out how best to do the build, etc..

Normally, you install MacPorts on your local system, and use the Terminal to install ports (a port is an individual software offering). However, it is also possible to use MacPorts to build macOS installer packages (.pkg files). MacPorts can also bundle multiple ports into a single package (an .mpkg file), so you can install multiple ports in a single action. The ability to make .mpkg files is useful, because ports typically depend on other ports in order to function properly.

This document describes the process for making .mpkg files, so that you can distribute them to systems.

The document is divided into the following sections:

  • BUILD PORTS talks about how to actually build the .mpkg file. This involves downloading, (if necessary) building, and packaging software.
  • ON A NEW SYSTEM talks about how to get a freshly-built system set up to run MacPorts.
  • MONTHLY REBUILD describes how to take an existing system (one which has built .mpkg files before) and do regular updates. This is like monthly patching, but for MacPorts.
  • AFTER A MINOR UPGRADE describes what you should do when there is a minor macOS upgrade (for example, from 10.12.1 to 10.12.2).
  • AFTER A MAJOR UPGRADE describes what you should do when there is a major macOS upgrade (for example, from 10.12 to 10.13).

BUILD PORTS

If you are starting on a completely fresh system, first follow the steps from the ON A NEW SYSTEM section; if you are working on an existing system, first follow the steps from the MONTHLY REBUILD section. Once you are done there, come back here.

At this time, the following ports will be packaged into one .mpkg file:

  • emacs 25.1_4: A newer Emacs than what macOS provides.
  • emacs-app 25.1_4: A macOS application form of the Emacs text editor.
  • git 2.11.1: A newer Git than what macOS provides.
  • kerberos5 1.15: A newer Kerberos than what macOS provides.
  • macvim 8.0.snapshot124: A macOS application form of the Vim text editor, with Python 3.6 support enabled.
  • opensc 0.16.0: Enabled OpenSSH to access a private key that is stored inside a Yubikey.
  • openssh 7.3p1: A newer OpenSSH than what macOS provides. Enables support for GSSAPI Key Exchange, and disables Xauth (X Windows) support.
  • py36-awscli 1.11.45: Provides the aws command, for management of AWS from the command-line.
  • remctl 3.1_1: For running remote commands without SSH.
  • vim 8.0.0237: A newer Vim editor (command-line only) than what macOS provides, with Python 3.6 support enabled.
  • wallet 1.3: For secret storage & retrieval.

The above ports all have dependencies, which will automatically be downloaded and packaged.

To build the package, open a Terminal and run the following commands:

sudo port mpkg emacs emacs-app git kerberos5 macvim +python36 opensc openssh +gsskex -xauth py36-awscli remctl vim +python36 wallet
open /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_devel_git/emacs/work

The first command will download software (either source or pre-built binaries), create a .pkg file for each port, and then combine everything into a single .mpkg file.

The second command opens the folder where the .mpkg file may be found. Since git was the first port on the list, the .mpkg file is named for Git.

To see the files that are contained in the package, run this command:

pkgutil --payload-files PATH_TO_MPKG_FILE

The .mpkg file may now be distributed via BigFix. It is suggested that you call the package something like “MacPorts packages”, and that you use today’s date (for example, 20170213) as the version number. In the description, list the main packages being installed (see the list above).

ON A NEW SYSTEM

Install Xcode from the Mac App Store: https://itunes.apple.com/us/app/xcode/id497799835?mt=12

Launch Terminal, and run two commands:

xcode-select --install
sudo xcodebuild -license

The first command initiates the installation of the Xcode command-line tools, which MacPorts needs. Follow the prompts to download and install.

The second command is used to display and accept the Xcode license agreement. You will be prompted for your password, as the command must run as root. You will then be shown the license agreement, and asked to agree to it.

Next, download and install the MacPorts installer. The download page is here: https://github.com/macports/macports-base/releases/

Select the appropriate .pkg file for your macOS release. Install the package. You should expect it to take several minutes at the end, as it downloads the initial list of ports available, and sets up the environment.

You are now ready to build the port packages! Follow the instructions in the BUILD PORTS section.

MONTHLY REBUILD

Every month, you should update your system and rebuild the ports installer, so that the latest ports are available to everyone. You may also wish to do this more often, if there is a security problem to address.

Launch the Mac App Store, go to the Updates tab, and install any pending updates. Be on the lookout for updates for macOS and Xcode. Restart if required.

Once all updates are installed, launch Terminal and run these two commands:

sudo port selfupdate
sudo port upgrade outdated

These two commands will update MacPorts (and the list of available ports), and then upgrade any ports that have become outdated.

Now that everything is updated, follow the instructions in the BUILD PORTS section.

AFTER A MINOR UPGRADE

A minor upgrade is an upgrade where only the third number changes. For example, from 10.12.1 to 10.12.2.

In that case, no special work is needed: Once the macOS upgrade—and any other App Store upgrades—has completed, follow the instructions from the MONTHLY REBUILD section.

AFTER A MAJOR UPGRADE

A major upgrade is an upgrade where the third number changes. For example, from 10.12.2 to 10.13.1.

If you decide to upgrade by completely re-imaging your system, then nothing special needs to be done. Follow the instructions from the ON A NEW SYSTEM section. If you decide to upgrade in-place, then go ahead and do the upgrade of macOS, followed by upgrading anything else that the App Store identifies (like Xcode).

Once the macOS upgrade is complete, more work will be needed: When a major macOS upgrade takes place, Xcode and related libraries typically have many updates. Although the Mac App Store handles upgrading Xcode and the Xcode command-line tools, for MacPorts it is much easier to simply remove everything and start again.

To remove MacPorts completely, run these commands:

rm -rf ~/.macports
sudo pkgutil --forget org.macports.MacPorts

Next, open the .profile file in your home directory, and look for any instances of the PATH and MANPATH variables being changed. There will be comments near those changes, indicating that they were changed by MacPorts. Remove those lines.

Finally, log out and reboot your system.

You should now follow the instructions from the ON A NEW SYSTEM section to reinstall everything, followed by the BUILD PORTS section to rebuild the ports installer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment