Question

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.

Was it helpful?

Solution

I ended up doing this:

package.json:

{ 
  "scripts": {
    "preinstall": "./bin/install_check.sh"
  }
}

bin/install_check.sh:

#!/bin/bash

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;
fi

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top