My custom make targets for ports(7)

As the collection of machines running OpenBSD on my network grew bigger, I needed a solution for a central download/storage of packages. I often downloaded a package into /tmp and then pkg_add'ed it on one machine, just to find myself downloading the very same package on another machine the next day.

My sollution for this is a central server with an up to date ports tree on disk, which is exported via NFS to all other machines. When I run "make installpkg" in a port's dir, that package is downloaded and pkg_add'ed. The package also gets saved in /usr/ports/packages/<arch>/all/ for future use. Since this directory is on the NFS mounted disk, all other machines can get the package from there, instead of downloading it again. Please not that it doesn't recurse into dependencies.

I got this idea while reading about port_update by Nikolay Sturm.

/etc/mk.conf:

SUDO=sudo
PKG_MIRROR=ftp://ftp.openbsd.org/pub/OpenBSD/snapshots/packages/`uname -m`/
PKG_PATH=${PKGREPOSITORY}:${PKG_MIRROR}

.include "/usr/ports/infrastructure/mk/mytargets.port.mk"

If you're using this on OpenBSD-stable just change the path stored in PKG_MIRROR above.

/usr/ports/infrastructure/mk/mytargets.port.mk:

getpkg: .NOTMAIN
        @if [ ! -f ${PKGREPOSITORY}/${FULLPKGNAME}.tgz ]; then \
            echo "The package (${FULLPKGNAME}.tgz) doesn't exist in ${PKGREPOSITORY}, downloading."; \
            ${SUDO} ftp -V -o ${PKGREPOSITORY}/${FULLPKGNAME}.tgz ${PKG_MIRROR}/${FULLPKGNAME}.tgz; \
        else \
            echo "The package (${FULLPKGNAME}.tgz) already exists in ${PKGREPOSITORY}, not downloading."; \
        fi

installpkg: .NOTMAIN getpkg
        @env PKG_PATH=${PKG_PATH} ${SUDO} /usr/sbin/pkg_add -v ${FULLPKGNAME}

Please note that the space between "getpkg:" and ".NOTMAIN" is a tab, and not spaces (same goes for installpkg). You will be barfed upon by make(1) if you use spaces. Download this file: mytargets.port.mk.

Example:

$ cd /usr/ports/www/http_ping
$ make installpkg
The package (http_ping-20020403.tgz) doesn't exist in /usr/ports/packages/i386/all, downloading.
100% |**************************************************|  7803       00:00    
Adding http_ping-20020403
extracting /usr/local/bin/http_ping
extracting /usr/local/man/cat1/http_ping.0
/usr: 17412 bytes
$