Check if libpam headers are available


In my Node.js application, I use pam authentication and the module I use requires libpam-dev (or pam-devel) to be installed or it won't compile. The error messages it generates aren't very user friendly, and many people won't be bothered to read the docs.

I'd like to use the preinstall hook in NPM to check if the headers are available, and if not, display a friendly error and then kill NPM before it tries to install the module.

I know how to kill NPM, just not how to check if pam headers are available. The solution should be be distro-agnostic.

Problem courtesy of: Brandon Wamboldt


I ended up doing this:


  "scripts": {
    "preinstall": "./bin/"



if [ `echo '#include <security/pam_appl.h>' | cpp -H -o /dev/null 2>&1 | head -n1 | grep 'fatal error' | wc -l` == "1" ]; then
  echo "nodeftpd: Please install the libpam-dev package";
  exit 1;

I wasn't able to figure out how to avoid needed a separate script.

Solution courtesy of: Brandon Wamboldt


There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.