forked from sprinkle-tool/sprinkle
/
file.rb
35 lines (33 loc) · 1.02 KB
/
file.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
module Sprinkle
module Verifiers
# = File Verifier
#
# Contains a verifier to check the existance of a file.
#
# == Example Usage
#
# verify { has_file '/etc/apache2/apache2.conf' }
#
# verify { file_contains '/etc/apache2/apache2.conf', 'mod_gzip'}
#
module File
Sprinkle::Verify.register(Sprinkle::Verifiers::File)
# Checks to make sure <tt>path</tt> 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
def user_present(username)
has_user username
end
def matches_local(localfile, remotefile, mode=nil)
raise "Couldn't find local file #{localfile}" unless ::File.exists?(localfile)
require 'digest/md5'
local = Digest::MD5.hexdigest(::File.read(localfile))
@commands << %{[ "X$(md5sum #{remotefile}|cut -d\\ -f 1)" = "X#{local}" ]}
end
end
end
end