By barts on Apr 29, 2014
As part of the platinum customer program we had some customer discussions regarding the need to 're-baseline' a machine - basically, the ability to return the installed set of package to a specified set (plus dependencies), removing any additional packages that may have been added by other administrators, and add any missing ones. After thinking about the problem for a while we came to the understanding that this approach also resolves some of the requests we've had for recursive uninstall - a feature IPS had prior to 11 FCS but proved about as useful as a chainsaw with two bars and no handles.
The new option is named 'exact-install' ( a name few liked, but no one could come up with a better one).
It functions exactly as the install command does except that it behaves as if you're installing onto a blank system with respect to package tenancy - any installed packages not a direct or indirect dependent of the packages specified on the command line are removed. Note that configuration files, etc. on remaining packages are left alone just as if you used pkg install.
This is also quite handy in maintaining and auditing configuration; if you publish a package that has dependencies on all desired packages and call it baseline,
pkg exact-install baseline
will remove any packages currently installed that are not require by the packages named in the baseline pkg.
pkg exact-install -n baseline
will return an exit code of 4 (nothing to do) if all is well, but will specify work to be done with exit code 0 if someone has added or removed a package.