module PKGUtil

/usr/sbin/pkgutil

developer.apple.com/library/mac/documentation/Darwin/Reference/Manpages/man1/pkgutil.1.html

Public Class Methods

read(input) { |tmp| ... } click to toggle source

Perform read-only actions on the input package.

If a block is given the block will be yielded with the path of the package expanded directory, otherwise a shell will be open.

input - The String path to the input package.

# File lib/iesd/utility/pkgutil.rb, line 14
def self.read input
  Dir.mktmpdir { |tmp|
    tmp = File.join tmp, File.basename(input)
    expand input, tmp
    if block_given?
      yield tmp
    else
      shell tmp
    end
  }
end
write(input, output = input) { |tmp| ... } click to toggle source

Perform read-write actions on the input package and export as the output package.

If a block is given the block will be yielded with the path of the package expanded directory, otherwise a shell will be open.

input - The String path to the input package. output - The String path to the output package.

# File lib/iesd/utility/pkgutil.rb, line 32
def self.write input, output = input
  Dir.mktmpdir { |tmp|
    tmp = File.join tmp, File.basename(input)
    expand input, tmp
    if block_given?
      yield tmp
    else
      shell tmp
    end
    flatten tmp, output
  }
end

Private Class Methods

expand(pkg, dir) click to toggle source

Expand a PKG.

pkg - The String path to the PKG. dir - The String path to the expand directory.

# File lib/iesd/utility/pkgutil.rb, line 51
def self.expand pkg, dir
  ohai "Expanding #{pkg}"
  system("/usr/bin/env", "pkgutil", "--expand", pkg, dir)
  puts "Expanded: #{dir}"
end
flatten(dir, pkg) click to toggle source

Flatten a PKG.

dir - The String path to the flatten directory. pkg - The String path to the PKG.

# File lib/iesd/utility/pkgutil.rb, line 61
def self.flatten dir, pkg
  ohai "Flattening #{dir}"
  system("/usr/bin/env", "pkgutil", "--flatten", dir, pkg)
  puts "Flattened: #{pkg}"
end
shell(dir) click to toggle source

Open a shell in the directory.

dir - The String path to the directory.

# File lib/iesd/utility/pkgutil.rb, line 70
def self.shell dir
  Dir.chdir(dir) {
    ohai ENV['SHELL']
    Kernel.system ENV, ENV['SHELL']
  }
end