Build a package for the "which" command

I don't want to build the whole FreeBSD Base system.

I just want to build a package for the "which" executable.

Is there a way to do this in FreeBSD?

Why?

...because I have a FreeNAS system. This FreeNAS system is a stripped down version of FreeBSD 7.3 that is missing many executables. I want my "which" command back.

Once the package is created on my FreeBSD system, I'll move it over to my FreeNAS system and install it.
 
Theoretically you can just take the binary from a FreeBSD 7.3 system and just copy it over. But keep in mind that FreeBSD 7 is end-of-life, support for the last, 7.4, ended in February 2013. Even FreeNAS doesn't support it any more.
 
I understand that I can copy the "/usr/bin/which" file from my FreeBSD platform to my FreeNAS box, but that doesn't answer my question.

Listen, the "which" command has dynamically linked libraries to it. It wouldn't be a good thing to do to just copy it over.

So my original question is:

Can I build a package for the " which" command, using source, and ....how would I do it?

BTW: I already know that FreeNAS 7.x and FreeBSD 7.x are old.
 
Well, again theoretically, since FreeNAS 7.3 is based on FreeBSD 7.3 I would guess they each have the same libraries too. Certainly when it comes to the base userland. You may be able to coax the ports system into creating a package for you but it was never meant to be used like that.
 
If you have basic scripting skills, you could write your own replacement. All which(1) does is search the user's PATH for executables matching the list of provided name(s).
 
The "/usr/bin/which" file is only linked to the "/lib/libc.so.7" library and FreeNAS has that file. So I could just copy over "/usr/bin/which" in this instance.

The issue is this...

I might run into a FreeBSD base system binary (in the future) that links to a library that FreeNAS does not have and then I would be screwed. I wouldn't be able to just copy over the binary from the FreeBSD platform to my FreeNAS box in this case

This is why I wanted to learn how to create a package of a Base system binary from source.
 
Well, you could always use /usr/src/usr.bin/which (assuming you've downloaded source) and see if you can make(1) it as a stand-alone program on FreeNAS. It has it's own Makefile. But I think this approach is fraught with perils. I would not expect the specialized FreeBSD *.mk files to play nicely on FreeNAS.
 
If you require any newer executables you're probably better off simply upgrading FreeNAS to the latest version. Pick a 9 version, it has proven itself for some time now and it'll be supported until around 2016 (I'm expecting a 9.3-RELEASE some time this year).

As a stop gap, and if you have access to a recent FreeBSD, you can build most base userland tools statically. Then it would include all the needed libraries in one (big) executable. Mind you some tools will not work if they need to talk to the kernel. You can run older executables on newer versions of the kernel (Using COMPAT_FREEBSD7 etc.) but not the other way around.
 
There were some people using pkg(8) to build packages for portions of the operating system. Don't know the current status of that.

You might ask the FreeNAS people to add an option to install the rest of FreeBSD on an existing FreeNAS system. Certainly we see enough people here asking for missing pieces.
 
Niatross said:
The "/usr/bin/which" file is only linked to the "/lib/libc.so.7" library and FreeNAS has that file. So I could just copy over "/usr/bin/which" in this instance.

The issue is this...

I might run into a FreeBSD base system binary (in the future) that links to a library that FreeNAS does not have and then I would be screwed. I wouldn't be able to just copy over the binary from the FreeBSD platform to my FreeNAS box in this case

This is why I wanted to learn how to create a package of a Base system binary from source.

The base system is not meant to be packaged as individual packages. It's a monolitic blob meant to be installed/upgraded/managed as a single unit, controlled via /etc/make.conf and/or /etc/src.conf.

What you want to do is not (easily) possible.

Your better solution is:
  • install FreeBSD 7.3 somewhere (VM is fine)
  • run # ldd /path/to/which and make note of the libraries it links to
  • check FreeNAS system to see which of those libraries are installed and which are missing
  • use tar(1) to create a tarball of the binary and any missing libraries, using full paths from the root filesystem (/)
  • extract tarball on the FreeNAS system
  • repeat for each binary you want to add to the FreeNAS system
 
Back
Top