PDA

View Full Version : setting $PKGDIR screws up port installations


TerryP
06-26-2008, 08:22 PM
I just switched my laptop from PC-BSD 1.5.1.x to FreeBSD 7.0-Release and I noticed something odd.


I setenv PKGDIR to a safe spot and went about installing packages and ports through a shell script but, when it tried to install some apps via ports with PKGDIR set, they would barf pkg-descr not found style messages.


Doing it by hand using makes -i/-k switches things worked (but probably not smart), things also worked perfectly *normal* when the PKGDIR environment variable was not set when I went to install individual ports.


I found this kinda odd because I don't recall the ports manual saying it honoured PKGDIR. However, /usr/ports/*.mk has a concept of ${PKGDIR}/pkg-* when looking for files such as pkg-descr, pkg-plist, and such.


Grr !

Carpetsmoker
06-26-2008, 08:30 PM
First of all, why are you manually setting PKGDIR?

If I understand it correctly, PKGDIR is the directory containing all the ports files (pkg-descr, pkg-plist, files/ etc.) so I'm not surprised that ports fail o build if you set it to something odd.
I'm also not sure if setting PKGDIR actually has any effect when installing packages.

lvlamb
06-26-2008, 08:40 PM
Help my failing eyes or my obsolete glasses,
but I don't see a PKGDIR environment you can set in the ports manpage for FreeBSD-7

Carpetsmoker
06-26-2008, 08:46 PM
grep PKGDIR /ports/Mk/bsd.port.mk

ohauer
06-26-2008, 08:49 PM
I do this the following way since 5.1 with no hassle

file:/etc/fstab

/space2/ports /usr/ports nullfs rw,noatime 0 0

file:/etc/portsnap.conf

PORTSDIR=/space2/ports

file:/etc/make.conf

PACKAGES?= /space1/packages
WRKDIR?= /build_space/PORTBUILD/${PORTNAME}_${PORTVERSION}
DISTDIR?= /big_space/distfiles

.if ${HOSTNAME} != "MachineWithAllTheDistfiles"
MASTER_SITE_BACKUP=ftp://MachineWithAllTheDistfiles/pub/distfiles/${DIST_SUBDIR}/
MASTER_SITE_OVERRIDE?=${MASTER_SITE_BACKUP}
.endif


With WRKDIR set in make.conf php ports cannot be builded if build-recursive contains more then one php port

So i have one central machine that updates every subscribed machine with rsync and portsnap gets all installed ports with the command
pkg_info -qoa
and fetch new distfiles from all collected ports

lvlamb
06-26-2008, 10:27 PM
Snippet from my /etc/make.conf

PORTSDIR=/data/fbsd/ports/
WRKDIRPREFIX=/sandbox/obj/
DISTDIR=/data/distfiles/
PACKAGES=/data/fbsd/packages/


I prefer to set WRKDIRPREFIX to WRKDIR as some sourrces are sensitive.

/sandbox and /data are slices
/sandox is just that, I can newfs the whole slice fatster than a make clean

In fact, I share those slices.

My OpenBSD /etc/mk.conf snippet :
PORTSDIR=/data/obsd/ports
DISTDIR=/data/distfiles
PACKAGE_REPOSITORY=/data/obsd/packages44
PKG_CACHE=/data/obsd/packages44
WRKOBJDIR=/sandbox/pobj
MAKEOBJDIR=/sandbox/sobj
XSRCDIR=/data/obsd/xenocara
XOBJDIR=/sandbox/xobj

TerryP
06-26-2008, 10:29 PM
pkg_add[/fman]"]
The environment variable PKGDIR specifies an alternative location to save
downloaded packages to when -K option is used.


Which is specifically what I wanted to do and why PKGDIR was set ;-)


When I first planned out the operation, I checked the manual for two reasons:

0/ What environment variable controls where packages can be saved? -- found

1/ What environment variables effect port builds -- found but incomplete



When I have issues with ports, I just go to the Makefiles and trace my fingers along the code until I find my way.


In this case, I was adding packages in sequence via bourne shell script and stopping to install ports in a sub shell when necessary (no package available or out of date).


And found no logical reason to poke around the ports systems internal makefile, since I would naturally look in the end user documentation on orts and pkg_* for how to avoid shooting myself in the foot with environment variables ^_^


My systems almost fully operational and ready to rock & roll. Just a few more things to install via ports (with PKGDIR unset) and a kernel to compile and volia.


While the saved packages get off loaded to be placed in cold storage in, just in case I need a backup of 4 hours worth of fetching at a later date :eek:.

lvlamb
06-26-2008, 11:41 PM
OK!

With pkg_add you may define an alternative directory PKGDIR to save the packages to.

While PKG_PATH is where pkg_add expects to find the packages.

The value of the PKG_PATH is used if a given package cannot be found.
The environment variable should be a series of entries separated by
colons. Each entry consists of a directory name.

Hence, $PKGDIR has to be added (or prepended) to the directories list, default /usr/ports/packages.
Why use an alternative to PKG_PATH ? Errr ... Yup! PKGDIR can be a CDROM, files saved rw to PKG_PATH, PKGDIR a ro CDROM, or the other way, and vice versa.

While PACKAGESITE should be set to a "mirror_close_to_you" for remote install.
PACKAGESITE only understands URL and fetch, while PKG_PATH only reads directories.

Now I understand why there is a subdirectory /usr/ports/ports-mgmt in FreeBSD tree.

Yeesh! Glad my default OS is OpenBSD :D

Carpetsmoker
06-27-2008, 12:38 AM
PKGDIR has different meanings for ports and packages.

From /usr/ports/Mk/bsd.port.mk


# PKGDIR - A directory containing any package creation files.
# Default: ${MASTERDIR}
[...]
PATCHDIR?= ${MASTERDIR}/files
FILESDIR?= ${MASTERDIR}/files
SCRIPTDIR?= ${MASTERDIR}/scripts
PKGDIR?= ${MASTERDIR}
[...]
DESCR?= ${PKGDIR}/pkg-descr
PLIST?= ${PKGDIR}/pkg-plist
PKGINSTALL?= ${PKGDIR}/pkg-install
PKGDEINSTALL?= ${PKGDIR}/pkg-deinstall
PKGREQ?= ${PKGDIR}/pkg-req
PKGMESSAGE?= ${PKGDIR}/pkg-message
[...]

Those are ALL the appearances of PKGDIR in bsd.port.mk, so PKGDIR is the port directory (i.e. /usr/ports/www/opera).

If you want to use a different package directory for ports, use PACKAGES.
# PACKAGES - A top level directory where all packages go (rather than
# going locally to each port).
# Default: ${PORTSDIR}/packages

So let's look at pkg_* source:
[/usr/src/usr.sbin/pkg_install]% find . -type f -exec grep -H PKGDIR {} \;
./add/pkg_add.1:.Ev PKGDIR
./add/pkg_add.1:.Ev PKGDIR
./info/pkg_info.1:.Ev PKGDIR
./info/pkg_info.1:.It Ev PKGDIR
./lib/url.c: tmp = getenv("PKGDIR");

So, lets look at /usr/src/usr.sbin/pkg_install/lib/url.c (Other 4 files are manpages)
if (keep_package) {
tmp = getenv("PKGDIR");
strlcpy(pkg, tmp ? tmp : ".", sizeof(pkg));
tmp = basename(fname);
strlcat(pkg, "/", sizeof(pkg));
strlcat(pkg, tmp, sizeof(pkg));
if ((pkgfd = open(pkg, O_WRONLY|O_CREAT|O_TRUNC, 0644)) == -1) {
printf("Error: Unable to open %s\n", pkg);
perror("open");
return NULL;
}
}

So for pkg_* it is indeed the directory/URL to find packages in ... Totally different meaning than for ports.

I know, this is not the best design choice ... And maybe renaming one of the variables might be a good idea...

TerryP
06-27-2008, 04:45 AM
or adding it to the bloody manual page along with any friends it might have ;-)