Add check for required commands
parent
5d927399c7
commit
55cf17bf15
44
msfdb
44
msfdb
|
@ -906,6 +906,46 @@ def invoke_command(commands, component, command)
|
|||
end
|
||||
end
|
||||
|
||||
# Searches the user's path for the executable file that would be run had the
|
||||
# command actually been invoked.
|
||||
# @param cmd [String] command name
|
||||
# @param return_all [Boolean] If true, returns a list of all instances of
|
||||
# executable found (instead of just the first one). Default: false.
|
||||
# @return [Array] instance or instances of executable found based on return_all, or nil.
|
||||
def which(cmd, return_all: false)
|
||||
return nil if cmd.empty?
|
||||
|
||||
found = []
|
||||
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
||||
exe_file = File.join(path, cmd)
|
||||
found << exe_file if !File.directory?(exe_file) && File.executable?(exe_file)
|
||||
break if !return_all && found.size > 0
|
||||
end
|
||||
|
||||
return found.empty? ? nil : found
|
||||
end
|
||||
|
||||
def has_requirements
|
||||
ret_val = true
|
||||
postgresql_cmds = %w(psql pg_ctl initdb createdb)
|
||||
other_cmds = %w(bundle thin)
|
||||
missing_msg = 'Missing requirement: %<name>s does not appear to be installed or is not in the environment path'
|
||||
|
||||
unless postgresql_cmds.all? { |cmd| !which(cmd).nil? }
|
||||
puts missing_msg % { name: 'PostgreSQL' }
|
||||
ret_val = false
|
||||
end
|
||||
|
||||
other_cmds.each do |cmd|
|
||||
if which(cmd).nil?
|
||||
puts missing_msg % { name: "'#{cmd}'" }
|
||||
ret_val = false
|
||||
end
|
||||
end
|
||||
|
||||
ret_val
|
||||
end
|
||||
|
||||
|
||||
|
||||
if $PROGRAM_NAME == __FILE__
|
||||
|
@ -915,6 +955,10 @@ if $PROGRAM_NAME == __FILE__
|
|||
abort
|
||||
end
|
||||
|
||||
unless has_requirements
|
||||
abort
|
||||
end
|
||||
|
||||
# map component commands to methods
|
||||
commands = {
|
||||
database: {
|
||||
|
|
Loading…
Reference in New Issue