module Divvy
module Verifiers
# Checks to make sure path is a file on the remote server.
def has_file(path)
@commands << "test -f #{path}"
end
def file_contains(path, text)
@commands << "grep '#{text}' #{path}"
end
# Tests that the directory dir exists.
def has_directory(dir)
@commands << "test -d #{dir}"
end
# Checks if path is an executable script. This verifier is "smart" because
# if the path contains a forward slash '/' then it assumes you're checking an
# absolute path to an executable. If no '/' is in the path, it assumes you're
# checking for a global executable that would be available anywhere on the command line.
def has_executable(path)
# Be smart: If the path includes a forward slash, we're checking
# an absolute path. Otherwise, we're checking a global executable
if path.include?('/')
@commands << "test -x #{path}"
else
@commands << "[ -n \"`echo \\`which #{path}\\``\" ]"
end
end
# Checks to make sure process is a process running
# on the remote server.
def has_process(process)
@commands << "ps aux | grep '#{process}' | grep -v grep"
end
# Checks if ruby can require the files given. rubygems
# is always included first.
def ruby_can_load(*files)
# Always include rubygems first
files = files.unshift('rubygems').collect { |x| "require '#{x}'" }
@commands << "ruby -e \"#{files.join(';')}\""
end
# Checks if a gem exists by calling "sudo gem list" and grepping against it.
def has_gem(name, version=nil)
version = version.nil? ? '' : version.gsub('.', '\.')
@commands << "sudo gem list | grep -e '^#{name} (.*#{version}.*)$'"
end
# Checks that symlink is a symbolic link. If file is
# given, it checks that symlink points to file
def has_symlink(symlink, file = nil)
if file.nil?
@commands << "test -L #{symlink}"
else
@commands << "test '#{file}' = `readlink #{symlink}`"
end
end
end
end