summaryrefslogtreecommitdiff
path: root/lib/chef/provider
diff options
context:
space:
mode:
authorEzra Zygmuntowicz <ez@engineyard.com>2008-10-08 14:19:52 -0700
committerEzra Zygmuntowicz <ez@engineyard.com>2008-10-08 14:19:52 -0700
commitc5d33c1298834ce40b8fbf344f281045771b5371 (patch)
tree1f0d4c7eab1eb379b544282a7ce48052acf719a5 /lib/chef/provider
parent3d14601aea23dee3899d097324875274da419d84 (diff)
downloadchef-c5d33c1298834ce40b8fbf344f281045771b5371.tar.gz
big refactor of the repo layout. move to a chef gem and a chef-server gem all with proper deps
Diffstat (limited to 'lib/chef/provider')
-rw-r--r--lib/chef/provider/directory.rb68
-rw-r--r--lib/chef/provider/execute.rb55
-rw-r--r--lib/chef/provider/file.rb169
-rw-r--r--lib/chef/provider/link.rb71
-rw-r--r--lib/chef/provider/package.rb105
-rw-r--r--lib/chef/provider/package/apt.rb89
-rw-r--r--lib/chef/provider/package/portage.rb93
-rw-r--r--lib/chef/provider/package/rubygems.rb116
-rw-r--r--lib/chef/provider/remote_directory.rb78
-rw-r--r--lib/chef/provider/remote_file.rb80
-rw-r--r--lib/chef/provider/script.rb35
-rw-r--r--lib/chef/provider/service.rb86
-rw-r--r--lib/chef/provider/service/debian.rb53
-rw-r--r--lib/chef/provider/service/init.rb95
-rw-r--r--lib/chef/provider/sysctl.rb38
-rw-r--r--lib/chef/provider/template.rb69
-rw-r--r--lib/chef/provider/user.rb172
-rw-r--r--lib/chef/provider/user/useradd.rb88
18 files changed, 0 insertions, 1560 deletions
diff --git a/lib/chef/provider/directory.rb b/lib/chef/provider/directory.rb
deleted file mode 100644
index d042b6a8eb..0000000000
--- a/lib/chef/provider/directory.rb
+++ /dev/null
@@ -1,68 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@hjksolutions.com>)
-# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require File.join(File.dirname(__FILE__), "file")
-require "fileutils"
-
-class Chef
- class Provider
- class Directory < Chef::Provider::File
- def load_current_resource
- @current_resource = Chef::Resource::Directory.new(@new_resource.name)
- @current_resource.path(@new_resource.path)
- if ::File.exist?(@current_resource.path) && ::File.directory?(@current_resource.path)
- cstats = ::File.stat(@current_resource.path)
- @current_resource.owner(cstats.uid)
- @current_resource.group(cstats.gid)
- @current_resource.mode("%o" % (cstats.mode & 007777))
- end
- @current_resource
- end
-
- def action_create
- unless ::File.exists?(@new_resource.path)
- Chef::Log.info("Creating #{@new_resource} at #{@new_resource.path}")
- if @new_resource.recursive == true
- ::FileUtils.mkdir_p(@new_resource.path)
- else
- ::Dir.mkdir(@new_resource.path)
- end
- @new_resource.updated = true
- end
- set_owner if @new_resource.owner != nil
- set_group if @new_resource.group != nil
- set_mode if @new_resource.mode != nil
- end
-
- def action_delete
- if ::File.exists?(@new_resource.path) && ::File.writable?(@new_resource.path)
- if @new_resource.recursive == true
- Chef::Log.info("Deleting #{@new_resource} recursively at #{@new_resource.path}")
- FileUtils.rm_rf(@new_resource.path)
- else
- Chef::Log.info("Deleting #{@new_resource} at #{@new_resource.path}")
- ::Dir.delete(@new_resource.path)
- end
- @new_resource.updated = true
- else
- raise RuntimeError, "Cannot delete #{@new_resource} at #{@new_resource_path}!" if ::File.exists?(@new_resource.path)
- end
- end
- end
- end
-end \ No newline at end of file
diff --git a/lib/chef/provider/execute.rb b/lib/chef/provider/execute.rb
deleted file mode 100644
index 67a706e4f1..0000000000
--- a/lib/chef/provider/execute.rb
+++ /dev/null
@@ -1,55 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@hjksolutions.com>)
-# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require File.join(File.dirname(__FILE__), "..", "mixin", "command")
-
-class Chef
- class Provider
- class Execute < Chef::Provider
-
- include Chef::Mixin::Command
-
- def load_current_resource
- true
- end
-
- def action_run
- command_args = {
- :command => @new_resource.command,
- :command_string => @new_resource.to_s,
- }
- command_args[:creates] = @new_resource.creates if @new_resource.creates
- command_args[:onlyif] = @new_resource.onlyif if @new_resource.onlyif
- command_args[:not_if] = @new_resource.not_if if @new_resource.not_if
- command_args[:timeout] = @new_resource.timeout if @new_resource.timeout
- command_args[:returns] = @new_resource.returns if @new_resource.returns
- command_args[:environment] = @new_resource.environment if @new_resource.environment
- command_args[:user] = @new_resource.user if @new_resource.user
- command_args[:group] = @new_resource.group if @new_resource.group
- command_args[:cwd] = @new_resource.cwd if @new_resource.cwd
-
- status = run_command(command_args)
- if status
- @new_resource.updated = true
- Chef::Log.info("Ran #{@new_resource} successfully")
- end
- end
-
- end
- end
-end \ No newline at end of file
diff --git a/lib/chef/provider/file.rb b/lib/chef/provider/file.rb
deleted file mode 100644
index d25e5decca..0000000000
--- a/lib/chef/provider/file.rb
+++ /dev/null
@@ -1,169 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@hjksolutions.com>)
-# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'etc'
-require 'fileutils'
-require File.join(File.dirname(__FILE__), "..", "mixin", "checksum")
-require File.join(File.dirname(__FILE__), "..", "mixin", "generate_url")
-
-class Chef
- class Provider
- class File < Chef::Provider
- include Chef::Mixin::Checksum
- include Chef::Mixin::GenerateURL
-
- def load_current_resource
- @current_resource = Chef::Resource::File.new(@new_resource.name)
- @current_resource.path(@new_resource.path)
- if ::File.exist?(@current_resource.path) && ::File.readable?(@current_resource.path)
- cstats = ::File.stat(@current_resource.path)
- @current_resource.owner(cstats.uid)
- @current_resource.group(cstats.gid)
- @current_resource.mode("%o" % (cstats.mode & 007777))
- @current_resource.checksum(checksum(@current_resource.path))
- end
- @current_resource
- end
-
- # Compare the ownership of a file. Returns true if they are the same, false if they are not.
- def compare_owner
- if @new_resource.owner != nil
- case @new_resource.owner
- when /^\d+$/, Integer
- @set_user_id = @new_resource.owner.to_i
- @set_user_id == @current_resource.owner
- else
- # This raises an ArugmentError if you can't find the user
- user_info = Etc.getpwnam(@new_resource.owner)
- @set_user_id = user_info.uid
- @set_user_id == @current_resource.owner
- end
- end
- end
-
- # Set the ownership on the file, assuming it is not set correctly already.
- def set_owner
- unless compare_owner
- Chef::Log.info("Setting owner to #{@set_user_id} for #{@new_resource}")
- ::File.chown(@set_user_id, nil, @new_resource.path)
- @new_resource.updated = true
- end
- end
-
- # Compares the group of a file. Returns true if they are the same, false if they are not.
- def compare_group
- if @new_resource.group != nil
- case @new_resource.group
- when /^\d+$/, Integer
- @set_group_id = @new_resource.group.to_i
- @set_group_id == @current_resource.group
- else
- group_info = Etc.getgrnam(@new_resource.group)
- @set_group_id = group_info.gid
- @set_group_id == @current_resource.group
- end
- end
- end
-
- def set_group
- unless compare_group
- Chef::Log.info("Setting group to #{@set_group_id} for #{@new_resource}")
- ::File.chown(nil, @set_group_id, @new_resource.path)
- @new_resource.updated = true
- end
- end
-
- def compare_mode
- if @new_resource.mode != nil
- case @new_resource.mode
- when /^\d+$/, Integer
- real_mode = sprintf("%o" % (@new_resource.mode & 007777))
- real_mode.to_i == @current_resource.mode.to_i
- end
- end
- end
-
- def set_mode
- unless compare_mode && @new_resource.mode != nil
- Chef::Log.info("Setting mode to #{sprintf("%o" % (@new_resource.mode & 007777))
- } for #{@new_resource}")
- ::File.chmod(@new_resource.mode.to_i, @new_resource.path)
- @new_resource.updated = true
- end
- end
-
- def action_create
- unless ::File.exists?(@new_resource.path)
- Chef::Log.info("Creating #{@new_resource} at #{@new_resource.path}")
- ::File.open(@new_resource.path, "w+") { |f| }
- @new_resource.updated = true
- end
- set_owner if @new_resource.owner != nil
- set_group if @new_resource.group != nil
- set_mode if @new_resource.mode != nil
- end
-
- def action_delete
- if ::File.exists?(@new_resource.path) && ::File.writable?(@new_resource.path)
- backup
- Chef::Log.info("Deleting #{@new_resource} at #{@new_resource.path}")
- ::File.delete(@new_resource.path)
- @new_resource.updated = true
- else
- raise "Cannot delete #{@new_resource} at #{@new_resource_path}!"
- end
- end
-
- def action_touch
- action_create
- time = Time.now
- Chef::Log.info("Updating #{@new_resource} with new atime/mtime of #{time}")
- ::File.utime(time, time, @new_resource.path)
- @new_resource.updated = true
- end
-
- def backup(file=nil)
- file ||= @new_resource.path
- if @new_resource.backup && ::File.exist?(file)
- time = Time.now
- savetime = time.strftime("%Y%m%d%H%M%S")
- backup_filename = "#{@new_resource.path}.chef-#{savetime}"
- Chef::Log.info("Backing up #{@new_resource} to #{backup_filename}")
- FileUtils.cp(file, backup_filename)
-
- # Clean up after the number of backups
- slice_number = @new_resource.backup - 1
- backup_files = Dir["#{@new_resource.path}.chef-*"].sort { |a,b| b <=> a }
- if backup_files.length >= @new_resource.backup
- remainder = backup_files.slice(slice_number..-1)
- remainder.each do |backup_to_delete|
- Chef::Log.info("Removing backup of #{@new_resource} at #{backup_to_delete}")
- FileUtils.rm(backup_to_delete)
- end
- end
-
- end
- end
-
- def generate_url(url, type, args=nil)
- generate_cookbook_url(url, @new_resource.cookbook_name, type, @node, args)
- end
-
- end
- end
-end \ No newline at end of file
diff --git a/lib/chef/provider/link.rb b/lib/chef/provider/link.rb
deleted file mode 100644
index 843a4ad009..0000000000
--- a/lib/chef/provider/link.rb
+++ /dev/null
@@ -1,71 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@hjksolutions.com>)
-# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-class Chef
- class Provider
- class Link < Chef::Provider
- def load_current_resource
- @current_resource = Chef::Resource::Link.new(@new_resource.name)
- @current_resource.target_file(@new_resource.target_file)
- @current_resource.link_type(@new_resource.link_type)
- if @new_resource.link_type == :symbolic
- if ::File.exists?(@current_resource.target_file) && ::File.symlink?(@current_resource.target_file)
- @current_resource.source_file(
- ::File.expand_path(::File.readlink(@current_resource.target_file))
- )
- else
- @current_resource.source_file("")
- end
- elsif @new_resource.link_type == :hard
- if ::File.exists?(@current_resource.target_file) && ::File.exists?(@new_resource.source_file)
- if ::File.stat(@current_resource.target_file).ino == ::File.stat(@new_resource.source_file).ino
- @current_resource.source_file(@new_resource.source_file)
- else
- @current_resource.source_file("")
- end
- else
- @current_resource.source_file("")
- end
- end
- @current_resource
- end
-
- def action_create
- if @current_resource.source_file != @new_resource.source_file
- Chef::Log.info("Creating a #{@new_resource.link_type} link from #{@new_resource.source_file} -> #{@new_resource.target_file} for #{@new_resource}")
- if @new_resource.link_type == :symbolic
- ::File.symlink(@new_resource.source_file, @new_resource.target_file)
- elsif @new_resource.link_type == :hard
- ::File.link(@new_resource.source_file, @new_resource.target_file)
- end
- @new_resource.updated = true
- end
- end
-
- def action_delete
- if ::File.exists?(@new_resource.target_file) && ::File.writable?(@new_resource.target_file)
- Chef::Log.info("Deleting #{@new_resource} at #{@new_resource.target_file}")
- ::File.delete(@new_resource.target_file)
- @new_resource.updated = true
- else
- raise "Cannot delete #{@new_resource} at #{@new_resource_path}!"
- end
- end
- end
- end
-end \ No newline at end of file
diff --git a/lib/chef/provider/package.rb b/lib/chef/provider/package.rb
deleted file mode 100644
index a68c2e88f2..0000000000
--- a/lib/chef/provider/package.rb
+++ /dev/null
@@ -1,105 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@hjksolutions.com>)
-# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require File.join(File.dirname(__FILE__), "..", "mixin", "command")
-
-class Chef
- class Provider
- class Package < Chef::Provider
-
- include Chef::Mixin::Command
-
- def initialize(node, new_resource)
- super(node, new_resource)
- @candidate_version = nil
- end
-
- def action_install
- # First, select what version we should be using
- install_version = @new_resource.version
- install_version ||= @candidate_version
-
- unless install_version
- raise(Chef::Exception::Package, "No version specified, and no candidate version available!")
- end
-
- do_package = false
- # If it's not installed at all, install it
- if @current_resource.version == nil
- do_package = true
- # If we specified a version, and it's not the current version, move to the current version
- elsif @new_resource.version != nil
- if @new_resource.version != @current_resource.version
- do_package = true
- end
- end
-
- if do_package
- Chef::Log.info("Installing #{@new_resource} version #{install_version} successfully")
- status = install_package(@new_resource.package_name, install_version)
- if status
- @new_resource.updated = true
- end
- end
- end
-
- def action_upgrade
- if @current_resource.version != @candidate_version
- Chef::Log.info("Upgrading #{@new_resource} version from #{@current_resource.version} to #{@candidate_version} successfully")
- status = install_package(@new_resource.package_name, @candidate_version)
- if status
- @new_resource.updated = true
- end
- end
- end
-
- def action_remove
- if @current_resource.version != nil
- Chef::Log.info("Removing #{@new_resource} successfully")
- remove_package(@new_resource.package_name, @new_resource.version)
- @new_resource.updated = true
- end
- end
-
- def action_purge
- if @current_resource.version != nil
- Chef::Log.info("Purging #{@new_resource} successfully")
- purge_package(@new_resource.package_name, @new_resource.version)
- @new_resource.updated = true
- end
- end
-
- def install_package(name, version)
- raise Chef::Exception::UnsupportedAction, "#{self.to_s} does not support :install"
- end
-
- def upgrade_package(name, version)
- raise Chef::Exception::UnsupportedAction, "#{self.to_s} does not support :upgrade"
- end
-
- def remove_package(name, version)
- raise Chef::Exception::UnsupportedAction, "#{self.to_s} does not support :remove"
- end
-
- def purge_package(name, version)
- raise Chef::Exception::UnsupportedAction, "#{self.to_s} does not support :purge"
- end
-
- end
- end
-end
diff --git a/lib/chef/provider/package/apt.rb b/lib/chef/provider/package/apt.rb
deleted file mode 100644
index a2e9bd68a2..0000000000
--- a/lib/chef/provider/package/apt.rb
+++ /dev/null
@@ -1,89 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@hjksolutions.com>)
-# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require File.join(File.dirname(__FILE__), "..", "package")
-require File.join(File.dirname(__FILE__), "..", "..", "mixin", "command")
-
-class Chef
- class Provider
- class Package
- class Apt < Chef::Provider::Package
-
- def load_current_resource
- @current_resource = Chef::Resource::Package.new(@new_resource.name)
- @current_resource.package_name(@new_resource.package_name)
-
- status = popen4("apt-cache policy #{@new_resource.package_name}") do |pid, stdin, stdout, stderr|
- stdin.close
- stdout.each do |line|
- case line
- when /^\s{2}Installed: (.+)$/
- installed_version = $1
- if installed_version == '(none)'
- @current_resource.version(nil)
- else
- @current_resource.version(installed_version)
- end
- when /^\s{2}Candidate: (.+)$/
- @candidate_version = $1
- end
- end
- end
-
- unless status.exitstatus == 0
- raise Chef::Exception::Package, "apt-cache failed - #{status.inspect}!"
- end
-
- @current_resource
- end
-
- def install_package(name, version)
- run_command(
- :command => "apt-get -q -y install #{name}=#{version}",
- :environment => {
- "DEBIAN_FRONTEND" => "noninteractive"
- }
- )
- end
-
- def upgrade_package(name, version)
- install_package(name, version)
- end
-
- def remove_package(name, version)
- run_command(
- :command => "apt-get -q -y remove #{@new_resource.package_name}",
- :environment => {
- "DEBIAN_FRONTEND" => "noninteractive"
- }
- )
- end
-
- def purge_package(name, version)
- run_command(
- :command => "apt-get -q -y purge #{@new_resource.package_name}",
- :environment => {
- "DEBIAN_FRONTEND" => "noninteractive"
- }
- )
- end
-
- end
- end
- end
-end
diff --git a/lib/chef/provider/package/portage.rb b/lib/chef/provider/package/portage.rb
deleted file mode 100644
index 8981a386bc..0000000000
--- a/lib/chef/provider/package/portage.rb
+++ /dev/null
@@ -1,93 +0,0 @@
-#
-# Author:: Ezra Zygmuntowicz (<ezra@engineyard.com>)
-# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require File.join(File.dirname(__FILE__), "..", "package")
-require File.join(File.dirname(__FILE__), "..", "..", "mixin", "command")
-
-class Chef
- class Provider
- class Package
- class Portage < Chef::Provider::Package
-
- def load_current_resource
- @current_resource = Chef::Resource::Package.new(@new_resource.name)
- @current_resource.package_name(@new_resource.package_name)
-
- status = popen4("emerge --color n --nospinner --search #{@new_resource.package_name}") do |pid, stdin, stdout, stderr|
- stdin.close
-
- available, installed = parse_emerge(@new_resource.package_name, stdout.read)
-
- if installed == "[ Not Installed ]"
- @current_resource.version(nil)
- else
- @current_resource.version(installed)
- end
- @candidate_version = available
- end
-
- unless status.exitstatus == 0
- raise Chef::Exception::Package, "emerge --search failed - #{status.inspect}!"
- end
-
- @current_resource
- end
-
-
- def parse_emerge(package, txt)
- available, installed, pkg = nil
- txt.each do |line|
- if line =~ /\*(.*)/
- pkg = $1.strip.split('/').last
- end
- if pkg == package
- if line =~ /Latest version available: (.*)/
- available = $1
- elsif line =~ /Latest version installed: (.*)/
- installed = $1
- end
- end
- end
- [available, installed]
- end
-
-
- def install_package(name, version)
- run_command(
- :command => "emerge -g --color n --nospinner --quiet =#{name}-#{version}"
- )
- end
-
- def upgrade_package(name, version)
- install_package(name, version)
- end
-
- def remove_package(name, version)
- run_command(
- :command => "emerge --unmerge --color n --nospinner --quiet #{@new_resource.package_name}"
- )
- end
-
- def purge_package(name, version)
- remove_package(name, version)
- end
-
- end
- end
- end
-end \ No newline at end of file
diff --git a/lib/chef/provider/package/rubygems.rb b/lib/chef/provider/package/rubygems.rb
deleted file mode 100644
index 69459ffef4..0000000000
--- a/lib/chef/provider/package/rubygems.rb
+++ /dev/null
@@ -1,116 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@hjksolutions.com>)
-# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require File.join(File.dirname(__FILE__), "..", "package")
-require File.join(File.dirname(__FILE__), "..", "..", "mixin", "command")
-
-class Chef
- class Provider
- class Package
- class Rubygems < Chef::Provider::Package
-
- def gem_list_parse(line)
- installed_versions = Array.new
- if line.match("^#{@new_resource.package_name} \\((.+?)\\)$")
- installed_versions = $1.split(/, /)
- installed_versions
- else
- nil
- end
- end
-
- def load_current_resource
- @current_resource = Chef::Resource::Package.new(@new_resource.name)
- @current_resource.package_name(@new_resource.package_name)
- @current_resource.version(nil)
-
- # First, we need to look up whether we have the local gem installed or not
- status = popen4("gem list --local #{@new_resource.package_name}") do |pid, stdin, stdout, stderr|
- stdin.close
- stdout.each do |line|
- installed_versions = gem_list_parse(line)
- next unless installed_versions
- # If the version we are asking for is installed, make that our current
- # version. Otherwise, go ahead and use the highest one, which
- # happens to come first in the array.
- if installed_versions.detect { |v| v == @new_resource.version }
- Chef::Log.debug("#{@new_resource.package_name} at version #{@new_resource.version}")
- @current_resource.version(@new_resource.version)
- else
- iv = installed_versions.first
- Chef::Log.debug("#{@new_resource.package_name} at version #{iv}")
- @current_resource.version(iv)
- end
- end
- end
-
- unless status.exitstatus == 0
- raise Chef::Exception::Package, "gem list --local failed - #{status.inspect}!"
- end
-
- status = popen4("gem list --remote #{@new_resource.package_name}") do |pid, stdin, stdout, stderr|
- stdin.close
- stdout.each do |line|
- installed_versions = gem_list_parse(line)
- next unless installed_versions
- Chef::Log.debug("I have #{installed_versions.inspect}")
-
- if installed_versions.length >= 1
- Chef::Log.debug("Setting candidate version")
- @candidate_version = installed_versions.first
- end
- end
- end
-
- unless status.exitstatus == 0
- raise Chef::Exception::Package, "gem list --remote failed - #{status.inspect}!"
- end
-
- @current_resource
- end
-
- def install_package(name, version)
- run_command(
- :command => "gem install #{name} -q --no-rdoc --no-ri -v #{version}"
- )
- end
-
- def upgrade_package(name, version)
- install_package(name, version)
- end
-
- def remove_package(name, version)
- if version
- run_command(
- :command => "gem uninstall #{name} -q -v #{version}"
- )
- else
- run_command(
- :command => "gem uninstall #{name} -q -a"
- )
- end
- end
-
- def purge_package(name, version)
- remove_package(name, version)
- end
-
- end
- end
- end
-end
diff --git a/lib/chef/provider/remote_directory.rb b/lib/chef/provider/remote_directory.rb
deleted file mode 100644
index 47d62b6308..0000000000
--- a/lib/chef/provider/remote_directory.rb
+++ /dev/null
@@ -1,78 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@hjksolutions.com>)
-# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require File.join(File.dirname(__FILE__), "file")
-require 'uri'
-require 'tempfile'
-require 'net/https'
-
-class Chef
- class Provider
- class RemoteDirectory < Chef::Provider::Directory
-
- def action_create
- super
-
- @remote_file_list = Hash.new
- do_recursive
- end
-
- def do_recursive
- Chef::Log.debug("Doing a recursive directory transfer for #{@new_resource}")
-
- r = Chef::REST.new(Chef::Config[:remotefile_url])
-
- files_to_transfer = r.get_rest(generate_url(@new_resource.source, "files", { :recursive => "true" }))
-
- files_to_transfer.each do |remote_file_source|
- full_path = ::File.join(@new_resource.path, remote_file_source)
- full_dir = ::File.dirname(full_path)
- unless ::File.directory?(full_dir)
- new_dir = Chef::Resource::Directory.new(full_dir, nil, @node)
- new_dir.cookbook_name = @new_resource.cookbook_name
- new_dir.mode(@new_resource.mode)
- new_dir.group(@new_resource.group)
- new_dir.owner(@new_resource.owner)
- new_dir.recursive(true)
-
- d_provider_class = Chef::Platform.find_provider_for_node(@node, new_dir)
- d_provider = d_provider_class.new(@node, new_dir)
- d_provider.load_current_resource
- d_provider.action_create
- @new_resource.updated = true if d_provider.new_resource.updated
- end
-
- remote_file = Chef::Resource::RemoteFile.new(full_path, nil, @node)
- remote_file.cookbook_name = @new_resource.cookbook_name
- remote_file.source(::File.join(@new_resource.source, remote_file_source))
- remote_file.mode(@new_resource.files_mode) if @new_resource.files_mode
- remote_file.group(@new_resource.files_group) if @new_resource.files_group
- remote_file.owner(@new_resource.files_owner) if @new_resource.files_owner
- remote_file.backup(@new_resource.files_backup) if @new_resource.files_backup
-
- rf_provider_class = Chef::Platform.find_provider_for_node(@node, remote_file)
- rf_provider = rf_provider_class.new(@node, remote_file)
- rf_provider.load_current_resource
- rf_provider.action_create
- @new_resource.updated = true if rf_provider.new_resource.updated
- end
- end
-
- end
- end
-end \ No newline at end of file
diff --git a/lib/chef/provider/remote_file.rb b/lib/chef/provider/remote_file.rb
deleted file mode 100644
index cc0812346e..0000000000
--- a/lib/chef/provider/remote_file.rb
+++ /dev/null
@@ -1,80 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@hjksolutions.com>)
-# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require File.join(File.dirname(__FILE__), "file")
-require 'uri'
-require 'tempfile'
-require 'net/https'
-
-class Chef
- class Provider
- class RemoteFile < Chef::Provider::File
-
- def action_create
- Chef::Log.debug("Checking #{@new_resource} for changes")
- do_remote_file(@new_resource.source, @current_resource.path)
- end
-
- def do_remote_file(source, path)
- r = Chef::REST.new(Chef::Config[:remotefile_url])
-
- current_checksum = nil
- current_checksum = self.checksum(path) if ::File.exists?(path)
-
- url = generate_url(
- source,
- "files",
- {
- :checksum => current_checksum
- }
- )
-
- raw_file = nil
- begin
- raw_file = r.get_rest(url, true)
- rescue Net::HTTPRetriableError => e
- if e.response.kind_of?(Net::HTTPNotModified)
- Chef::Log.debug("File #{path} is unchanged")
- return false
- else
- raise e
- end
- end
-
- raw_file_checksum = self.checksum(raw_file.path)
-
- if ::File.exists?(path)
- Chef::Log.debug("#{path} changed from #{current_checksum} to #{raw_file_checksum}")
- Chef::Log.info("Updating file for #{@new_resource} at #{path}")
- else
- Chef::Log.info("Creating file for #{@new_resource} at #{path}")
- end
-
- backup(path)
- FileUtils.cp(raw_file.path, path)
- @new_resource.updated = true
-
- set_owner if @new_resource.owner != nil
- set_group if @new_resource.group != nil
- set_mode if @new_resource.mode != nil
- return true
- end
-
- end
- end
-end \ No newline at end of file
diff --git a/lib/chef/provider/script.rb b/lib/chef/provider/script.rb
deleted file mode 100644
index 4669361142..0000000000
--- a/lib/chef/provider/script.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@hjksolutions.com>)
-# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'tempfile'
-
-class Chef
- class Provider
- class Script < Chef::Provider::Execute
-
- def action_run
- tf = Tempfile.new("chef-script")
- tf.puts(@new_resource.code)
- tf.close
- @new_resource.command("#{@new_resource.interpreter} #{tf.path}")
- super
- end
-
- end
- end
-end \ No newline at end of file
diff --git a/lib/chef/provider/service.rb b/lib/chef/provider/service.rb
deleted file mode 100644
index 5ac53478e3..0000000000
--- a/lib/chef/provider/service.rb
+++ /dev/null
@@ -1,86 +0,0 @@
-#
-# Author:: AJ Christensen (<aj@hjksolutions.com>)
-# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require File.join(File.dirname(__FILE__), "..", "mixin", "command")
-
-class Chef
- class Provider
- class Service < Chef::Provider
-
- include Chef::Mixin::Command
-
- def initialize(node, new_resource)
- super(node, new_resource)
- @enabled = nil
- end
-
- def action_enable
- if @current_resource.enabled == false
- Chef::Log.debug("#{@new_resource}: attempting to enable")
- status = enable_service(@new_resource.service_name)
- if status
- @new_resource.enabled == true
- Chef::Log.info("#{@new_resource}: enabled succesfully")
- end
- else
- Chef::Log.debug("#{@new_resource}: not enabling, already enabled")
- end
- end
-
- def action_disable
- if @current_resource.enabled == true
- Chef::Log.debug("#{@new_resource}: attempting to disable")
- status = disable_service(@new_resource.service_name)
- if status
- @new_resource.enabled == false
- Chef::Log.info("#{@new_resource}: disabled succesfully")
- end
- else
- Chef::Log.debug("#{@new_resource}: not disabling, already disabled")
- end
- end
-
- def action_start
- if @current_resource.running == false
- Chef::Log.debug("#{@new_resource}: attempting to start")
- status = start_service(@new_resource.service_name)
- if status
- @new_resource.running == true
- Chef::Log.info("Started service #{@new_resource} succesfully")
- end
- else
- Chef::Log.debug("#{@new_resource}: not starting, already running")
- end
- end
-
- def action_stop
- if @current_resource.running == true
- Chef::Log.debug("#{@new_resource}: attempting to stop")
- status = stop_service(@new_resource.service_name)
- if status
- @new_resource.running == false
- Chef::Log.info("#{@new_resource}: stopped succesfully")
- end
- else
- Chef::Log.debug("#{@new_resource}: not stopping, already stopped")
- end
- end
-
- end
- end
-end
diff --git a/lib/chef/provider/service/debian.rb b/lib/chef/provider/service/debian.rb
deleted file mode 100644
index 21f166ba6a..0000000000
--- a/lib/chef/provider/service/debian.rb
+++ /dev/null
@@ -1,53 +0,0 @@
-#
-# Author:: AJ Christensen (<aj@hjksolutions.com>)
-# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require File.join(File.dirname(__FILE__), "..", "service")
-require File.join(File.dirname(__FILE__), "init")
-require File.join(File.dirname(__FILE__), "..", "..", "mixin", "command")
-
-class Chef
- class Provider
- class Service
- class Debian < Chef::Provider::Service::Init
- def load_current_resource
- super
-
- status = popen4("update-rc.d -n -f #{@current_resource.service_name} remove") do |pid, stdin, stdout, stderr|
- stdin.close
- stdout.gets(nil) =~ /etc\/rc[\dS].d\/S|not installed/i ? @current_resource.enabled(true) : @current_resource.enabled(false)
- end
-
- unless status.exitstatus == 0
- raise Chef::Exception::Service, "update-rc.d -n -f #{@current_resource.service_name} failed - #{status.inspect}"
- end
-
- @current_resource
- end
-
- def enable_service(name)
- run_command(:command => "update-rc.d #{name} defaults")
- end
-
- def disable_service(name)
- run_command(:command => "update-rc.d -f #{name} remove")
- end
-
- end
- end
- end
-end
diff --git a/lib/chef/provider/service/init.rb b/lib/chef/provider/service/init.rb
deleted file mode 100644
index 0ccfc232d8..0000000000
--- a/lib/chef/provider/service/init.rb
+++ /dev/null
@@ -1,95 +0,0 @@
-#
-# Author:: AJ Christensen (<aj@hjksolutions.com>)
-# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require File.join(File.dirname(__FILE__), "..", "service")
-require File.join(File.dirname(__FILE__), "..", "..", "mixin", "command")
-
-class Chef
- class Provider
- class Service
- class Init < Chef::Provider::Service
-
- def load_current_resource
- @current_resource = Chef::Resource::Service.new(@new_resource.name)
- @current_resource.service_name(@new_resource.service_name)
- process_running = false
- if @new_resource.supports[:status]
- run_command(:command => "/etc/init.d/#{@current_resource.service_name} status") == 0 ? process_running = true : process_running = false
- elsif @new_resource.status_command
- run_command(:command => @new_resource.status_command) == 0 ? process_running = true : process_running = false
- else
- Chef::Log.debug("#{@new_resource} does not support status and you have not specified a status command, falling back to process table inspection")
- if @new_resource.pattern == @new_resource.service_name
- Chef::Log.debug("#{@new_resource} defaulting pattern to #{Regex.new(@new_resource.pattern)}")
- elsif @node[:ps] == ""
- raise Chef::Exception::Service, "#{@new_resource}: Facter could not determine how to call `ps` on your system (#{Facter["ps"].value})"
- end
-
- process_pid = nil
- status = popen4(@node[:ps]) do |pid, stdin, stdout, stderr|
- stdin.close
- r = Regexp.new(@new_resource.pattern)
- Chef::Log.debug("#{@new_resource}: attempting to match #{@new_resource.pattern} (#{r}) against process table")
- stdout.each_line do |line|
- if r.match(line)
- process_pid = line.sub(/^\s+/, '').split(/\s+/)[1]
- end
- end
- end
- unless status.exitstatus == 0
- raise Chef::Exception::Service, "Command #{@node[:ps]} failed"
- else
- process_pid ? process_running = true : process_running = false
- Chef::Log.debug("#{@new_resource}: #{@node[:ps]} exited succesfully, process_running: #{process_running}")
- end
- end
- @current_resource.running process_running
- @current_resource
- end
-
- def start_service(name)
- if @new_resource.start_command
- run_command(:command => @new_resource.start_command)
- else
- run_command(:command => "/etc/init.d/#{name} start")
- end
- end
-
- def stop_service(name)
- if @new_resource.stop_command
- run_command(:command => @new_resource.stop_command)
- else
- run_command(:command => "/etc/init.d/#{name} stop")
- end
- end
-
- def restart_service(name)
- if @new_resource.supports[:restart]
- run_command(:command => "/etc/init.d/#{name} restart")
- elsif @new_resource.restart_command
- run_command(:command => @new_resource.restart_command)
- else
- stop_service
- start_service
- end
- end
-
- end
- end
- end
-end
diff --git a/lib/chef/provider/sysctl.rb b/lib/chef/provider/sysctl.rb
deleted file mode 100644
index 09b5942f5e..0000000000
--- a/lib/chef/provider/sysctl.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@hjksolutions.com>)
-# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require File.join(File.dirname(__FILE__), "file")
-require "fileutils"
-
-class Chef
- class Provider
- class Sysctl < Chef::Provider
- def load_current_resource
- @current_resource = Chef::Resource::Sysctl.new(@new_resource.name)
- @current_resource.value(`/sbin/sysctl #{@new_resource.name}`.chomp)
- @current_resource
- end
-
- def action_set
- if @current_resource.value != @new_resource.value
- system("/sbin/sysctl #{@new_resource.name}=#{@new_resource.value}")
- end
- end
- end
- end
-end \ No newline at end of file
diff --git a/lib/chef/provider/template.rb b/lib/chef/provider/template.rb
deleted file mode 100644
index 550a1388bf..0000000000
--- a/lib/chef/provider/template.rb
+++ /dev/null
@@ -1,69 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@hjksolutions.com>)
-# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require File.join(File.dirname(__FILE__), "file")
-require File.join(File.dirname(__FILE__), "..", "mixin", "template")
-require 'uri'
-require 'tempfile'
-
-class Chef
- class Provider
- class Template < Chef::Provider::File
-
- include Chef::Mixin::Template
-
- def action_create
- r = Chef::REST.new(Chef::Config[:template_url])
-
- template_url = generate_url(@new_resource.source, "templates")
- raw_template_file = r.get_rest(template_url, true)
-
- context = @new_resource.variables
- context[:node] = @node
- template_file = render_template(::File.read(raw_template_file.path), context)
-
- update = false
-
- if ::File.exists?(@new_resource.path)
- @new_resource.checksum(self.checksum(template_file.path))
- if @new_resource.checksum != @current_resource.checksum
- Chef::Log.debug("#{@new_resource} changed from #{@current_resource.checksum} to #{@new_resource.checksum}")
- Chef::Log.info("Updating #{@new_resource} at #{@new_resource.path}")
- update = true
- end
- else
- Chef::Log.info("Creating #{@new_resource} at #{@new_resource.path}")
- update = true
- end
-
- if update
- backup
- FileUtils.cp(template_file.path, @new_resource.path)
- @new_resource.updated = true
- else
- Chef::Log.debug("#{@new_resource} is unchanged")
- end
-
- set_owner if @new_resource.owner != nil
- set_group if @new_resource.group != nil
- set_mode if @new_resource.mode != nil
- end
-
- end
- end
-end \ No newline at end of file
diff --git a/lib/chef/provider/user.rb b/lib/chef/provider/user.rb
deleted file mode 100644
index a3de68d93c..0000000000
--- a/lib/chef/provider/user.rb
+++ /dev/null
@@ -1,172 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@hjksolutions.com>)
-# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require File.join(File.dirname(__FILE__), "..", "provider")
-require File.join(File.dirname(__FILE__), "..", "mixin", "command")
-require 'etc'
-
-class Chef
- class Provider
- class User < Chef::Provider
-
- include Chef::Mixin::Command
-
- def initialize(node, new_resource)
- super(node, new_resource)
- @user_exists = true
- @locked = nil
- end
-
- def load_current_resource
- @current_resource = Chef::Resource::User.new(@new_resource.name)
- @current_resource.username(@new_resource.username)
-
- user_info = nil
- begin
- user_info = Etc.getpwnam(@new_resource.username)
- rescue ArgumentError => e
- @user_exists = false
- Chef::Log.debug("User #{@new_resource.username} does not exist")
- end
-
- if user_info
- @current_resource.uid(user_info.uid)
- @current_resource.gid(user_info.gid)
- @current_resource.comment(user_info.gecos)
- @current_resource.home(user_info.dir)
- @current_resource.shell(user_info.shell)
-
- if @new_resource.password
- begin
- require 'shadow'
- rescue Exception => e
- Chef::Log.error("You must have ruby-shadow installed for password support!")
- raise Chef::Exception::MissingLibrary, "You must have ruby-shadow installed for password support!"
- end
- shadow_info = Shadow::Passwd.getspnam(@new_resource.username)
- @current_resource.password(shadow_info.sp_pwdp)
- end
- end
-
- @current_resource
- end
-
- def compare_user
- change_required = false
- change_required = true if @new_resource.uid != @current_resource.uid
- change_required = true if @new_resource.gid != @current_resource.gid
- change_required = true if @new_resource.comment != @current_resource.comment
- change_required = true if @new_resource.home != @current_resource.home
- change_required = true if @new_resource.shell != @current_resource.shell
- change_required = true if @new_resource.password != @current_resource.password
- change_required
- end
-
- def action_create
- case @user_exists
- when false
- create_user
- Chef::Log.info("Created #{@new_resource}")
- @new_resource.updated = true
- else
- if compare_user
- manage_user
- Chef::Log.info("Altered #{@new_resource}")
- @new_resource.updated = true
- end
- end
- end
-
- def action_remove
- if @user_exists
- remove_user
- @new_resource.updated = true
- Chef::Log.info("Removed #{@new_resource}")
- end
- end
-
- def action_manage
- if @user_exists && compare_user
- manage_user
- @new_resource.updated = true
- Chef::Log.info("Managed #{@new_resource}")
- end
- end
-
- def action_modify
- if @user_exists && compare_user
- manage_user
- @new_resource.updated = true
- Chef::Log.info("Modified #{@new_resource}")
- else
- raise Chef::Exception::User, "Cannot modify #{@new_resource} - user does not exist!"
- end
- end
-
- def check_lock
- status = popen4("passwd -S #{@new_resource.username}") do |pid, stdin, stdout, stderr|
- stdin.close
- status_line = stdout.gets.split(' ')
- case status_line[1]
- when /^P/
- @locked = false
- when /^N/
- @locked = false
- when /^L/
- @locked = true
- end
- end
-
- unless status.exitstatus == 0
- raise Chef::Exception::User, "Cannot determine if #{@new_resource} is locked!"
- end
-
- @locked
- end
-
- def action_lock
- if @user_exists
- if check_lock() == false
- lock_user
- @new_resource.updated = true
- Chef::Log.info("Locked #{@new_resource}")
- else
- Chef::Log.debug("No need to lock #{@new_resource}")
- end
- else
- raise Chef::Exception::User, "Cannot lock #{@new_resource} - user does not exist!"
- end
- end
-
- def action_unlock
- if @user_exists
- if check_lock() == true
- unlock_user
- @new_resource.updated = true
- Chef::Log.info("Unlocked #{@new_resource}")
- else
- Chef::Log.debug("No need to unlock #{@new_resource}")
- end
- else
- raise Chef::Exception::User, "Cannot unlock #{@new_resource} - user does not exist!"
- end
- end
-
- end
- end
-end
diff --git a/lib/chef/provider/user/useradd.rb b/lib/chef/provider/user/useradd.rb
deleted file mode 100644
index 96736a27a8..0000000000
--- a/lib/chef/provider/user/useradd.rb
+++ /dev/null
@@ -1,88 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@hjksolutions.com>)
-# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require File.join(File.dirname(__FILE__), "..", "user")
-
-class Chef
- class Provider
- class User
- class Useradd < Chef::Provider::User
- def create_user
- command = "useradd"
- command << set_options
- run_command(:command => command)
- end
-
- def manage_user
- command = "usermod"
- command << set_options
- run_command(:command => command)
- end
-
- def remove_user
- command = "userdel"
- command << " -r" if @new_resource.supports[:manage_home]
- command << " #{@new_resource.username}"
- run_command(:command => command)
- end
-
- def lock_user
- run_command(:command => "usermod -L #{@new_resource.username}")
- end
-
- def unlock_user
- run_command(:command => "usermod -U #{@new_resource.username}")
- end
-
- def set_options
- opts = ''
-
- field_list = {
- 'comment' => "-c",
- 'home' => "-d",
- 'gid' => "-g",
- 'uid' => "-u",
- 'shell' => "-s",
- 'password' => "-p"
- }
- field_list.each do |field, option|
- field_symbol = field.to_sym
- if @current_resource.send(field_symbol) != @new_resource.send(field_symbol)
- if @new_resource.send(field_symbol)
- Chef::Log.debug("Setting #{@new_resource} #{field} to #{@new_resource.send(field_symbol)}")
- opts << " #{option} '#{@new_resource.send(field_symbol)}'"
- end
- end
- end
- if @new_resource.supports[:manage_home]
- Chef::Log.debug("Managing the home directory for #{@new_resource}")
- case @node[:operatingsystem]
- when "Fedora","RedHat","CentOS"
- opts << " -M"
- else
- opts << " -m"
- end
- end
- opts << " #{@new_resource.username}"
- opts
- end
-
- end
- end
- end
-end \ No newline at end of file