Checking external dependencies during the installation

Dear list member,

I'm packaging some scripts as gems on my Linux based box, and I need to
check during the runtime after the first script invocation if all
external dependences (like e.g. `ls`) are installed and present on the
machine.

A couple of weeks ago I found a mention about a working library, but
totally forgot the library name and cannot find it again.

Any ideas what it the best tool for checking for external dependencies?

Thanks in advance,

arbox

Hi,

(like e.g. `ls`)

For this particular task you should probably better be using Ruby's
internal Dir.glob/Dir.foreach methods or the Find module from the
stdlib.

check during the runtime after the first script invocation if all
external dependences

I don’t know of a library that does this, but you can certainly code
something up as it's not too complicated. A very easy approach would be
to use the #system method and check if invocation of the program in
question is possible by checking its return value. A more complete
approach would search ENV["PATH"] (and additionally try an invocation).

A quick’n’dirty solution that searches PATH and tries to invocate the
program with the "--help" switch to see it is present and works:

def find_program(progname)
  ENV["PATH"].each do |dir|
    Dir.foreach(dir) do |filename|
      if filename == progname
        full_path = "#{dir}/#{filename}"
        if system("#{full_path} --help")
          return full_path
        end
      end
    end
  end

  false
end

This is untested. It can certainly be improved, but you get the general
idea.

Greetings
Marvin

···

Am Thu, 26 May 2016 22:35:56 +0200 schrieb Andrei Beliankou <arbox@yandex.ru>:

--
Blog: http://www.guelkerdev.de
PGP/GPG ID: F1D8799FBCC8BC4F

Thank you, Marvin,

I don’t know of a library that does this, but you can certainly code

yes, I'm aware of `system` based approaches and use it now.

Google is damn unreliable... I found this library a couple of weeks ago,
and now I cannot...

Best,
arbox