Module: Sprinkle::Verifiers::Executable

Defined in:
lib/sprinkle/verifiers/executable.rb

Overview

Executable Verifier

Contains a verifier to check the existance of an executable script on your server.

Example Usage

First, absolute path to an executable:

verify { has_executable '/usr/special/secret/bin/scipt' }

Second, a global executable which would be available anywhere on the command line:

verify { has_executable 'grep' }

Instance Method Summary collapse

Instance Method Details

#has_executable(path) ⇒ Object

Checks if path is an executable script using which

  • accepts both absolute paths and binary names with no path



23
24
25
# File 'lib/sprinkle/verifiers/executable.rb', line 23

def has_executable(path)
  @commands << "which #{path}"
end

#has_executable_with_version(path, version, get_version = '-v') ⇒ Object

Same as has_executable but with checking for e certain version number. Last option is the parameter to append for getting the version (which defaults to ā€œ-vā€).



30
31
32
33
34
35
36
# File 'lib/sprinkle/verifiers/executable.rb', line 30

def has_executable_with_version(path, version, get_version = '-v')
  if path.include?('/')
    @commands << "[ -x #{path} -a -n \"`#{path} #{get_version} 2>&1 | egrep -e \\\"#{version}\\\"`\" ]"
  else
    @commands << "[ -n \"`echo \\`which #{path}\\``\" -a -n \"`\\`which #{path}\\` #{get_version} 2>&1 | egrep -e \\\"#{version}\\\"`\" ]"
  end
end

#has_version_in_grep(cmd, version) ⇒ Object

Same as has_executable but checking output of a certain command with grep.



40
41
42
# File 'lib/sprinkle/verifiers/executable.rb', line 40

def has_version_in_grep(cmd, version)
  @commands << "[ -n \"`#{cmd} 2> /dev/null | egrep -e \\\"#{version}\\\"`\" ]"
end