06 April 2007

Setting multiple package sites

In a previous post, I discussed how to set the environment variable PACKAGESITE such that your various package tools would fetch the more recent packages instead of the release packages.* We specified a full URL there, so you could change the ftp server to one closer to you as well in the same variable.

If you're changing the server, say from 'ftp.freebsd.org' to 'ftp2.freebsd.org', the question naturally arises: what if ftp2 doesn't work today or just doesn't have the particular package I'm trying to fetch? It's a good question because it seems that the mirrors don't always carry everything or have the latest files. (... Which I say, rather unfairly, based on one missing ISO I was looking for on one mirror a couple of months ago.)

I've found one solution in the pkg_fetch man page. There it mentions an environment variable called PKG_SITES, which does exactly what we want: you fill it with a space-separated list of URL's. If the first URL fails when a pkg_fetch is tried, it tries the next, etc. Furthermore, portupgrade uses pkg_fetch when it is set to use packages (with '-P'). That makes me all warm inside. (In case you can't find it, pkg_fetch is part of the portupgrade port.)

But, there are some issues to be aware of. First, you do NOT specify the full URL like we did with PACKAGESITE. You leave off that last sub-directory (was 'Latest/' in that case). With PKG_SITES, each fetch request will have that last sub-directory appended depending on whether or not there was a version specified on the package name it was asked for. Has-version means it will use 'All/' and no version suffix means it will append 'Latest/'. Everything in 'Latest/' is just a link to something else in 'All/' anyway.

Other issues. PACKAGESITE, if present, will override PKG_SITES. pkg_add is not aware of PKG_SITES. And pkg_fetch, naturally, only fetches the packages and does not install them. I'm still pondering all of this because I do like to use 'pkg_add -r' and now there could be some environment issues with portupgrade/pkg_fetch. ('env' to the rescue, perhaps.)

And, finally, the obligatory example (with too much line wrapping :/) :

# PKG_SITES='ftp://ftp11.freebsd.org/pub/FreeBSD/ports/i386/packages-6-stable/ ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-6-stable/'
# export PKG_SITES
# pkg_fetch ubench
---> Fetching ubench
fetch: ftp://ftp11.freebsd.org/pub/FreeBSD/ports/i386/packages-6-stable/Latest/ubench.tbz: Connection refused
** The command returned a non-zero exit status: 1
** Failed to fetch ftp://ftp11.freebsd.org/pub/FreeBSD/ports/i386/packages-6-stable/Latest/ubench.tbz
fetch: ftp://ftp11.freebsd.org/pub/FreeBSD/ports/i386/packages-6-stable/Latest/ubench.tgz: Connection refused
** The command returned a non-zero exit status: 1
** Failed to fetch ftp://ftp11.freebsd.org/pub/FreeBSD/ports/i386/packages-6-stable/Latest/ubench.tgz
/var/tmp/portupgradepSBOcGHE/ubench.tbz 100% of 8348 B 17 kBps
---> Downloaded as ubench.tbz
---> Identifying the package /var/tmp/portupgradepSBOcGHE/ubench.tbz
---> Saved as /usr/ports/packages/All/ubench-0.32.tbz
#


* Update

This method isn't working right now! If you're on 6.0-6.2, you'd better do all your port upgrades by compiling for now. More here.

Labels: