Solved How to update makewhatis(8) every time the port is installed?

I usually have a situation that I have just installed a port and I immediately want to find an appropriate manual page for it using apropos(1), but it can't locate it. The reason why is that apropos(1) uses the database generated by makewhatis(8) and since it has not been re-generated after the installation of a port, it doesn't contain the entry for these new manual pages.

There's a periodic(8) job /etc/periodic/weekly/320.whatis, which updates this database using a wrapper-script /usr/libexec/makewhatis.local on a weekly basis. It's just once a week, so every time I encounter a situation like that, I end up running /usr/libexec/makewhatis.local manually. It works, but it's somewhat cumbersome. It's just seems to me that updating this database once a week (which is a system default) doesn't make much sense, since you almost always would need a manual page for a program in less than a week after you installed it.

I want to know, it is possible to maybe make this command run every time the port or a pkg(8) is installed?
Or, if not, maybe some of you can share some tips on how to manage makewhatis(8) in a more nice manner?
 
Yeah, you can simply run that (or any other) periodic script from the command line. periodic(8) isn't some special environment, it's basically a bunch of shell scripts that get kicked off via cron(8).
 
Maybe totally not the objective but I would add a script in my shell path that keeps a copy of the pkg info output and compares this with the current situation to see if a new port or package has been added. If that's the case, use the output of pkg info -l <package> to find manual pages that belong to it.
 
You can set a script to execute whenever a package touches a directory with pkg-triggers(5).
There are probably other examples in /usr/local/share/pkg/triggers/.
Yes, this works! I created /usr/local/shared/pkg/triggers/mandoc.ucl (essentially copied it from /usr/share/pkg/triggers/mandoc.ucl, just changed /usr/share/... to /usr/local/share/...):
Code:
path_glob: [
    "/usr/local/share/man/*",
    "/usr/local/share/openssl/man/*",
]

cleanup: {
    type: lua
    sandbox: false
    script: <<EOD
    os.remove("/usr/local/share/man/mandoc.db")
    os.remove("/usr/local/share/man/mandoc.db")
EOD
}

trigger: {
    type: lua
    sandbox: false
    script: <<EOD

    local dirs = {
        "/usr/local/share/man",
        "/usr/local/share/openssl/man",
    }

    for _,dir in ipairs(dirs) do
        if pkg.stat(dir) then
            print("Generating apropos(1) database for "..dir.."...")
            pkg.exec({"/usr/bin/makewhatis", dir})
        end
    end
EOD
}

Now every time I install or remove a package that has a man page, the following message is printed:
Code:
==> Running trigger: mandoc.ucl
Generating apropos(1) database for /usr/local/share/man...

So neat! Thanks jwillia3!
 
Back
Top