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