chef 0.9.6 → 0.9.8.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. data/lib/chef/application.rb +19 -3
  2. data/lib/chef/application/client.rb +7 -8
  3. data/lib/chef/application/knife.rb +9 -3
  4. data/lib/chef/application/solo.rb +5 -5
  5. data/lib/chef/cache/checksum.rb +2 -2
  6. data/lib/chef/client.rb +30 -64
  7. data/lib/chef/config.rb +52 -30
  8. data/lib/chef/cookbook/metadata.rb +12 -1
  9. data/lib/chef/cookbook_site_streaming_uploader.rb +211 -0
  10. data/lib/chef/cookbook_uploader.rb +102 -0
  11. data/lib/chef/cookbook_version.rb +47 -30
  12. data/lib/chef/couchdb.rb +1 -11
  13. data/lib/chef/exceptions.rb +1 -0
  14. data/lib/chef/file_access_control.rb +1 -1
  15. data/lib/chef/index_queue/amqp_client.rb +10 -3
  16. data/lib/chef/knife.rb +154 -58
  17. data/lib/chef/knife/bootstrap.rb +84 -48
  18. data/lib/chef/knife/bootstrap/centos5-gems.erb +41 -0
  19. data/lib/chef/knife/bootstrap/fedora13-gems.erb +38 -0
  20. data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +44 -0
  21. data/lib/chef/knife/client_bulk_delete.rb +1 -1
  22. data/lib/chef/knife/client_create.rb +1 -1
  23. data/lib/chef/knife/client_delete.rb +1 -1
  24. data/lib/chef/knife/client_edit.rb +1 -1
  25. data/lib/chef/knife/client_list.rb +1 -1
  26. data/lib/chef/knife/client_reregister.rb +1 -1
  27. data/lib/chef/knife/client_show.rb +1 -1
  28. data/lib/chef/knife/configure.rb +1 -1
  29. data/lib/chef/knife/configure_client.rb +1 -1
  30. data/lib/chef/knife/cookbook_bulk_delete.rb +1 -1
  31. data/lib/chef/knife/cookbook_create.rb +159 -0
  32. data/lib/chef/knife/cookbook_delete.rb +6 -6
  33. data/lib/chef/knife/cookbook_download.rb +1 -1
  34. data/lib/chef/knife/cookbook_list.rb +1 -1
  35. data/lib/chef/knife/cookbook_metadata.rb +1 -1
  36. data/lib/chef/knife/cookbook_metadata_from_file.rb +1 -1
  37. data/lib/chef/knife/cookbook_show.rb +1 -1
  38. data/lib/chef/knife/cookbook_site_download.rb +2 -1
  39. data/lib/chef/knife/cookbook_site_list.rb +2 -1
  40. data/lib/chef/knife/cookbook_site_search.rb +2 -1
  41. data/lib/chef/knife/cookbook_site_share.rb +108 -0
  42. data/lib/chef/knife/cookbook_site_show.rb +2 -1
  43. data/lib/chef/knife/cookbook_site_unshare.rb +52 -0
  44. data/lib/chef/knife/cookbook_site_vendor.rb +3 -2
  45. data/lib/chef/knife/cookbook_test.rb +1 -1
  46. data/lib/chef/knife/cookbook_upload.rb +22 -155
  47. data/lib/chef/knife/data_bag_create.rb +2 -1
  48. data/lib/chef/knife/data_bag_delete.rb +2 -1
  49. data/lib/chef/knife/data_bag_edit.rb +2 -1
  50. data/lib/chef/knife/data_bag_from_file.rb +2 -1
  51. data/lib/chef/knife/data_bag_list.rb +2 -1
  52. data/lib/chef/knife/data_bag_show.rb +2 -1
  53. data/lib/chef/knife/ec2_instance_data.rb +1 -1
  54. data/lib/chef/knife/ec2_server_create.rb +16 -4
  55. data/lib/chef/knife/ec2_server_delete.rb +8 -2
  56. data/lib/chef/knife/ec2_server_list.rb +8 -2
  57. data/lib/chef/knife/index_rebuild.rb +1 -1
  58. data/lib/chef/knife/node_bulk_delete.rb +1 -1
  59. data/lib/chef/knife/node_create.rb +1 -1
  60. data/lib/chef/knife/node_delete.rb +1 -1
  61. data/lib/chef/knife/node_edit.rb +1 -1
  62. data/lib/chef/knife/node_from_file.rb +1 -1
  63. data/lib/chef/knife/node_list.rb +1 -1
  64. data/lib/chef/knife/node_run_list_add.rb +1 -1
  65. data/lib/chef/knife/node_run_list_remove.rb +1 -1
  66. data/lib/chef/knife/node_show.rb +1 -1
  67. data/lib/chef/knife/rackspace_server_create.rb +1 -1
  68. data/lib/chef/knife/rackspace_server_delete.rb +1 -1
  69. data/lib/chef/knife/rackspace_server_list.rb +1 -1
  70. data/lib/chef/knife/recipe_list.rb +1 -1
  71. data/lib/chef/knife/role_bulk_delete.rb +1 -1
  72. data/lib/chef/knife/role_create.rb +1 -1
  73. data/lib/chef/knife/role_delete.rb +1 -1
  74. data/lib/chef/knife/role_edit.rb +1 -1
  75. data/lib/chef/knife/role_from_file.rb +1 -1
  76. data/lib/chef/knife/role_list.rb +1 -1
  77. data/lib/chef/knife/role_show.rb +1 -1
  78. data/lib/chef/knife/search.rb +1 -1
  79. data/lib/chef/knife/slicehost_images_list.rb +1 -1
  80. data/lib/chef/knife/slicehost_server_create.rb +1 -1
  81. data/lib/chef/knife/slicehost_server_delete.rb +1 -1
  82. data/lib/chef/knife/slicehost_server_list.rb +1 -1
  83. data/lib/chef/knife/ssh.rb +49 -9
  84. data/lib/chef/knife/status.rb +2 -2
  85. data/lib/chef/knife/terremark_server_create.rb +1 -1
  86. data/lib/chef/knife/terremark_server_delete.rb +1 -1
  87. data/lib/chef/knife/terremark_server_list.rb +1 -1
  88. data/lib/chef/mixin/command.rb +17 -204
  89. data/lib/chef/mixin/command/unix.rb +215 -0
  90. data/lib/chef/mixin/command/windows.rb +72 -0
  91. data/lib/chef/mixin/find_preferred_file.rb +3 -3
  92. data/lib/chef/mixin/language.rb +64 -23
  93. data/lib/chef/node.rb +27 -3
  94. data/lib/chef/node/attribute.rb +20 -10
  95. data/lib/chef/platform.rb +3 -9
  96. data/lib/chef/provider/cron.rb +1 -1
  97. data/lib/chef/provider/deploy.rb +4 -1
  98. data/lib/chef/provider/group.rb +1 -1
  99. data/lib/chef/provider/group/dscl.rb +2 -2
  100. data/lib/chef/provider/mount/mount.rb +6 -6
  101. data/lib/chef/provider/package/easy_install.rb +8 -7
  102. data/lib/chef/provider/package/pacman.rb +1 -1
  103. data/lib/chef/provider/package/rpm.rb +4 -4
  104. data/lib/chef/provider/package/solaris.rb +127 -0
  105. data/lib/chef/provider/package/yum.rb +51 -28
  106. data/lib/chef/provider/remote_directory.rb +5 -2
  107. data/lib/chef/provider/remote_file.rb +1 -1
  108. data/lib/chef/provider/ruby_block.rb +1 -0
  109. data/lib/chef/provider/script.rb +2 -2
  110. data/lib/chef/provider/service/debian.rb +40 -4
  111. data/lib/chef/provider/service/freebsd.rb +1 -1
  112. data/lib/chef/provider/service/upstart.rb +3 -10
  113. data/lib/chef/provider/user/dscl.rb +2 -2
  114. data/lib/chef/providers.rb +1 -0
  115. data/lib/chef/resource.rb +7 -8
  116. data/lib/chef/resource/service.rb +17 -0
  117. data/lib/chef/resource/solaris_package.rb +36 -0
  118. data/lib/chef/resource/yum_package.rb +11 -4
  119. data/lib/chef/rest/rest_request.rb +18 -1
  120. data/lib/chef/run_list/run_list_expansion.rb +4 -0
  121. data/lib/chef/run_list/run_list_item.rb +8 -1
  122. data/lib/chef/shef/ext.rb +1 -1
  123. data/lib/chef/shef/shef_session.rb +7 -3
  124. data/lib/chef/tasks/chef_repo.rake +1 -0
  125. data/lib/chef/version.rb +2 -1
  126. metadata +23 -8
  127. data/lib/chef/cache/file_cache_by_checksum.rb +0 -52
@@ -0,0 +1,72 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008 Opscode, Inc.
4
+ # Author:: Doug MacEachern (<dougm@vmware.com>)
5
+ # Copyright:: Copyright (c) 2010 VMware, Inc.
6
+ # License:: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+
21
+ require 'win32/open3'
22
+
23
+ class Chef
24
+ module Mixin
25
+ module Command
26
+ module Windows
27
+ def popen4(cmd, args={}, &b)
28
+
29
+ # By default, we are waiting before we yield the block.
30
+ args[:waitlast] ||= false
31
+
32
+ #XXX :user, :group, :environment support?
33
+
34
+ Open4.popen4(cmd) do |stdin,stdout,stderr,cid|
35
+ if b
36
+ if args[:waitlast]
37
+ b[cid, stdin, stdout, stderr]
38
+ # send EOF so that if the child process is reading from STDIN
39
+ # it will actually finish up and exit
40
+ stdin.close_write
41
+ else
42
+ o = StringIO.new
43
+ e = StringIO.new
44
+
45
+ stdin.close
46
+
47
+ stdout.sync = true
48
+ stderr.sync = true
49
+
50
+ line = stdout.gets(nil)
51
+ if line
52
+ o.write(line)
53
+ end
54
+ line = stderr.gets(nil)
55
+ if line
56
+ e.write(line)
57
+ end
58
+ o.rewind
59
+ e.rewind
60
+ b[cid, stdin, o, e]
61
+ end
62
+ else
63
+ [cid, stdin, stdout, stderr]
64
+ end
65
+ end
66
+ $?
67
+ end
68
+
69
+ end
70
+ end
71
+ end
72
+ end
@@ -47,9 +47,9 @@ class Chef
47
47
  name = File.basename(full)
48
48
  case file_type
49
49
  when :remote_file
50
- rf =~ /^.+#{cookbook_id}[\\|\/]files[\\|\/](.+?)[\\|\/]#{name}/
50
+ rf =~ /^.+#{Regexp.escape(cookbook_id)}[\\|\/]files[\\|\/](.+?)[\\|\/]#{Regexp.escape(name)}/
51
51
  when :template
52
- rf =~ /^.+#{cookbook_id}[\\|\/]templates[\\|\/](.+?)[\\|\/]#{name}/
52
+ rf =~ /^.+#{Regexp.escape(cookbook_id)}[\\|\/]templates[\\|\/](.+?)[\\|\/]#{Regexp.escape(name)}/
53
53
  end
54
54
  singlecopy = $1
55
55
  files[full] = {
@@ -78,7 +78,7 @@ class Chef
78
78
 
79
79
  preferences.each do |pref|
80
80
  Chef::Log.debug("Looking for #{pref}")
81
- matcher = /^(.+#{pref})$/
81
+ matcher = /^(.+#{Regexp.escape(pref)})$/
82
82
  if match = matcher.match(file_list_str)
83
83
  return match[1]
84
84
  end
@@ -24,6 +24,69 @@ class Chef
24
24
  module Mixin
25
25
  module Language
26
26
 
27
+ # Implementation class for determining platform dependent values
28
+ class PlatformDependentValue
29
+
30
+ # Create a platform dependent value object.
31
+ # === Arguments
32
+ # platform_hash (Hash) a hash of the same structure as Chef::Platform,
33
+ # like this:
34
+ # {
35
+ # :debian => {:default => 'the value for all debian'}
36
+ # [:centos, :redhat, :fedora] => {:default => "value for all EL variants"}
37
+ # :ubuntu => { :default => "default for ubuntu", '10.04' => "value for 10.04 only"},
38
+ # :default => "the default when nothing else matches"
39
+ # }
40
+ # * platforms can be specified as Symbols or Strings
41
+ # * multiple platforms can be grouped by using an Array as the key
42
+ # * values for platforms need to be Hashes of the form:
43
+ # {platform_version => value_for_that_version}
44
+ # * the exception to the above is the default value, which is given as
45
+ # :default => default_value
46
+ def initialize(platform_hash)
47
+ @values = {}
48
+ platform_hash.each { |platforms, value| set(platforms, value)}
49
+ end
50
+
51
+ def value_for_node(node)
52
+ platform, version = node[:platform].to_s, node[:platform_version].to_s
53
+ if @values.key?(platform) && @values[platform].key?(version)
54
+ @values[platform][version]
55
+ elsif @values.key?(platform) && @values[platform].key?("default")
56
+ @values[platform]["default"]
57
+ elsif @values.key?("default")
58
+ @values["default"]
59
+ else
60
+ nil
61
+ end
62
+ end
63
+
64
+ private
65
+
66
+ def set(platforms, value)
67
+ if platforms.to_s == 'default'
68
+ @values["default"] = value
69
+ else
70
+ assert_valid_platform_values!(platforms, value)
71
+ Array(platforms).each { |platform| @values[platform.to_s] = format_values(value)}
72
+ value
73
+ end
74
+ end
75
+
76
+ def format_values(hash)
77
+ formatted_array = hash.map { |key, value| [key.to_s, value]}.flatten
78
+ Hash[*formatted_array]
79
+ end
80
+
81
+ def assert_valid_platform_values!(platforms, value)
82
+ unless value.kind_of?(Hash)
83
+ msg = "platform dependent values must be specified in the format :platform => {:version => value} "
84
+ msg << "you gave a value #{value.inspect} for platform(s) #{platforms}"
85
+ raise ArgumentError, msg
86
+ end
87
+ end
88
+ end
89
+
27
90
  # Given a hash similar to the one we use for Platforms, select a value from the hash. Supports
28
91
  # per platform defaults, along with a single base default. Arrays may be passed as hash keys and
29
92
  # will be expanded.
@@ -34,29 +97,7 @@ class Chef
34
97
  # === Returns
35
98
  # value:: Whatever the most specific value of the hash is.
36
99
  def value_for_platform(platform_hash)
37
- result = nil
38
-
39
- platform_hash.each_pair do |key, value|
40
- if key.is_a?(Array)
41
- key.each { |array_key| platform_hash[array_key] = value }
42
- platform_hash.delete(key)
43
- end
44
- end
45
- if platform_hash.has_key?(node[:platform])
46
- if platform_hash[node[:platform]].has_key?(node[:platform_version])
47
- result = platform_hash[node[:platform]][node[:platform_version]]
48
- elsif platform_hash[node[:platform]].has_key?("default")
49
- result = platform_hash[node[:platform]]["default"]
50
- end
51
- end
52
-
53
- unless result
54
- if platform_hash.has_key?("default")
55
- result = platform_hash["default"]
56
- end
57
- end
58
-
59
- result
100
+ PlatformDependentValue.new(platform_hash).value_for_node(node)
60
101
  end
61
102
 
62
103
  # Given a list of platforms, returns true if the current recipe is being run on a node with
@@ -460,6 +460,20 @@ class Chef
460
460
  end
461
461
  end
462
462
 
463
+ def self.find_or_create(node_name)
464
+ load(node_name)
465
+ rescue Net::HTTPServerException => e
466
+ raise unless e.response.code == '404'
467
+ node = build(node_name)
468
+ node.create
469
+ end
470
+
471
+ def self.build(node_name)
472
+ node = new
473
+ node.name(node_name)
474
+ node
475
+ end
476
+
463
477
  # Load a node by name
464
478
  def self.load(name)
465
479
  Chef::REST.new(Chef::Config[:chef_server_url]).get_rest("nodes/#{name}")
@@ -536,7 +550,11 @@ class Chef
536
550
  self
537
551
  end
538
552
 
539
- def prepare_for_run(ohai_data, json_cli_attrs)
553
+ # Consume data from ohai and Attributes provided as JSON on the command line.
554
+ # The run_list from the command-line attributes will be applied immediately,
555
+ # other attributes from the command line will be saved for later. Ohai data
556
+ # is applied immediately
557
+ def process_external_attrs(ohai_data, json_cli_attrs)
540
558
  Chef::Log.debug("Extracting run list from JSON attributes provided on command line")
541
559
  @json_attrib_for_expansion = consume_run_list(json_cli_attrs)
542
560
 
@@ -546,8 +564,11 @@ class Chef
546
564
  Chef::Log.debug("Platform is #{platform} version #{version}")
547
565
  @automatic_attrs[:platform] = platform
548
566
  @automatic_attrs[:platform_version] = version
549
- # We clear defaults and overrides, so that any deleted attributes between runs are
550
- # still gone.
567
+ end
568
+
569
+ # Clear defaults and overrides, so that any deleted attributes between runs are
570
+ # still gone.
571
+ def reset_defaults_and_overrides
551
572
  @default_attrs = Mash.new
552
573
  @override_attrs = Mash.new
553
574
  end
@@ -574,6 +595,9 @@ class Chef
574
595
  @default_attrs = Chef::Mixin::DeepMerge.merge(default_attrs, expansion.default_attrs)
575
596
  @override_attrs = Chef::Mixin::DeepMerge.merge(override_attrs, expansion.override_attrs)
576
597
 
598
+ @automatic_attrs[:recipes] = expansion.recipes
599
+ @automatic_attrs[:roles] = expansion.roles
600
+
577
601
  expansion.recipes
578
602
  end
579
603
 
@@ -7,9 +7,9 @@
7
7
  # Licensed under the Apache License, Version 2.0 (the "License");
8
8
  # you may not use this file except in compliance with the License.
9
9
  # You may obtain a copy of the License at
10
- #
10
+ #
11
11
  # http://www.apache.org/licenses/LICENSE-2.0
12
- #
12
+ #
13
13
  # Unless required by applicable law or agreed to in writing, software
14
14
  # distributed under the License is distributed on an "AS IS" BASIS,
15
15
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -23,6 +23,8 @@ require 'chef/log'
23
23
  class Chef
24
24
  class Node
25
25
  class Attribute
26
+ HIDDEN_ATTRIBUES = [:@override, :@attribute, :@default, :@normal, :@automatic]
27
+
26
28
  attr_accessor :normal,
27
29
  :default,
28
30
  :override,
@@ -46,8 +48,8 @@ class Chef
46
48
  @current_default = default
47
49
  @override = override
48
50
  @current_override = override
49
- @automatic = automatic
50
- @current_automatic = automatic
51
+ @automatic = automatic
52
+ @current_automatic = automatic
51
53
  @state = state
52
54
  @auto_vivifiy_on_read = false
53
55
  @set_unless_value_present = false
@@ -93,7 +95,7 @@ class Chef
93
95
  # See the comments in []= for more details.
94
96
  @has_been_read = true
95
97
 
96
- # If we have a set type, our destiny is to write
98
+ # If we have a set type, our destiny is to write
97
99
  if @set_type
98
100
  a_value = @set_type == :automatic ? value_or_descend(current_automatic, key, auto_vivifiy_on_read) : nil
99
101
  o_value = @set_type == :override ? value_or_descend(current_override, key, auto_vivifiy_on_read) : nil
@@ -101,7 +103,7 @@ class Chef
101
103
  d_value = @set_type == :default ? value_or_descend(current_default, key, auto_vivifiy_on_read) : nil
102
104
 
103
105
  determine_value(a_value, o_value, n_value, d_value)
104
- # Our destiny is only to read, so we get the full list.
106
+ # Our destiny is only to read, so we get the full list.
105
107
  else
106
108
  a_value = value_or_descend(current_automatic, key)
107
109
  o_value = value_or_descend(current_override, key)
@@ -249,7 +251,7 @@ class Chef
249
251
  def keys
250
252
  tkeys = current_automatic ? current_automatic.keys : []
251
253
  [ current_override, current_normal, current_default ].each do |attr_hash|
252
- if attr_hash
254
+ if attr_hash
253
255
  attr_hash.keys.each do |key|
254
256
  tkeys << key unless tkeys.include?(key)
255
257
  end
@@ -295,18 +297,18 @@ class Chef
295
297
  value = Chef::Mixin::DeepMerge.merge(value, d_value) if hash_and_not_cna?(d_value)
296
298
  value = Chef::Mixin::DeepMerge.merge(value, n_value) if hash_and_not_cna?(n_value)
297
299
  value = Chef::Mixin::DeepMerge.merge(value, o_value) if hash_and_not_cna?(o_value)
298
- value = Chef::Mixin::DeepMerge.merge(value, a_value)
300
+ value = Chef::Mixin::DeepMerge.merge(value, a_value)
299
301
  value
300
302
  elsif hash_and_not_cna?(o_value)
301
303
  value = {}
302
304
  value = Chef::Mixin::DeepMerge.merge(value, d_value) if hash_and_not_cna?(d_value)
303
305
  value = Chef::Mixin::DeepMerge.merge(value, n_value) if hash_and_not_cna?(n_value)
304
- value = Chef::Mixin::DeepMerge.merge(value, o_value)
306
+ value = Chef::Mixin::DeepMerge.merge(value, o_value)
305
307
  value
306
308
  elsif hash_and_not_cna?(n_value)
307
309
  value = {}
308
310
  value = Chef::Mixin::DeepMerge.merge(value, d_value) if hash_and_not_cna?(d_value)
309
- value = Chef::Mixin::DeepMerge.merge(value, n_value)
311
+ value = Chef::Mixin::DeepMerge.merge(value, n_value)
310
312
  value
311
313
  elsif hash_and_not_cna?(d_value)
312
314
  d_value
@@ -426,6 +428,14 @@ class Chef
426
428
  end
427
429
  end
428
430
 
431
+ def inspect
432
+ determine_value(current_automatic, current_override, current_normal, current_default)
433
+
434
+ "#<#{self.class} " << instance_variables.map{|iv|
435
+ iv.to_s + '=' + (HIDDEN_ATTRIBUES.include?(iv.to_sym) ? "{...}" : instance_variable_get(iv).inspect)
436
+ }.join(', ') << ">"
437
+ end
438
+
429
439
  def to_hash
430
440
  result = determine_value(current_automatic, current_override, current_normal, current_default)
431
441
  if result.class == Hash
@@ -80,14 +80,6 @@ class Chef
80
80
  :mdadm => Chef::Provider::Mdadm
81
81
  }
82
82
  },
83
- :scientific => {
84
- :default => {
85
- :service => Chef::Provider::Service::Redhat,
86
- :cron => Chef::Provider::Cron,
87
- :package => Chef::Provider::Package::Yum,
88
- :mdadm => Chef::Provider::Mdadm
89
- }
90
- },
91
83
  :fedora => {
92
84
  :default => {
93
85
  :service => Chef::Provider::Service::Redhat,
@@ -157,7 +149,9 @@ class Chef
157
149
  :solaris => {},
158
150
  :solaris2 => {
159
151
  :default => {
160
- :service => Chef::Provider::Service::Solaris
152
+ :service => Chef::Provider::Service::Solaris,
153
+ :package => Chef::Provider::Package::Solaris,
154
+ :cron => Chef::Provider::Cron
161
155
  }
162
156
  },
163
157
  :default => {
@@ -25,7 +25,7 @@ class Chef
25
25
  class Cron < Chef::Provider
26
26
  include Chef::Mixin::Command
27
27
 
28
- CRON_PATTERN = /([0-9\*\-\,\/]+)\s*([0-9\*\-\,\/]+)\s*([0-9\*\-\,\/]+)\s*([0-9\*\-\,\/]+)\s*([0-9\*\-\,\/]+)\s*(.*)/
28
+ CRON_PATTERN = /([-0-9*,\/]+)\s([-0-9*,\/]+)\s([-0-9*,\/]+)\s([-0-9*,\/]+)\s([-0-9*,\/]+)\s(.*)/
29
29
 
30
30
  def initialize(new_resource, run_context)
31
31
  super(new_resource, run_context)
@@ -51,7 +51,10 @@ class Chef
51
51
 
52
52
  def run(command, &block)
53
53
  exec = execute(command, &block)
54
- exec.user(@new_resource.user)
54
+ exec.user(@new_resource.user) if @new_resource.user
55
+ exec.group(@new_resource.group) if @new_resource.group
56
+ exec.cwd(release_path) unless exec.cwd
57
+ exec.environment(@new_resource.environment) unless exec.environment
55
58
  exec
56
59
  end
57
60
 
@@ -45,7 +45,7 @@ class Chef
45
45
  end
46
46
 
47
47
  if group_info
48
- @new_resource.gid(group_info.gid)
48
+ @new_resource.gid(group_info.gid) unless @new_resource.gid
49
49
  @current_resource.gid(group_info.gid)
50
50
  @current_resource.members(group_info.mem)
51
51
  end
@@ -50,7 +50,7 @@ class Chef
50
50
  gid = nil; next_gid_guess = 200
51
51
  groups_gids = safe_dscl("list /Groups gid")
52
52
  while(next_gid_guess < search_limit + 200)
53
- if groups_gids =~ Regexp.new("#{next_gid_guess}\n")
53
+ if groups_gids =~ Regexp.new("#{Regexp.escape(next_gid_guess.to_s)}\n")
54
54
  next_gid_guess += 1
55
55
  else
56
56
  gid = next_gid_guess
@@ -63,7 +63,7 @@ class Chef
63
63
  def gid_used?(gid)
64
64
  return false unless gid
65
65
  groups_gids = safe_dscl("list /Groups gid")
66
- !! ( groups_gids =~ Regexp.new("#{gid}\n") )
66
+ !! ( groups_gids =~ Regexp.new("#{Regexp.escape(gid.to_s)}\n") )
67
67
  end
68
68
 
69
69
  def set_gid
@@ -49,10 +49,10 @@ class Chef
49
49
  mounted = false
50
50
  shell_out!("mount").stdout.each_line do |line|
51
51
  case line
52
- when /^#{device_mount_regex}\s+on\s+#{@new_resource.mount_point}/
52
+ when /^#{device_mount_regex}\s+on\s+#{Regexp.escape(@new_resource.mount_point)}/
53
53
  mounted = true
54
54
  Chef::Log.debug("Special device #{device_logstring} mounted as #{@new_resource.mount_point}")
55
- when /^([\/\w])+\son\s#{@new_resource.mount_point}\s+/
55
+ when /^([\/\w])+\son\s#{Regexp.escape(@new_resource.mount_point)}\s+/
56
56
  mounted = false
57
57
  Chef::Log.debug("Special device #{$~[1]} mounted as #{@new_resource.mount_point}")
58
58
  end
@@ -65,14 +65,14 @@ class Chef
65
65
  case line
66
66
  when /^[#\s]/
67
67
  next
68
- when /^#{device_fstab_regex}\s+#{@new_resource.mount_point}\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/
68
+ when /^#{device_fstab_regex}\s+#{Regexp.escape(@new_resource.mount_point)}\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/
69
69
  enabled = true
70
70
  @current_resource.fstype($1)
71
71
  @current_resource.options($2)
72
72
  @current_resource.dump($3.to_i)
73
73
  @current_resource.pass($4.to_i)
74
74
  Chef::Log.debug("Found mount #{device_fstab} to #{@new_resource.mount_point} in /etc/fstab")
75
- when /^[\/\w]+\s+#{@new_resource.mount_point}/
75
+ when /^[\/\w]+\s+#{Regexp.escape(@new_resource.mount_point)}/
76
76
  enabled = false
77
77
  Chef::Log.debug("Found conflicting mount point #{@new_resource.mount_point} in /etc/fstab")
78
78
  end
@@ -147,7 +147,7 @@ class Chef
147
147
 
148
148
  found = false
149
149
  ::File.readlines("/etc/fstab").reverse_each do |line|
150
- if !found && line =~ /^#{device_fstab_regex}\s+#{@new_resource.mount_point}/
150
+ if !found && line =~ /^#{device_fstab_regex}\s+#{Regexp.escape(@new_resource.mount_point)}/
151
151
  found = true
152
152
  Chef::Log.debug("Removing #{@new_resource.mount_point} from fstab")
153
153
  next
@@ -203,7 +203,7 @@ class Chef
203
203
  end
204
204
 
205
205
  def device_mount_regex
206
- ::File.symlink?(device_real) ? "(?:#{device_real})|(?:#{::File.readlink(device_real)})" : device_real
206
+ ::File.symlink?(device_real) ? "(?:#{Regexp.escape(device_real)})|(?:#{Regexp.escape(::File.readlink(device_real))})" : Regexp.escape(device_real)
207
207
  end
208
208
 
209
209
  def device_fstab_regex