Skip to content

Instantly share code, notes, and snippets.

@williamsjj
Created July 22, 2011 02:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save williamsjj/1098782 to your computer and use it in GitHub Desktop.
Save williamsjj/1098782 to your computer and use it in GitHub Desktop.
#
# Author:: Jason J. W. Williams (<williamsjj@digitar.com>)
# Copyright:: Copyright (c) 2011 Opscode, Inc.
# 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 'chef/provider/package'
require 'chef/mixin/command'
require 'chef/resource/package'
class Chef
class Provider
class Package
class Ips < Chef::Provider::Package
include Chef::Mixin::ShellOut
attr_accessor :virtual
def load_current_resource
@current_resource = Chef::Resource::Package.new(@new_resource.name)
@current_resource.package_name(@new_resource.package_name)
check_package_state(@new_resource.package_name)
@current_resource
end
def check_package_state(package)
Chef::Log.debug("Checking package status for #{package}")
installed = false
depends = false
shell_out!("pkg info -r #{package}").stdout.each_line do |line|
case line
when /^\s+State: Installed/
installed = true
when /^\s+Version: (.*)/
@candidate_version = $1
if installed
@current_resource.version($1)
else
@current_resource.version(nil)
end
end
if @candidate_version.nil?
raise Chef::Exceptions::Package, "pkg does not have a version of package #{@new_resource.package_name}"
end
return installed
end
def install_package(name, version)
package_name = "#{name}@#{version}"
run_command_with_systems_locale(
:command => "pkg -q --accept #{expand_options(@new_resource.options)} install #{package_name}",
)
end
def upgrade_package(name, version)
install_package(name, version)
end
def remove_package(name, version)
package_name = "#{name}@#{version}"
run_command_with_systems_locale(
:command => "pkg -q #{expand_options(@new_resource.options)} uninstall #{package_name}",
)
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment