madscience 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.madscience_gem_location +0 -0
  4. data/Cheffile +9 -0
  5. data/Cheffile.lock +34 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +9 -0
  8. data/README.md +126 -0
  9. data/Rakefile +1 -0
  10. data/TODO +17 -0
  11. data/bin/madscience +90 -0
  12. data/cookbooks/apt/CHANGELOG.md +183 -0
  13. data/cookbooks/apt/README.md +255 -0
  14. data/cookbooks/apt/attributes/default.rb +29 -0
  15. data/cookbooks/apt/files/default/apt-proxy-v2.conf +50 -0
  16. data/cookbooks/apt/libraries/helpers.rb +49 -0
  17. data/cookbooks/apt/libraries/matchers.rb +17 -0
  18. data/cookbooks/apt/libraries/network.rb +31 -0
  19. data/cookbooks/apt/metadata.json +54 -0
  20. data/cookbooks/apt/metadata.rb +34 -0
  21. data/cookbooks/apt/providers/preference.rb +63 -0
  22. data/cookbooks/apt/providers/repository.rb +150 -0
  23. data/cookbooks/apt/recipes/cacher-client.rb +81 -0
  24. data/cookbooks/apt/recipes/cacher-ng.rb +43 -0
  25. data/cookbooks/apt/recipes/default.rb +91 -0
  26. data/cookbooks/apt/resources/preference.rb +32 -0
  27. data/cookbooks/apt/resources/repository.rb +43 -0
  28. data/cookbooks/apt/templates/debian-6.0/acng.conf.erb +173 -0
  29. data/cookbooks/apt/templates/default/01proxy.erb +5 -0
  30. data/cookbooks/apt/templates/default/acng.conf.erb +275 -0
  31. data/cookbooks/apt/templates/ubuntu-10.04/acng.conf.erb +269 -0
  32. data/cookbooks/chef_handler/CHANGELOG.md +44 -0
  33. data/cookbooks/chef_handler/README.md +103 -0
  34. data/cookbooks/chef_handler/attributes/default.rb +30 -0
  35. data/cookbooks/chef_handler/files/default/handlers/README +1 -0
  36. data/cookbooks/chef_handler/libraries/matchers.rb +29 -0
  37. data/cookbooks/chef_handler/metadata.json +29 -0
  38. data/cookbooks/chef_handler/metadata.rb +7 -0
  39. data/cookbooks/chef_handler/providers/default.rb +97 -0
  40. data/cookbooks/chef_handler/recipes/default.rb +33 -0
  41. data/cookbooks/chef_handler/recipes/json_file.rb +28 -0
  42. data/cookbooks/chef_handler/resources/default.rb +34 -0
  43. data/cookbooks/dmg/CHANGELOG.md +75 -0
  44. data/cookbooks/dmg/README.md +143 -0
  45. data/cookbooks/dmg/attributes/default.rb +20 -0
  46. data/cookbooks/dmg/metadata.json +30 -0
  47. data/cookbooks/dmg/metadata.rb +9 -0
  48. data/cookbooks/dmg/providers/package.rb +91 -0
  49. data/cookbooks/dmg/recipes/default.rb +18 -0
  50. data/cookbooks/dmg/resources/package.rb +37 -0
  51. data/cookbooks/vagrant/Berksfile +2 -0
  52. data/cookbooks/vagrant/CHANGELOG.md +7 -0
  53. data/cookbooks/vagrant/README.md +146 -0
  54. data/cookbooks/vagrant/TESTING.md +25 -0
  55. data/cookbooks/vagrant/attributes/default.rb +22 -0
  56. data/cookbooks/vagrant/metadata.rb +14 -0
  57. data/cookbooks/vagrant/providers/plugin.rb +50 -0
  58. data/cookbooks/vagrant/recipes/debian.rb +9 -0
  59. data/cookbooks/vagrant/recipes/default.rb +34 -0
  60. data/cookbooks/vagrant/recipes/fedora.rb +1 -0
  61. data/cookbooks/vagrant/recipes/mac_os_x.rb +7 -0
  62. data/cookbooks/vagrant/recipes/rhel.rb +9 -0
  63. data/cookbooks/vagrant/recipes/uninstall_gem.rb +7 -0
  64. data/cookbooks/vagrant/recipes/windows.rb +5 -0
  65. data/cookbooks/vagrant/resources/plugin.rb +8 -0
  66. data/cookbooks/virtualbox/README.md +167 -0
  67. data/cookbooks/virtualbox/attributes/default.rb +32 -0
  68. data/cookbooks/virtualbox/attributes/user.rb +22 -0
  69. data/cookbooks/virtualbox/attributes/webportal.rb +22 -0
  70. data/cookbooks/virtualbox/attributes/webservice.rb +24 -0
  71. data/cookbooks/virtualbox/files/ubuntu/machines_enabled +1 -0
  72. data/cookbooks/virtualbox/files/ubuntu/vboxcontrol +104 -0
  73. data/cookbooks/virtualbox/libraries/helpers.rb +30 -0
  74. data/cookbooks/virtualbox/metadata.rb +16 -0
  75. data/cookbooks/virtualbox/recipes/default.rb +70 -0
  76. data/cookbooks/virtualbox/recipes/systemservice.rb +56 -0
  77. data/cookbooks/virtualbox/recipes/user.rb +39 -0
  78. data/cookbooks/virtualbox/recipes/webportal.rb +58 -0
  79. data/cookbooks/virtualbox/recipes/webservice.rb +44 -0
  80. data/cookbooks/virtualbox/templates/ubuntu/config.erb +3 -0
  81. data/cookbooks/virtualbox/templates/ubuntu/config.php.erb +183 -0
  82. data/cookbooks/virtualbox/templates/ubuntu/vbox.cfg.erb +51 -0
  83. data/cookbooks/windows/CHANGELOG.md +268 -0
  84. data/cookbooks/windows/README.md +665 -0
  85. data/cookbooks/windows/attributes/default.rb +23 -0
  86. data/cookbooks/windows/files/default/handlers/windows_reboot_handler.rb +76 -0
  87. data/cookbooks/windows/libraries/feature_base.rb +59 -0
  88. data/cookbooks/windows/libraries/matchers.rb +450 -0
  89. data/cookbooks/windows/libraries/powershell_helper.rb +59 -0
  90. data/cookbooks/windows/libraries/powershell_out.rb +79 -0
  91. data/cookbooks/windows/libraries/registry_helper.rb +357 -0
  92. data/cookbooks/windows/libraries/version.rb +206 -0
  93. data/cookbooks/windows/libraries/windows_architecture_helper.rb +86 -0
  94. data/cookbooks/windows/libraries/windows_helper.rb +88 -0
  95. data/cookbooks/windows/libraries/windows_privileged.rb +94 -0
  96. data/cookbooks/windows/metadata.json +31 -0
  97. data/cookbooks/windows/metadata.rb +9 -0
  98. data/cookbooks/windows/providers/auto_run.rb +32 -0
  99. data/cookbooks/windows/providers/batch.rb +62 -0
  100. data/cookbooks/windows/providers/feature_dism.rb +64 -0
  101. data/cookbooks/windows/providers/feature_powershell.rb +38 -0
  102. data/cookbooks/windows/providers/feature_servermanagercmd.rb +47 -0
  103. data/cookbooks/windows/providers/package.rb +252 -0
  104. data/cookbooks/windows/providers/pagefile.rb +153 -0
  105. data/cookbooks/windows/providers/path.rb +35 -0
  106. data/cookbooks/windows/providers/printer.rb +100 -0
  107. data/cookbooks/windows/providers/printer_port.rb +102 -0
  108. data/cookbooks/windows/providers/reboot.rb +31 -0
  109. data/cookbooks/windows/providers/registry.rb +72 -0
  110. data/cookbooks/windows/providers/shortcut.rb +56 -0
  111. data/cookbooks/windows/providers/task.rb +128 -0
  112. data/cookbooks/windows/providers/zipfile.rb +91 -0
  113. data/cookbooks/windows/recipes/default.rb +34 -0
  114. data/cookbooks/windows/recipes/reboot_handler.rb +32 -0
  115. data/cookbooks/windows/resources/auto_run.rb +30 -0
  116. data/cookbooks/windows/resources/batch.rb +36 -0
  117. data/cookbooks/windows/resources/feature.rb +44 -0
  118. data/cookbooks/windows/resources/package.rb +46 -0
  119. data/cookbooks/windows/resources/pagefile.rb +29 -0
  120. data/cookbooks/windows/resources/path.rb +28 -0
  121. data/cookbooks/windows/resources/printer.rb +41 -0
  122. data/cookbooks/windows/resources/printer_port.rb +40 -0
  123. data/cookbooks/windows/resources/reboot.rb +29 -0
  124. data/cookbooks/windows/resources/registry.rb +34 -0
  125. data/cookbooks/windows/resources/shortcut.rb +35 -0
  126. data/cookbooks/windows/resources/task.rb +50 -0
  127. data/cookbooks/windows/resources/zipfile.rb +33 -0
  128. data/cookbooks/yum/CHANGELOG.md +212 -0
  129. data/cookbooks/yum/README.md +268 -0
  130. data/cookbooks/yum/attributes/main.rb +97 -0
  131. data/cookbooks/yum/libraries/matchers.rb +27 -0
  132. data/cookbooks/yum/metadata.json +34 -0
  133. data/cookbooks/yum/metadata.rb +13 -0
  134. data/cookbooks/yum/providers/globalconfig.rb +37 -0
  135. data/cookbooks/yum/providers/repository.rb +85 -0
  136. data/cookbooks/yum/recipes/default.rb +34 -0
  137. data/cookbooks/yum/resources/globalconfig.rb +105 -0
  138. data/cookbooks/yum/resources/repository.rb +63 -0
  139. data/cookbooks/yum/templates/default/main.erb +251 -0
  140. data/cookbooks/yum/templates/default/repo.erb +109 -0
  141. data/lib/madscience/version.rb +3 -0
  142. data/lib/madscience.rb +5 -0
  143. data/madscience.gemspec +44 -0
  144. data/new_gem_version.rb +6 -0
  145. data/node-data.json +3 -0
  146. data/site-cookbooks/madscience-vagrant-cookbook/CHANGELOG.md +13 -0
  147. data/site-cookbooks/madscience-vagrant-cookbook/README.md +53 -0
  148. data/site-cookbooks/madscience-vagrant-cookbook/metadata.rb +17 -0
  149. data/site-cookbooks/madscience-vagrant-cookbook/recipes/default.rb +87 -0
  150. data/solo.rb +6 -0
  151. metadata +337 -0
@@ -0,0 +1,252 @@
1
+ #
2
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ # Cookbook Name:: windows
4
+ # Provider:: package
5
+ #
6
+ # Copyright:: 2011, Opscode, Inc.
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
+ if RUBY_PLATFORM =~ /mswin|mingw32|windows/
22
+ require 'win32/registry'
23
+ end
24
+
25
+ require 'chef/mixin/shell_out'
26
+ require 'chef/mixin/language'
27
+
28
+ include Chef::Mixin::ShellOut
29
+ include Windows::Helper
30
+
31
+ # the logic in all action methods mirror that of
32
+ # the Chef::Provider::Package which will make
33
+ # refactoring into core chef easy
34
+
35
+ action :install do
36
+ # If we specified a version, and it's not the current version, move to the specified version
37
+ if @new_resource.version != nil && @new_resource.version != @current_resource.version
38
+ install_version = @new_resource.version
39
+ # If it's not installed at all, install it
40
+ elsif @current_resource.version == nil
41
+ install_version = candidate_version
42
+ end
43
+
44
+ if install_version
45
+ Chef::Log.info("Installing #{@new_resource} version #{install_version}")
46
+ status = install_package(@new_resource.package_name, install_version)
47
+ if status
48
+ @new_resource.updated_by_last_action(true)
49
+ end
50
+ end
51
+ end
52
+
53
+ action :upgrade do
54
+ if @current_resource.version != candidate_version
55
+ orig_version = @current_resource.version || "uninstalled"
56
+ Chef::Log.info("Upgrading #{@new_resource} version from #{orig_version} to #{candidate_version}")
57
+ status = upgrade_package(@new_resource.package_name, candidate_version)
58
+ if status
59
+ @new_resource.updated_by_last_action(true)
60
+ end
61
+ end
62
+ end
63
+
64
+ action :remove do
65
+ if removing_package?
66
+ Chef::Log.info("Removing #{@new_resource}")
67
+ remove_package(@current_resource.package_name, @new_resource.version)
68
+ @new_resource.updated_by_last_action(true)
69
+ else
70
+ end
71
+ end
72
+
73
+ def removing_package?
74
+ if @current_resource.version.nil?
75
+ false # nothing to remove
76
+ elsif @new_resource.version.nil?
77
+ true # remove any version of a package
78
+ elsif @new_resource.version == @current_resource.version
79
+ true # remove the version we have
80
+ else
81
+ false # we don't have the version we want to remove
82
+ end
83
+ end
84
+
85
+ def expand_options(options)
86
+ options ? " #{options}" : ""
87
+ end
88
+
89
+ # these methods are the required overrides of
90
+ # a provider that extends from Chef::Provider::Package
91
+ # so refactoring into core Chef should be easy
92
+
93
+ def load_current_resource
94
+ @current_resource = Chef::Resource::WindowsPackage.new(@new_resource.name)
95
+ @current_resource.package_name(@new_resource.package_name)
96
+ @current_resource.version(nil)
97
+
98
+ unless current_installed_version.nil?
99
+ @current_resource.version(current_installed_version)
100
+ end
101
+
102
+ @current_resource
103
+ end
104
+
105
+ def current_installed_version
106
+ @current_installed_version ||= begin
107
+ if installed_packages.include?(@new_resource.package_name)
108
+ installed_packages[@new_resource.package_name][:version]
109
+ end
110
+ end
111
+ end
112
+
113
+ def candidate_version
114
+ @candidate_version ||= begin
115
+ @new_resource.version || 'latest'
116
+ end
117
+ end
118
+
119
+ def install_package(name,version)
120
+ Chef::Log.debug("Processing #{@new_resource} as a #{installer_type} installer.")
121
+ install_args = [cached_file(@new_resource.source, @new_resource.checksum), expand_options(unattended_installation_flags), expand_options(@new_resource.options)]
122
+ Chef::Log.info("Starting installation...this could take awhile.")
123
+ Chef::Log.debug "Install command: #{ sprintf(install_command_template, *install_args) }"
124
+ shell_out!(sprintf(install_command_template, *install_args), {:timeout => @new_resource.timeout, :returns => @new_resource.success_codes})
125
+ end
126
+
127
+ def remove_package(name, version)
128
+ uninstall_string = installed_packages[@new_resource.package_name][:uninstall_string]
129
+ Chef::Log.info("Registry provided uninstall string for #{@new_resource} is '#{uninstall_string}'")
130
+ uninstall_command = begin
131
+ if uninstall_string =~ /msiexec/i
132
+ "#{uninstall_string} /qn"
133
+ else
134
+ uninstall_string.gsub!('"','')
135
+ "start \"\" /wait /d\"#{::File.dirname(uninstall_string)}\" #{::File.basename(uninstall_string)}#{expand_options(@new_resource.options)} /S"
136
+ end
137
+ end
138
+ Chef::Log.info("Removing #{@new_resource} with uninstall command '#{uninstall_command}'")
139
+ shell_out!(uninstall_command, {:returns => @new_resource.success_codes})
140
+ end
141
+
142
+ private
143
+
144
+ def install_command_template
145
+ case installer_type
146
+ when :msi
147
+ "msiexec%2$s \"%1$s\"%3$s"
148
+ else
149
+ "start \"\" /wait \"%1$s\"%2$s%3$s"
150
+ end
151
+ end
152
+
153
+ def uninstall_command_template
154
+ case installer_type
155
+ when :msi
156
+ "msiexec %2$s %1$s"
157
+ else
158
+ "start \"\" /wait /d%1$s %2$s %3$s"
159
+ end
160
+ end
161
+
162
+ # http://unattended.sourceforge.net/installers.php
163
+ def unattended_installation_flags
164
+ case installer_type
165
+ when :msi
166
+ # this is no-ui
167
+ "/qn /i"
168
+ when :installshield
169
+ "/s /sms"
170
+ when :nsis
171
+ "/S /NCRC"
172
+ when :inno
173
+ #"/sp- /silent /norestart"
174
+ "/verysilent /norestart"
175
+ when :wise
176
+ "/s"
177
+ else
178
+ end
179
+ end
180
+
181
+ def installed_packages
182
+ @installed_packages || begin
183
+ installed_packages = {}
184
+ # Computer\HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall
185
+ installed_packages.merge!(extract_installed_packages_from_key(::Win32::Registry::HKEY_LOCAL_MACHINE)) #rescue nil
186
+ # 64-bit registry view
187
+ # Computer\HKEY_LOCAL_MACHINE\Software\Wow6464Node\Microsoft\Windows\CurrentVersion\Uninstall
188
+ installed_packages.merge!(extract_installed_packages_from_key(::Win32::Registry::HKEY_LOCAL_MACHINE, (::Win32::Registry::Constants::KEY_READ | 0x0100))) #rescue nil
189
+ # 32-bit registry view
190
+ # Computer\HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall
191
+ installed_packages.merge!(extract_installed_packages_from_key(::Win32::Registry::HKEY_LOCAL_MACHINE, (::Win32::Registry::Constants::KEY_READ | 0x0200))) #rescue nil
192
+ # Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall
193
+ installed_packages.merge!(extract_installed_packages_from_key(::Win32::Registry::HKEY_CURRENT_USER)) #rescue nil
194
+ installed_packages
195
+ end
196
+ end
197
+
198
+ def extract_installed_packages_from_key(hkey = ::Win32::Registry::HKEY_LOCAL_MACHINE, desired = ::Win32::Registry::Constants::KEY_READ)
199
+ uninstall_subkey = 'Software\Microsoft\Windows\CurrentVersion\Uninstall'
200
+ packages = {}
201
+ begin
202
+ ::Win32::Registry.open(hkey, uninstall_subkey, desired) do |reg|
203
+ reg.each_key do |key, wtime|
204
+ begin
205
+ k = reg.open(key, desired)
206
+ display_name = k["DisplayName"] rescue nil
207
+ version = k["DisplayVersion"] rescue "NO VERSION"
208
+ uninstall_string = k["UninstallString"] rescue nil
209
+ if display_name
210
+ packages[display_name] = {:name => display_name,
211
+ :version => version,
212
+ :uninstall_string => uninstall_string}
213
+ end
214
+ rescue ::Win32::Registry::Error
215
+ end
216
+ end
217
+ end
218
+ rescue ::Win32::Registry::Error
219
+ end
220
+ packages
221
+ end
222
+
223
+ def installer_type
224
+ @installer_type || begin
225
+ if @new_resource.installer_type
226
+ @new_resource.installer_type
227
+ else
228
+ basename = ::File.basename(cached_file(@new_resource.source, @new_resource.checksum))
229
+ if basename.split(".").last.downcase == "msi" # Microsoft MSI
230
+ :msi
231
+ else
232
+ # search the binary file for installer type
233
+ contents = ::Kernel.open(::File.expand_path(cached_file(@new_resource.source)), "rb") {|io| io.read } # TODO limit data read in
234
+ case contents
235
+ when /inno/i # Inno Setup
236
+ :inno
237
+ when /wise/i # Wise InstallMaster
238
+ :wise
239
+ when /nsis/i # Nullsoft Scriptable Install System
240
+ :nsis
241
+ else
242
+ # if file is named 'setup.exe' assume installshield
243
+ if basename == "setup.exe"
244
+ :installshield
245
+ else
246
+ raise Chef::Exceptions::AttributeNotFound, "installer_type could not be determined, please set manually"
247
+ end
248
+ end
249
+ end
250
+ end
251
+ end
252
+ end
@@ -0,0 +1,153 @@
1
+ #
2
+ # Author:: Kevin Moser (<kevin.moser@nordstrom.com>)
3
+ # Cookbook Name:: windows
4
+ # Provider:: pagefile
5
+ #
6
+ # Copyright:: 2012, Nordstrom, Inc.
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
+ include Chef::Mixin::ShellOut
22
+ include Windows::Helper
23
+
24
+ action :set do
25
+ pagefile = @new_resource.name
26
+ initial_size = @new_resource.initial_size
27
+ maximum_size = @new_resource.maximum_size
28
+ system_managed = @new_resource.system_managed
29
+ automatic_managed = @new_resource.automatic_managed
30
+ updated = false
31
+
32
+ if automatic_managed
33
+ unless automatic_managed?
34
+ set_automatic_managed
35
+ updated = true
36
+ end
37
+ else
38
+ if automatic_managed?
39
+ unset_automatic_managed
40
+ updated = true
41
+ end
42
+
43
+ # Check that the resource is not just trying to unset automatic managed, if it is do nothing more
44
+ if (initial_size && maximum_size) || system_managed
45
+ unless exists?(pagefile)
46
+ create(pagefile)
47
+ end
48
+
49
+ if system_managed
50
+ unless max_and_min_set?(pagefile, 0, 0)
51
+ set_system_managed(pagefile)
52
+ updated = true
53
+ end
54
+ else
55
+ unless max_and_min_set?(pagefile, initial_size, maximum_size)
56
+ set_custom_size(pagefile, initial_size, maximum_size)
57
+ updated = true
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ @new_resource.updated_by_last_action(updated)
64
+ end
65
+
66
+ action :delete do
67
+ pagefile = @new_resource.name
68
+ updated = false
69
+
70
+ if exists?(pagefile)
71
+ delete(pagefile)
72
+ updated = true
73
+ end
74
+
75
+ @new_resource.updated_by_last_action(updated)
76
+ end
77
+
78
+
79
+ private
80
+ def exists?(pagefile)
81
+ @exists ||= begin
82
+ cmd = shell_out("#{wmic} pagefileset where SettingID=\"#{get_setting_id(pagefile)}\" list /format:list", {:returns => [0]})
83
+ cmd.stderr.empty? && (cmd.stdout =~ /SettingID=#{get_setting_id(pagefile)}/i)
84
+ end
85
+ end
86
+
87
+ def max_and_min_set?(pagefile, min, max)
88
+ @max_and_min_set ||= begin
89
+ cmd = shell_out("#{wmic} pagefileset where SettingID=\"#{get_setting_id(pagefile)}\" list /format:list", {:returns => [0]})
90
+ cmd.stderr.empty? && (cmd.stdout =~ /InitialSize=#{min}/i) && (cmd.stdout =~ /MaximumSize=#{max}/i)
91
+ end
92
+ end
93
+
94
+ def create(pagefile)
95
+ Chef::Log.debug("Creating pagefile #{pagefile}")
96
+ cmd = shell_out("#{wmic} pagefileset create name=\"#{win_friendly_path(pagefile)}\"")
97
+ check_for_errors(cmd.stderr)
98
+ end
99
+
100
+ def delete(pagefile)
101
+ Chef::Log.debug("Removing pagefile #{pagefile}")
102
+ cmd = shell_out("#{wmic} pagefileset where SettingID=\"#{get_setting_id(pagefile)}\" delete")
103
+ check_for_errors(cmd.stderr)
104
+ end
105
+
106
+ def automatic_managed?
107
+ @automatic_managed ||= begin
108
+ cmd = shell_out("#{wmic} computersystem where name=\"%computername%\" get AutomaticManagedPagefile /format:list")
109
+ cmd.stderr.empty? && (cmd.stdout =~ /AutomaticManagedPagefile=TRUE/i)
110
+ end
111
+ end
112
+
113
+ def set_automatic_managed
114
+ Chef::Log.debug("Setting pagefile to Automatic Managed")
115
+ cmd = shell_out("#{wmic} computersystem where name=\"%computername%\" set AutomaticManagedPagefile=True")
116
+ check_for_errors(cmd.stderr)
117
+ end
118
+
119
+ def unset_automatic_managed
120
+ Chef::Log.debug("Setting pagefile to User Managed")
121
+ cmd = shell_out("#{wmic} computersystem where name=\"%computername%\" set AutomaticManagedPagefile=False")
122
+ check_for_errors(cmd.stderr)
123
+ end
124
+
125
+ def set_custom_size(pagefile, min, max)
126
+ Chef::Log.debug("Setting #{pagefile} to InitialSize=#{min} & MaximumSize=#{max}")
127
+ cmd = shell_out("#{wmic} pagefileset where SettingID=\"#{get_setting_id(pagefile)}\" set InitialSize=#{min},MaximumSize=#{max}", {:returns => [0]})
128
+ check_for_errors(cmd.stderr)
129
+ end
130
+
131
+ def set_system_managed(pagefile)
132
+ Chef::Log.debug("Setting #{pagefile} to System Managed")
133
+ cmd = shell_out("#{wmic} pagefileset where SettingID=\"#{get_setting_id(pagefile)}\" set InitialSize=0,MaximumSize=0", {:returns => [0]})
134
+ check_for_errors(cmd.stderr)
135
+ end
136
+
137
+ def get_setting_id(pagefile)
138
+ pagefile = win_friendly_path(pagefile)
139
+ pagefile = pagefile.split("\\")
140
+ "#{pagefile[1]} @ #{pagefile[0]}"
141
+ end
142
+
143
+ def check_for_errors(stderr)
144
+ unless stderr.empty?
145
+ Chef::Log.fatal(stderr)
146
+ end
147
+ end
148
+
149
+ def wmic
150
+ @wmic ||= begin
151
+ locate_sysnative_cmd("wmic.exe")
152
+ end
153
+ end
@@ -0,0 +1,35 @@
1
+ #
2
+ # Author:: Paul Morotn (<pmorton@biaprotect.com>)
3
+ # Cookbook Name:: windows
4
+ # Provider:: path
5
+ #
6
+ # Copyright:: 2011, Business Intelligence Associates, Inc
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
+ action :add do
22
+ env "PATH" do
23
+ action :modify
24
+ delim ::File::PATH_SEPARATOR
25
+ value new_resource.path
26
+ end
27
+ end
28
+
29
+ action :remove do
30
+ env "PATH" do
31
+ action :delete
32
+ delim ::File::PATH_SEPARATOR
33
+ value new_resource.path
34
+ end
35
+ end
@@ -0,0 +1,100 @@
1
+ #
2
+ # Author:: Doug Ireton (<doug.ireton@nordstrom.com>)
3
+ # Cookbook Name:: windows
4
+ # Provider:: printer
5
+ #
6
+ # Copyright:: 2012, Nordstrom, Inc.
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
+ # Support whyrun
22
+ def whyrun_supported?
23
+ true
24
+ end
25
+
26
+ action :create do
27
+ if @current_resource.exists
28
+ Chef::Log.info "#{ @new_resource } already exists - nothing to do."
29
+ else
30
+ converge_by("Create #{ @new_resource }") do
31
+ create_printer
32
+ end
33
+ end
34
+ end
35
+
36
+ action :delete do
37
+ if @current_resource.exists
38
+ converge_by("Delete #{ @new_resource }") do
39
+ delete_printer
40
+ end
41
+ else
42
+ Chef::Log.info "#{ @current_resource } doesn't exist - can't delete."
43
+ end
44
+ end
45
+
46
+ def load_current_resource
47
+ @current_resource = Chef::Resource::WindowsPrinter.new(@new_resource.name)
48
+ @current_resource.name(@new_resource.name)
49
+
50
+ if printer_exists?(@current_resource.name)
51
+ # TODO: Set @current_resource printer properties from registry
52
+ @current_resource.exists = true
53
+ end
54
+ end
55
+
56
+
57
+ private
58
+
59
+ PRINTERS_REG_KEY = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\\'.freeze unless defined?(PRINTERS_REG_KEY)
60
+
61
+ def printer_exists?(name)
62
+ printer_reg_key = PRINTERS_REG_KEY + name
63
+ Chef::Log.debug "Checking to see if this reg key exists: '#{ printer_reg_key }'"
64
+ Registry.key_exists?(printer_reg_key)
65
+ end
66
+
67
+ def create_printer
68
+
69
+ # Create the printer port first
70
+ windows_printer_port new_resource.ipv4_address do
71
+ end
72
+
73
+ port_name = "IP_#{ new_resource.ipv4_address }"
74
+
75
+ powershell_script "Creating printer: #{ new_resource.name }" do
76
+ code <<-EOH
77
+
78
+ Set-WmiInstance -class Win32_Printer `
79
+ -EnableAllPrivileges `
80
+ -Argument @{ DeviceID = "#{ new_resource.device_id }";
81
+ Comment = "#{ new_resource.comment }";
82
+ Default = "$#{ new_resource.default }";
83
+ DriverName = "#{ new_resource.driver_name }";
84
+ Location = "#{ new_resource.location }";
85
+ PortName = "#{ port_name }";
86
+ Shared = "$#{ new_resource.shared }";
87
+ ShareName = "#{ new_resource.share_name }";
88
+ }
89
+ EOH
90
+ end
91
+ end
92
+
93
+ def delete_printer
94
+ powershell_script "Deleting printer: #{ new_resource.name }" do
95
+ code <<-EOH
96
+ $printer = Get-WMIObject -class Win32_Printer -EnableAllPrivileges -Filter "name = '#{ new_resource.name }'"
97
+ $printer.Delete()
98
+ EOH
99
+ end
100
+ end
@@ -0,0 +1,102 @@
1
+ #
2
+ # Author:: Doug Ireton (<doug.ireton@nordstrom.com>)
3
+ # Cookbook Name:: windows
4
+ # Provider:: printer_port
5
+ #
6
+ # Copyright:: 2012, Nordstrom, Inc.
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
+ # Support whyrun
22
+ def whyrun_supported?
23
+ true
24
+ end
25
+
26
+ action :create do
27
+ if @current_resource.exists
28
+ Chef::Log.info "#{ @new_resource } already exists - nothing to do."
29
+ else
30
+ converge_by("Create #{ @new_resource }") do
31
+ create_printer_port
32
+ end
33
+ end
34
+ end
35
+
36
+ action :delete do
37
+ if @current_resource.exists
38
+ converge_by("Delete #{ @new_resource }") do
39
+ delete_printer_port
40
+ end
41
+ else
42
+ Chef::Log.info "#{ @current_resource } doesn't exist - can't delete."
43
+ end
44
+ end
45
+
46
+ def load_current_resource
47
+ @current_resource = Chef::Resource::WindowsPrinterPort.new(@new_resource.name)
48
+ @current_resource.name(@new_resource.name)
49
+ @current_resource.ipv4_address(@new_resource.ipv4_address)
50
+ @current_resource.port_name(@new_resource.port_name || "IP_#{ @new_resource.ipv4_address }")
51
+
52
+ if port_exists?(@current_resource.port_name)
53
+ # TODO: Set @current_resource port properties from registry
54
+ @current_resource.exists = true
55
+ end
56
+ end
57
+
58
+
59
+ private
60
+
61
+ PORTS_REG_KEY = 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\\'.freeze unless defined?(PORTS_REG_KEY)
62
+
63
+ def port_exists?(name)
64
+ port_reg_key = PORTS_REG_KEY + name
65
+
66
+ Chef::Log.debug "Checking to see if this reg key exists: '#{ port_reg_key }'"
67
+ Registry.key_exists?(port_reg_key)
68
+ end
69
+
70
+
71
+ def create_printer_port
72
+
73
+ port_name = new_resource.port_name || "IP_#{ new_resource.ipv4_address }"
74
+
75
+ # create the printer port using PowerShell
76
+ powershell_script "Creating printer port #{ new_resource.port_name }" do
77
+ code <<-EOH
78
+
79
+ Set-WmiInstance -class Win32_TCPIPPrinterPort `
80
+ -EnableAllPrivileges `
81
+ -Argument @{ HostAddress = "#{ new_resource.ipv4_address }";
82
+ Name = "#{ port_name }";
83
+ Description = "#{ new_resource.port_description }";
84
+ PortNumber = "#{ new_resource.port_number }";
85
+ Protocol = "#{ new_resource.port_protocol }";
86
+ SNMPEnabled = "$#{ new_resource.snmp_enabled }";
87
+ }
88
+ EOH
89
+ end
90
+ end
91
+
92
+ def delete_printer_port
93
+
94
+ port_name = new_resource.port_name || "IP_#{ new_resource.ipv4_address }"
95
+
96
+ powershell_script "Deleting printer port: #{ new_resource.port_name }" do
97
+ code <<-EOH
98
+ $port = Get-WMIObject -class Win32_TCPIPPrinterPort -EnableAllPrivileges -Filter "name = '#{ port_name }'"
99
+ $port.Delete()
100
+ EOH
101
+ end
102
+ end
@@ -0,0 +1,31 @@
1
+ #
2
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ # Cookbook Name:: windows
4
+ # Provider:: reboot
5
+ #
6
+ # Copyright:: 2011, Opscode, Inc.
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
+ action :request do
22
+ node.run_state[:reboot_requested] = true
23
+ node.run_state[:reboot_timeout] = @new_resource.timeout
24
+ node.run_state[:reboot_reason] = @new_resource.reason
25
+ end
26
+
27
+ action :cancel do
28
+ node.run_state.delete(:reboot_requested)
29
+ node.run_state.delete(:reboot_timeout)
30
+ node.run_state.delete(:reboot_reason)
31
+ end