We’ve made some changes to our FreeBSD ports tree, and want to update our awesome contributors on these improvements. There is now a new overlay structure for handling OpenRC specific changes. These changes allow us to more efficiently sync from upstream FreeBSD and reduce the differences in files originating from the FreeBSD Project.

 

Overview of changes

 

First, we now use the trueos-master branch by default in trueos/freebsd-ports:

Now you can add an OpenRC script to our ports tree using this overlay structure:

  • Makefile.notes is used for USE_OPENRC_SUBR=openrc-nameofservice in the place of Makefile.
  • files/openrc-nameofservice.in is used instead of nameofservice.in.

For example, let’s look at the port of tor. Start by examining the Makefile.trueos file:

https://github.com/trueos/freebsd-ports/blob/trueos-master/security/tor/Makefile.trueos:

We use Makefile.trueos to instruct that we want to install an OpenRC script by setting:

USE_OPENRC_SUBR= openrc-tor

 

Next, we’ll look at openrc-tor.in:

https://github.com/trueos/freebsd-ports/blob/trueos-master/security/tor/files/openrc-tor.in:

This file is the OpenRC init.d compatible version of the script.

 

Finally, let’s look at tor.in:

https://github.com/trueos/freebsd-ports/blob/trueos-master/security/tor/files/tor.in

This is the rc.d compatible version of the script. This script comes directly from the FreeBSD Project. When working on OpenRC scripts, never modify tor.in. Merge conflicts happen when both TrueOS devs and FreeBSD devs make simultaneous changes to the same file. To avoid merge conflicts, we now have openrc-tor.in as a separate file. This allows us to pull in the latest improvements from FreeBSD without accidentally overwriting any of your contributions.

 

First steps: Writing OpenRC scripts

 

Many users ask us how to write their own OpenRC scripts. That’s great! Here’s a brief description of the starting steps. Hopefully, it’s helpful to get you started with writing your own awesome OpenRC scripts!

A good place to start is reviewing the openrc-update manpage (man openrc-update). It is very helpful in learning many of the available options. If you encounter a script that is not available in /usr/local/etc/init.d, it is sometimes more useful to copy the script over from /usr/local/etc/rc.d to begin the porting process. After copying, enter the file to change the required few lines. Then, test all changes by starting, restarting, and stopping the service. Next, copy the working copy of the service into a local copy of the trueos/freebsd-ports repository and commit your modifications. Finally, submit a pull request back to the TrueOS project.

Example: the tor script is a great example of a simple conversion. This commit shows the difference between the new and old process:

https://github.com/trueos/freebsd-ports/commit/fcd34944d314551407eb4ee5a226977547bce05f

Look at the full diff to see there are only a few major changes:

  • #!/bin/sh converts to #!/sbin/openrc-run
  • The conversion of variables %%PREFIX%%, %%USER%%, %%GROUP%%, which may be specific to rc.d.

Many rc.d specifics are removed:

  • . /etc/rc.subr
  • -rcvar=tor_enable
  • -exit_code=0-
  • -load_rc_config ${name}

This port is a good example of a port that needs a cleanup. Using any of the alternative variables for OpenRC, for example. Because this script is not written by the OpenRC authors, the license is also not required. While hopefully rare due to the ease of conversion, please include the appropriate license when using a script originating from the OpenRC authors, PacBSD, Gentoo, or any other project.

Those looking for an older copy of the ports tree may find it in the GitHub TrueOS master branch.

If you find a regression from our changes, please inform us immediately! We want to restore any potentially lost changes as quickly as possible. Thanks for supporting TrueOS, and we’ll update you on other upcoming changes soon!


Contribute!

Want to help guide TrueOS development? Jump into any of our community channels and let us know what you think! You can also contribute directly, shaping TrueOS for the future.