class FPM::Package::OSXpkg
Use an OS X pkg built with pkgbuild.
Supports input and output. Requires pkgbuild and (for input) pkgutil, part of a standard OS X install in 10.7 and higher.
Constants
- OWNERSHIP_OPTIONS
- POSTINSTALL_ACTIONS
- SCRIPT_MAP
Map of what scripts are named.
Public Instance Methods
identifier()
click to toggle source
return the identifier by prepending the reverse-domain prefix to the package name, else return just the name
# File lib/fpm/package/osxpkg.rb, line 60 def identifier identifier = name.dup if self.attributes[:osxpkg_identifier_prefix] identifier.insert(0, "#{self.attributes[:osxpkg_identifier_prefix]}.") end identifier end
input(input_path)
click to toggle source
Take a flat package as input
# File lib/fpm/package/osxpkg.rb, line 118 def input(input_path) # TODO: Fail if it's a Distribution pkg or old-fashioned expand_dir = File.join(build_path, "expand") # expand_dir must not already exist for pkgutil --expand safesystem("pkgutil --expand #{input_path} #{expand_dir}") extract_info(input_path) # extract Payload safesystem("tar -xz -f #{expand_dir}/Payload -C #{staging_path}") end
output(output_path)
click to toggle source
Output a pkgbuild pkg.
# File lib/fpm/package/osxpkg.rb, line 131 def output(output_path) output_check(output_path) temp_info = pkginfo_template_path args = ["--identifier", identifier, "--info", temp_info, "--version", version.to_s, "--ownership", attributes[:osxpkg_ownership]] if self.attributes[:osxpkg_payload_free?] args << "--nopayload" else args += ["--root", staging_path] end if attributes[:before_install_given?] or attributes[:after_install_given?] write_scripts args += ["--scripts", scripts_path] end args << output_path safesystem("pkgbuild", *args) FileUtils.remove_file(temp_info) end
to_s(format=nil)
click to toggle source
Calls superclass method
FPM::Package#to_s
# File lib/fpm/package/osxpkg.rb, line 157 def to_s(format=nil) return super("NAME-VERSION.pkg") if format.nil? return super(format) end
Private Instance Methods
extract_info(package)
click to toggle source
Extract name and version from PackageInfo XML
# File lib/fpm/package/osxpkg.rb, line 105 def extract_info(package) build_path("expand").tap do |path| doc = REXML::Document.new File.open(File.join(path, "PackageInfo")) pkginfo_elem = doc.elements["pkg-info"] identifier = pkginfo_elem.attribute("identifier").value self.version = pkginfo_elem.attribute("version").value # set name to the last dot element of the identifier self.name = identifier.split(".").last logger.info("inferring name #{self.name} from pkg-id #{identifier}") end end
pkginfo_template_path()
click to toggle source
Returns path of a processed template PackageInfo given to 'pkgbuild –info' note: '–info' is undocumented: managingosx.wordpress.com/2012/07/05/stupid-tricks-with-pkgbuild
# File lib/fpm/package/osxpkg.rb, line 96 def pkginfo_template_path pkginfo_template = Tempfile.open("fpm-PackageInfo") pkginfo_data = template("osxpkg.erb").result(binding) pkginfo_template.write(pkginfo_data) pkginfo_template.close pkginfo_template.path end
scripts_path(path=nil)
click to toggle source
scripts_path
and write_scripts
cribbed from deb.rb
# File lib/fpm/package/osxpkg.rb, line 69 def scripts_path(path=nil) @scripts_path ||= build_path("Scripts") FileUtils.mkdir(@scripts_path) if !File.directory?(@scripts_path) if path.nil? return @scripts_path else return File.join(@scripts_path, path) end end
write_scripts()
click to toggle source
# File lib/fpm/package/osxpkg.rb, line 80 def write_scripts SCRIPT_MAP.each do |scriptname, filename| next unless script?(scriptname) scripts_path(filename).tap do |pkgscript| logger.info("Writing pkg script", :source => filename, :target => pkgscript) File.write(pkgscript, script(scriptname)) # scripts are required to be executable File.chmod(0755, pkgscript) end end end