Skip to content

Instantly share code, notes, and snippets.

@btm

btm/inno.rb Secret

Created January 28, 2014 17:56
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 btm/92a40020c3eea6cb8b28 to your computer and use it in GitHub Desktop.
Save btm/92a40020c3eea6cb8b28 to your computer and use it in GitHub Desktop.
Windows package provider: We can't determine the installer type on windows until after the installer is on disk and we can example the file, so we do so in the provider.
# provider/package/windows/inno.rb
class Chef
class Provider
class Package
class Windows
class Inno
def install_package
end
def upgrade_pacakge
end
def remove_package
end
end
end
end
end
end
# provider/package/windows/msi.rb
class Chef
class Provider
class Package
class Windows
class MSI
def install_package
end
def upgrade_pacakge
end
def remove_package
end
end
end
end
end
end
# provider/package/windows.rb
class Chef
class Provider
class Package
class Windows
require 'chef/resource/package'
require 'chef/provider/package'
require 'chef/provider/package/windows/msi'
require 'chef/provider/package/windows/inno'
def load_current_resource
@current_resource = Chef::Resource::Package.new(@new_resource.name)
@provider_class = case installer_type
when :msi
Chef::Provider::Package::Windows::MSI.new
when :inno
Chef::Provider::Package::Windows::Inno.new
end
end
def installer_type
@installer_type || begin
if @new_resource.installer_type
@new_resource.installer_type
else
basename = ::File.basename(cached_file(@new_resource.source, @new_resource.checksum))
if basename.split(".").last.downcase == "msi" # Microsoft MSI
:msi
else
# search the binary file for installer type
contents = ::Kernel.open(::File.expand_path(cached_file(@new_resource.source)), "rb") {|io| io.read } # TODO limit data read in
case contents
when /inno/i # Inno Setup
:inno
when /wise/i # Wise InstallMaster
:wise
when /nsis/i # Nullsoft Scriptable Install System
:nsis
else
# if file is named 'setup.exe' assume installshield
if basename == "setup.exe"
:installshield
else
raise Chef::Exceptions::AttributeNotFound, "installer_type could not be determined, please set manually"
end
end
end
end
end
def candidate_version
end
def install_package
@provider_class.install_package
end
def upgrade_package
@provider_class.upgrade_package
end
def remove_package
@provider_class.remove_package
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment