Today I was setting up a new box and wanted to get all my favorite ports installed with a minimum
of fuss. My first thoughts of were of a shell script. But then I thought of using a port to install
ports. After all, some ports have dependencies, and they install the ports they need. Why can't I write
a port which just installs ports?
So I asked around. And I was told to use a meta-port. I was pointed at
misc/instant-workstation. That is what I used as the basis for this
example meta-port.
Here are a few comments on the various parts of this Makefile.
MASTER_SITES
The master site is where the distfile (distribution file) is downloaded from.
This file contains the source code, patches, etc, for the port. For our
meta-port, we don't have any source ourselves. We are just using other ports.
This is why we have no master site.
DISTFILES
As mentioned in the previous item, we have no distfile. Therefore this is emtpy.
MAINTAINER
Put your email address here
RUN_DEPENDS
These are the ports which must be installed in order for our port to run. Well,
actually, *our* port never runs. But that is not relevant to our task. We will
exploit this feature for the ports tree for our our purpose. Namely, to install
the ports we want.
bash:${PORTSDIR}/shells/bash2
This entry consists of two fields. First, we have bash, the name of
the executable we are installing. We have not supplied a path name. Just
the file name of the executable. Next, we have the port which should be installed
if the executable is not found. We use the predefined value ${PORTSDIR}
in case our ports tree is not installed in /usr/ports. This format will work
well for most ports.
In this case, we are not installing an executable which can be found in the normal
places (as determined by your $PATH variable). Therefore, we provide the full
pathname to the file in question. I determined this path by inspecting
/var/db/pkg/dnetc-2.8010.462_1,1/+CONTENTS. Because it starts
with a /, the ports system will know this is the name of a file, not an executable.
Therefore, it will not search your $PATH.
NO_WRKSUBDIR
This prevents the creation of any subdirectories.
NO_BUILD
We have nothing to build, so let's not build anything.
do-install
We have nothing to install when it comes to installing, so let's not install anything.
For more information on the RUN_DEPENDS, or any other entry in a Makefile, please read
/usr/ports/Mk/bsd.port.mk
Using the makefile
To use the port, download it from newbox-checklist.tgz.
Then unpack the tarball and install it.
fetch http://www.FreeBSDDiary.org/samples/ports/tarballs/newbox-checklist.tgz
tar xvfz newbox-checklist.tgz
cd newbox-checklist
make install
make clean
cd ..
rm -rf newbox-checklist newbox-checklist.tgz
pkg_delete newbox-checklist-1.0
Do not be concerned if you see the following error:
$ sudo pkg_delete newbox-checklist-1.0>
pkg_delete: couldn't open dependency file /var/db/pkg/sudo-1.6.3.7_2/+REQUIRED_BY'
That is to be expected. This is the ports tree attempting to do the right thing.
We told the ports tree with our RUN_DEPENDS entry that sudo
was required by our port. But because we already had sudo installed before I ran
this port, this dependency is not registered with sudo.
Other uses for metaports
In this example, all that we have done with this port is install other ports.
But you an also use the ports tree for system administration. You could
distribute configuration files for example. A good template to use might be
misc/instant-workstation. This port installs
several ports, modifies /etc/rc.conf, and adds
/etc/ntp.conf, amongst other things.