specinfra 2.0.0.beta15 → 2.0.0.beta16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/specinfra.rb +1 -1
- data/lib/specinfra/command/aix/base/file.rb +15 -13
- data/lib/specinfra/command/aix/base/group.rb +5 -3
- data/lib/specinfra/command/aix/base/package.rb +7 -5
- data/lib/specinfra/command/aix/base/port.rb +5 -3
- data/lib/specinfra/command/aix/base/service.rb +7 -5
- data/lib/specinfra/command/aix/base/user.rb +10 -8
- data/lib/specinfra/command/arch/base/file.rb +4 -2
- data/lib/specinfra/command/arch/base/package.rb +17 -15
- data/lib/specinfra/command/arch/base/service.rb +3 -1
- data/lib/specinfra/command/base.rb +70 -68
- data/lib/specinfra/command/base/cron.rb +8 -6
- data/lib/specinfra/command/base/file.rb +94 -92
- data/lib/specinfra/command/base/group.rb +8 -6
- data/lib/specinfra/command/base/host.rb +18 -16
- data/lib/specinfra/command/base/mail_alias.rb +5 -3
- data/lib/specinfra/command/base/package.rb +36 -34
- data/lib/specinfra/command/base/port.rb +7 -5
- data/lib/specinfra/command/base/process.rb +10 -9
- data/lib/specinfra/command/base/routing_table.rb +6 -4
- data/lib/specinfra/command/base/service.rb +19 -17
- data/lib/specinfra/command/base/user.rb +24 -22
- data/lib/specinfra/command/darwin/base/file.rb +35 -33
- data/lib/specinfra/command/darwin/base/package.rb +12 -10
- data/lib/specinfra/command/darwin/base/port.rb +5 -3
- data/lib/specinfra/command/darwin/base/service.rb +7 -5
- data/lib/specinfra/command/debian/base/package.rb +16 -14
- data/lib/specinfra/command/debian/base/service.rb +5 -3
- data/lib/specinfra/command/fedora/base/service.rb +7 -6
- data/lib/specinfra/command/fedora/v15/service.rb +3 -1
- data/lib/specinfra/command/freebsd/base/file.rb +8 -6
- data/lib/specinfra/command/freebsd/base/package.rb +13 -11
- data/lib/specinfra/command/freebsd/base/port.rb +5 -3
- data/lib/specinfra/command/freebsd/base/service.rb +4 -2
- data/lib/specinfra/command/freebsd/v10/package.rb +13 -11
- data/lib/specinfra/command/gentoo/base/package.rb +4 -2
- data/lib/specinfra/command/gentoo/base/service.rb +9 -7
- data/lib/specinfra/command/linux/base/file.rb +10 -8
- data/lib/specinfra/command/linux/base/interface.rb +13 -11
- data/lib/specinfra/command/linux/base/iptables.rb +9 -7
- data/lib/specinfra/command/linux/base/kernel_module.rb +4 -2
- data/lib/specinfra/command/linux/base/lxc_container.rb +7 -5
- data/lib/specinfra/command/linux/base/selinux.rb +9 -7
- data/lib/specinfra/command/linux/base/zfs.rb +3 -1
- data/lib/specinfra/command/nixos/base/package.rb +12 -10
- data/lib/specinfra/command/nixos/base/service.rb +3 -1
- data/lib/specinfra/command/openbsd/base/file.rb +31 -29
- data/lib/specinfra/command/openbsd/base/interface.rb +8 -13
- data/lib/specinfra/command/openbsd/base/mail_alias.rb +4 -2
- data/lib/specinfra/command/openbsd/base/package.rb +10 -8
- data/lib/specinfra/command/openbsd/base/port.rb +4 -2
- data/lib/specinfra/command/openbsd/base/service.rb +7 -5
- data/lib/specinfra/command/openbsd/base/user.rb +8 -6
- data/lib/specinfra/command/opensuse/base/service.rb +3 -1
- data/lib/specinfra/command/plamo/base/package.rb +7 -5
- data/lib/specinfra/command/plamo/base/service.rb +6 -4
- data/lib/specinfra/command/redhat/base/file.rb +5 -3
- data/lib/specinfra/command/redhat/base/package.rb +14 -12
- data/lib/specinfra/command/redhat/base/service.rb +4 -2
- data/lib/specinfra/command/redhat/base/yumrepo.rb +7 -5
- data/lib/specinfra/command/redhat/v5/iptables.rb +7 -5
- data/lib/specinfra/command/redhat/v7/service.rb +3 -1
- data/lib/specinfra/command/smartos/base/package.rb +10 -8
- data/lib/specinfra/command/smartos/base/service.rb +7 -5
- data/lib/specinfra/command/solaris/base/cron.rb +8 -6
- data/lib/specinfra/command/solaris/base/file.rb +15 -13
- data/lib/specinfra/command/solaris/base/group.rb +5 -3
- data/lib/specinfra/command/solaris/base/host.rb +7 -5
- data/lib/specinfra/command/solaris/base/ipfilter.rb +4 -2
- data/lib/specinfra/command/solaris/base/ipnat.rb +5 -3
- data/lib/specinfra/command/solaris/base/package.rb +7 -5
- data/lib/specinfra/command/solaris/base/port.rb +9 -7
- data/lib/specinfra/command/solaris/base/service.rb +14 -13
- data/lib/specinfra/command/solaris/base/user.rb +10 -8
- data/lib/specinfra/command/solaris/base/zfs.rb +3 -1
- data/lib/specinfra/command/solaris/v10/file.rb +33 -31
- data/lib/specinfra/command/solaris/v10/group.rb +4 -2
- data/lib/specinfra/command/solaris/v10/host.rb +9 -7
- data/lib/specinfra/command/solaris/v10/package.rb +7 -5
- data/lib/specinfra/command/solaris/v10/user.rb +8 -6
- data/lib/specinfra/command/suse/base/package.rb +14 -12
- data/lib/specinfra/command/suse/base/service.rb +4 -2
- data/lib/specinfra/command/ubuntu/base/ppa.rb +11 -9
- data/lib/specinfra/command/ubuntu/base/service.rb +4 -2
- data/lib/specinfra/command/windows/base.rb +11 -10
- data/lib/specinfra/command/windows/base/feature.rb +11 -9
- data/lib/specinfra/command/windows/base/file.rb +72 -71
- data/lib/specinfra/command/windows/base/group.rb +7 -5
- data/lib/specinfra/command/windows/base/host.rb +18 -16
- data/lib/specinfra/command/windows/base/hot_fix.rb +13 -11
- data/lib/specinfra/command/windows/base/iis_app_pool.rb +11 -9
- data/lib/specinfra/command/windows/base/iis_website.rb +26 -24
- data/lib/specinfra/command/windows/base/package.rb +7 -5
- data/lib/specinfra/command/windows/base/port.rb +11 -9
- data/lib/specinfra/command/windows/base/process.rb +5 -3
- data/lib/specinfra/command/windows/base/registry_key.rb +36 -35
- data/lib/specinfra/command/windows/base/scheduled_task.rb +6 -4
- data/lib/specinfra/command/windows/base/service.rb +21 -19
- data/lib/specinfra/command/windows/base/user.rb +16 -14
- data/lib/specinfra/runner.rb +1 -2
- data/lib/specinfra/version.rb +1 -1
- data/spec/command/base_spec.rb +12 -4
- data/spec/command/module/systemd_spec.rb +14 -4
- data/spec/command/redhat/interface_spec.rb +1 -1
- metadata +1 -2
- data/lib/specinfra/command/smartos/tmp.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d14a86072b75b57a9623d3008288d7abcfc8a77
|
4
|
+
data.tar.gz: d19a4a7af63fe7137cf5e7a52ce35dae188cd6d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e44a954ee10cc6be369ed721885c7a6016c096d0811e72a06464468b56b86381e25b228a0d04d5177cb54e4830d431ce0a34026f7516ddab9badd6876547191
|
7
|
+
data.tar.gz: 33143b70844ac8fea1f5bd343d61380151ca23af594824791a41218e5f442c3a21769a6db9183566b4cb11e273a5e4fc0b8e73447b232e9a9e69becdb5b1e071
|
data/lib/specinfra.rb
CHANGED
@@ -1,19 +1,21 @@
|
|
1
1
|
class Specinfra::Command::Aix::Base::File < Specinfra::Command::Base::File
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
class << self
|
3
|
+
def check_is_accessible_by_user(file, user, access)
|
4
|
+
"su -s sh -c \"test -#{access} #{file}\" #{user}"
|
5
|
+
end
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
def check_has_mode(file, mode)
|
8
|
+
raise NotImplementedError.new('check_has_mode is not implemented in Specinfra::Command::AIX::Base::File')
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
def check_is_owned_by(file, owner)
|
12
|
+
regexp = "^#{owner}$"
|
13
|
+
"ls -al #{escape(file)} | awk '{print $3}' | grep -- #{escape(regexp)}"
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
def check_is_grouped(file, group)
|
17
|
+
regexp = "^#{group}$"
|
18
|
+
"ls -al #{escape(file)} | awk '{print $4}' | grep -- #{escape(regexp)}"
|
19
|
+
end
|
18
20
|
end
|
19
21
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
class Specinfra::Command::Aix::Base::Group < Specinfra::Command::Base::Group
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
class << self
|
3
|
+
def check_has_gid(group, gid)
|
4
|
+
regexp = "^#{group}"
|
5
|
+
"cat etc/group | grep -w -- #{escape(regexp)} | cut -f 3 -d ':' | grep -w -- #{escape(gid)}"
|
6
|
+
end
|
5
7
|
end
|
6
8
|
end
|
@@ -1,9 +1,11 @@
|
|
1
1
|
class Specinfra::Command::Aix::Base::Package < Specinfra::Command::Base::Package
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
class << self
|
3
|
+
def check_is_installed(package, version=nil)
|
4
|
+
if version
|
5
|
+
"lslpp -L #{escape(package)} | awk '{print $2}' | grep -w -- #{version}"
|
6
|
+
else
|
7
|
+
"lslpp -L #{escape(package)}"
|
8
|
+
end
|
7
9
|
end
|
8
10
|
end
|
9
11
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
class Specinfra::Command::Aix::Base::Port < Specinfra::Command::Base::Port
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
class << self
|
3
|
+
def check_is_listening(port, options={})
|
4
|
+
regexp = "*.#{port} "
|
5
|
+
"netstat -an -f inet | awk '{print $4}' | grep -- #{regexp}"
|
6
|
+
end
|
5
7
|
end
|
6
8
|
end
|
@@ -1,9 +1,11 @@
|
|
1
1
|
class Specinfra::Command::Aix::Base::Service < Specinfra::Command::Base::Service
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
class << self
|
3
|
+
def check_is_enabled(service,level=nil)
|
4
|
+
"lssrc -s #{escape(service)} | grep active"
|
5
|
+
end
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
def check_is_running(service)
|
8
|
+
"ps -ef | grep -v grep | grep #{escape(service)}"
|
9
|
+
end
|
8
10
|
end
|
9
11
|
end
|
@@ -1,13 +1,15 @@
|
|
1
1
|
class Specinfra::Command::Aix::Base::User < Specinfra::Command::Base::User
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
class << self
|
3
|
+
def check_belongs_to_group(user, group)
|
4
|
+
"lsuser -a groups #{escape(user)} | awk -F'=' '{print $2}'| sed -e 's/,/ /g' |grep -w -- #{escape(group)}"
|
5
|
+
end
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
def check_has_login_shell(user, path_to_shell)
|
8
|
+
"lsuser -a shell #{escape(user)} |awk -F'=' '{print $2}' | grep -w -- #{escape(path_to_shell)}"
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
def check_has_home_directory(user, path_to_home)
|
12
|
+
"lsuser -a home #{escape(user)} | awk -F'=' '{print $2}' | grep -w -- #{escape(path_to_home)}"
|
13
|
+
end
|
12
14
|
end
|
13
15
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
class Specinfra::Command::Arch::Base::File < Specinfra::Command::Linux::Base::File
|
2
|
-
|
3
|
-
|
2
|
+
class << self
|
3
|
+
def check_is_accessible_by_user(file, user, access)
|
4
|
+
"runuser -s /bin/sh -c \"test -#{access} #{file}\" #{user}"
|
5
|
+
end
|
4
6
|
end
|
5
7
|
end
|
6
8
|
|
@@ -1,22 +1,24 @@
|
|
1
1
|
class Specinfra::Command::Arch::Base::Package < Specinfra::Command::Linux::Base::Package
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
class << self
|
3
|
+
def check_is_installed(package,version=nil)
|
4
|
+
if version
|
5
|
+
"pacman -Q | grep #{escape(package)} #{escape(version)}"
|
6
|
+
else
|
7
|
+
"pacman -Q | grep #{escape(package)}"
|
8
|
+
end
|
7
9
|
end
|
8
|
-
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
def get_version(package, opts=nil)
|
12
|
+
"pacman -Qi #{package} | grep Version | awk '{print $3}'"
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
def install(package)
|
16
|
+
"pacman -S --noconfirm #{package}"
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
# Should this method be here or not ?
|
20
|
+
def sync_repos
|
21
|
+
"pacman -Syy"
|
22
|
+
end
|
21
23
|
end
|
22
24
|
end
|
@@ -1,92 +1,94 @@
|
|
1
1
|
require 'shellwords'
|
2
2
|
class Specinfra::Command::Base
|
3
|
-
|
3
|
+
class << self
|
4
|
+
@@types = nil
|
4
5
|
|
5
|
-
|
6
|
+
class NotImplementedError < Exception; end
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
def create
|
9
|
+
self
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
def escape(target)
|
13
|
+
str = case target
|
14
|
+
when Regexp
|
15
|
+
target.source
|
16
|
+
else
|
17
|
+
target.to_s
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
def method_missing(meth, *args)
|
23
|
-
action, resource_type, subaction = breakdown(meth)
|
24
|
-
method = action
|
25
|
-
method += "_#{subaction}" if subaction
|
26
|
-
command_object = command_class(resource_type).create
|
27
|
-
if command_object.respond_to?(method)
|
28
|
-
command_object.send(method, *args)
|
29
|
-
else
|
30
|
-
raise NotImplementedError.new("#{method} is not implemented in #{command_class(resource_type)}")
|
20
|
+
Shellwords.shellescape(str)
|
31
21
|
end
|
32
|
-
end
|
33
22
|
|
34
|
-
|
35
|
-
|
36
|
-
|
23
|
+
def method_missing(meth, *args)
|
24
|
+
action, resource_type, subaction = breakdown(meth)
|
25
|
+
method = action
|
26
|
+
method += "_#{subaction}" if subaction
|
27
|
+
command_class = create_command_class(resource_type)
|
28
|
+
if command_class.respond_to?(method)
|
29
|
+
command_class.send(method, *args)
|
30
|
+
else
|
31
|
+
raise NotImplementedError.new("#{method} is not implemented in #{command_class}")
|
32
|
+
end
|
33
|
+
end
|
37
34
|
|
38
|
-
|
39
|
-
|
40
|
-
|
35
|
+
def create_command_class(resource_type)
|
36
|
+
family = os[:family]
|
37
|
+
version = os[:release] ? "V#{os[:release].to_i}" : nil
|
38
|
+
|
39
|
+
common_class = self.class.const_get('Specinfra').const_get('Command')
|
40
|
+
base_class = common_class.const_get('Base')
|
41
|
+
os_class = family.nil? ? base_class : common_class.const_get(family.capitalize)
|
42
|
+
|
43
|
+
if family && version
|
44
|
+
begin
|
45
|
+
version_class = os_class.const_get(version)
|
46
|
+
rescue
|
47
|
+
version_class = os_class.const_get('Base')
|
48
|
+
end
|
49
|
+
elsif family.nil?
|
50
|
+
version_class = os_class
|
51
|
+
elsif family != 'base' && version.nil?
|
52
|
+
version_class = os_class.const_get('Base')
|
53
|
+
end
|
41
54
|
|
42
|
-
if family && version
|
43
55
|
begin
|
44
|
-
|
56
|
+
command_class = version_class.const_get(resource_type.to_camel_case)
|
45
57
|
rescue
|
46
|
-
version_class = os_class.const_get('Base')
|
47
58
|
end
|
48
|
-
elsif family.nil?
|
49
|
-
version_class = os_class
|
50
|
-
elsif family != 'base' && version.nil?
|
51
|
-
version_class = os_class.const_get('Base')
|
52
|
-
end
|
53
59
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
60
|
+
if command_class.nil? ||( (command_class < Specinfra::Command::Base).nil? && (command_class < Specinfra::Command::Windows::Base).nil? )
|
61
|
+
command_class = base_class.const_get(resource_type.to_camel_case)
|
62
|
+
end
|
58
63
|
|
59
|
-
|
60
|
-
command_klass = base_class.const_get(resource_type.to_camel_case)
|
64
|
+
command_class.create
|
61
65
|
end
|
62
66
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
raise message
|
67
|
+
private
|
68
|
+
def breakdown(meth)
|
69
|
+
types = resource_types.map {|t| t.to_snake_case }.join('|')
|
70
|
+
md = meth.to_s.match(/^([^_]+)_(#{types})_?(.+)?$/)
|
71
|
+
if md.nil?
|
72
|
+
message = "Could not break down `#{meth}' to appropriate type and method.\n"
|
73
|
+
message += "The method name shoud be in the form of `action_type_subaction'."
|
74
|
+
raise message
|
75
|
+
end
|
76
|
+
return md[1], md[2], md[3]
|
74
77
|
end
|
75
|
-
return md[1], md[2], md[3]
|
76
|
-
end
|
77
78
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
79
|
+
def resource_types
|
80
|
+
if @@types.nil?
|
81
|
+
@@types = []
|
82
|
+
Specinfra::Command::Base.subclasses.each do |s|
|
83
|
+
@@types << s.to_s.split(':')[-1]
|
84
|
+
end
|
85
|
+
Specinfra::Command::Windows::Base.subclasses.each do |s|
|
86
|
+
@@types << s.to_s.split(':')[-1]
|
87
|
+
end
|
88
|
+
@@types.uniq!
|
86
89
|
end
|
87
|
-
|
90
|
+
@@types
|
88
91
|
end
|
89
|
-
@types
|
90
92
|
end
|
91
93
|
end
|
92
94
|
|
@@ -1,10 +1,12 @@
|
|
1
1
|
class Specinfra::Command::Base::Cron < Specinfra::Command::Base
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
class << self
|
3
|
+
def check_has_entry(user, entry)
|
4
|
+
entry_escaped = entry.gsub(/\*/, '\\*').gsub(/\[/, '\\[').gsub(/\]/, '\\]')
|
5
|
+
if user.nil?
|
6
|
+
"crontab -l | grep -v \"#\" -- | grep -- #{escape(entry_escaped)}"
|
7
|
+
else
|
8
|
+
"crontab -u #{escape(user)} -l | grep -v \"#\" | grep -- #{escape(entry_escaped)}"
|
9
|
+
end
|
8
10
|
end
|
9
11
|
end
|
10
12
|
end
|
@@ -1,95 +1,97 @@
|
|
1
1
|
class Specinfra::Command::Base::File < Specinfra::Command::Base
|
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
|
-
from
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
2
|
+
class << self
|
3
|
+
def check_is_file(file)
|
4
|
+
"test -f #{escape(file)}"
|
5
|
+
end
|
6
|
+
|
7
|
+
def check_is_directory(directory)
|
8
|
+
"test -d #{escape(directory)}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def check_is_socket(file)
|
12
|
+
"test -S #{escape(file)}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def check_contains(file, expected_pattern)
|
16
|
+
"#{check_file_contains_with_regexp(file, expected_pattern)} || #{check_file_contains_with_fixed_strings(file, expected_pattern)}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def check_is_grouped(file, group)
|
20
|
+
regexp = "^#{group}$"
|
21
|
+
"stat -c %G #{escape(file)} | grep -- #{escape(regexp)}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def check_is_owned_by(file, owner)
|
25
|
+
regexp = "^#{owner}$"
|
26
|
+
"stat -c %U #{escape(file)} | grep -- #{escape(regexp)}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def check_has_mode(file, mode)
|
30
|
+
regexp = "^#{mode}$"
|
31
|
+
"stat -c %a #{escape(file)} | grep -- #{escape(regexp)}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def check_contains_within(file, expected_pattern, from=nil, to=nil)
|
35
|
+
from ||= '1'
|
36
|
+
to ||= '$'
|
37
|
+
sed = "sed -n #{escape(from)},#{escape(to)}p #{escape(file)}"
|
38
|
+
checker_with_regexp = check_file_contains_with_regexp("-", expected_pattern)
|
39
|
+
checker_with_fixed = check_file_contains_with_fixed_strings("-", expected_pattern)
|
40
|
+
"#{sed} | #{checker_with_regexp} || #{sed} | #{checker_with_fixed}"
|
41
|
+
end
|
42
|
+
|
43
|
+
def check_contains_lines(file, expected_lines, from=nil, to=nil)
|
44
|
+
require 'digest/md5'
|
45
|
+
from ||= '1'
|
46
|
+
to ||= '$'
|
47
|
+
sed = "sed -n #{escape(from)},#{escape(to)}p #{escape(file)}"
|
48
|
+
head_line = expected_lines.first.chomp
|
49
|
+
lines_checksum = Digest::MD5.hexdigest(expected_lines.map(&:chomp).join("\n") + "\n")
|
50
|
+
afterwards_length = expected_lines.length - 1
|
51
|
+
"#{sed} | grep -A #{escape(afterwards_length)} -F -- #{escape(head_line)} | md5sum | grep -qiw -- #{escape(lines_checksum)}"
|
52
|
+
end
|
53
|
+
|
54
|
+
def check_contains_with_regexp(file, expected_pattern)
|
55
|
+
"grep -q -- #{escape(expected_pattern)} #{escape(file)}"
|
56
|
+
end
|
57
|
+
|
58
|
+
def check_contains_with_fixed_strings(file, expected_pattern)
|
59
|
+
"grep -qF -- #{escape(expected_pattern)} #{escape(file)}"
|
60
|
+
end
|
61
|
+
|
62
|
+
def check_has_md5checksum(file, expected)
|
63
|
+
regexp = "^#{expected}"
|
64
|
+
"md5sum #{escape(file)} | grep -iw -- #{escape(regexp)}"
|
65
|
+
end
|
66
|
+
|
67
|
+
def check_has_sha256checksum(file, expected)
|
68
|
+
regexp = "^#{expected}"
|
69
|
+
"sha256sum #{escape(file)} | grep -iw -- #{escape(regexp)}"
|
70
|
+
end
|
71
|
+
|
72
|
+
def get_content(file)
|
73
|
+
"cat #{file} 2> /dev/null || echo -n"
|
74
|
+
end
|
75
|
+
|
76
|
+
def check_is_mounted(path)
|
77
|
+
regexp = "on #{path}"
|
78
|
+
"mount | grep -w -- #{escape(regexp)}"
|
79
|
+
end
|
80
|
+
|
81
|
+
def get_mode(file)
|
82
|
+
"stat -c %a #{escape(file)}"
|
83
|
+
end
|
84
|
+
|
85
|
+
def check_is_linked_to(link, target)
|
86
|
+
"stat -c %N #{escape(link)} | egrep -e \"-> .#{escape(target)}.\""
|
87
|
+
end
|
88
|
+
|
89
|
+
def get_mtime(file)
|
90
|
+
"stat -c %Y #{escape(file)}"
|
91
|
+
end
|
92
|
+
|
93
|
+
def get_size(file)
|
94
|
+
"stat -c %s #{escape(file)}"
|
95
|
+
end
|
94
96
|
end
|
95
97
|
end
|