The FreeBSD Diary

The FreeBSD Diary (TM)

Providing practical examples since 1998

If you buy from Amazon USA, please support us by using this link.
[ HOME | TOPICS | INDEX | WEB RESOURCES | BOOKS | CONTRIBUTE | SEARCH | FEEDBACK | FAQ | FORUMS ]

Things look quiet here. But I've been doing a lot of blogging at dan.langille.org because I prefer WordPress now. Not all my posts there are FreeBSD related. I am in the midst of migrating The FreeBSD Diary over to WordPress (and you can read about that here). Once the migration is completed, I'll move the FreeBSD posts into the new FreeBSD Diary website.

And one port to install them all! 14 January 2002
Need more help on this topic? Click here
This article has 11 comments
Show me similar articles

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.

The Makefile

All the files for this port are available in the samples directory. You can download the files for this port from newbox-checklist.tgz.

The Makefile is pretty simple. Here is it:

# New ports collection makefile for: newbox-checklist
# Date created:	13 January 2002
# Whom:			Dan Langille
#
# $Id: meta-ports.php,v 1.6 2007/08/27 16:34:47 dan Exp $
#

PORTNAME=	newbox-checklist
PORTVERSION=	1.0
CATEGORIES=	misc

MASTER_SITES=   # none
DISTFILES=      # none

MAINTAINER=	ports@freebsddiary.org

RUN_DEPENDS=	bash:${PORTSDIR}/shells/bash2 \
		joe:${PORTSDIR}/editors/joe \
		screen:${PORTSDIR}/misc/screen \
		sudo:${PORTSDIR}/security/sudo \
		xtail:${PORTSDIR}/misc/xtail \
		${PREFIX}/distributed.net/dnetc:${PORTSDIR}/misc/dnetc \
		${PREFIX}/etc/logcheck.sh:${PORTSDIR}/security/logcheck

NO_WRKSUBDIR=	YES
NO_BUILD=	YES

do-install: # empty

.include <bsd.port.mk>

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.
${PREFIX}/distributed.net/dnetc:${PORTSDIR}/misc/dnetc
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.


Share
Need more help on this topic? Click here
This article has 11 comments
Show me similar articles