Module: HDIUtil
- Defined in:
- lib/iesd/utility/hdiutil.rb,
lib/iesd/utility/hdiutil.rb
Overview
:nodoc:
Defined Under Namespace
Classes: DMG
Constant Summary collapse
- DEFAULT_OPTIONS =
The default options for
hdiutil
. %w[ -quiet ]
- DEFAULT_MOUNT_OPTIONS =
The default options for
hdiutil attach
. %w[ -nobrowse -noverify ]
Class Method Summary collapse
-
.read(input) ⇒ Object
Perform read-only actions on the input image.
-
.validate(url) ⇒ Object
Returns true if the image is valid, false otherwise.
-
.write(input, output, options = {}) ⇒ Object
Perform read-write actions on the input image and export as the output image.
Class Method Details
.read(input) ⇒ Object
Perform read-only actions on the input image.
If a block is given the block will be yielded with the path of the mount point directory, otherwise a shell will be open.
input - The String path to the input image.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/iesd/utility/hdiutil.rb', line 22 def self.read input Dir.mktmpdir { |mountpoint| attach input, mountpoint, [*DEFAULT_OPTIONS, *DEFAULT_MOUNT_OPTIONS] if block_given? yield mountpoint else shell mountpoint end detach input, mountpoint, [*DEFAULT_OPTIONS] } end |
.validate(url) ⇒ Object
Returns true if the image is valid, false otherwise.
url - The String path to the image.
75 76 77 |
# File 'lib/iesd/utility/hdiutil.rb', line 75 def self.validate url Kernel.system(%Q[/usr/bin/env hdiutil imageinfo #{url.shellescape} >/dev/null 2>&1]) end |
.write(input, output, options = {}) ⇒ Object
Perform read-write actions on the input image and export as the output image.
If a block is given the block will be yielded with the path of the mount point directory, otherwise a shell will be open.
input - The String path to the input image. output - The String path to the output image. options - The Dictionary of hdiutil options.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/iesd/utility/hdiutil.rb', line 41 def self.write input, output, = {} = { :resize => { :grow => 0, :shrink => false } }.merge() Dir.mktmpdir { |tmp| shadow = File.join(tmp, "#{File.basename input}.shadow") = ["-shadow", shadow] = ["-format", `/usr/bin/env hdiutil imageinfo -format #{input.shellescape}`.chomp] Dir.mktmpdir(nil, tmp) { |mountpoint| resize_limits = `/usr/bin/env hdiutil resize -limits -shadow #{shadow.shellescape} #{input.shellescape}`.chomp.split.map { |s| s.to_i } sectors = (resize_limits[1] + [:resize][:grow]).to_s system("/usr/bin/env", "hdiutil", "resize", "-growonly", "-sectors", sectors, *, input) attach input, mountpoint, [*DEFAULT_OPTIONS, *DEFAULT_MOUNT_OPTIONS, *] if block_given? yield mountpoint else shell mountpoint end detach input, mountpoint, [*DEFAULT_OPTIONS] system("/usr/bin/env", "hdiutil", "resize", "-shrinkonly", "-sectors", "min", *, input) if [:resize][:shrink] } oh1 "Merging #{shadow}" system("/usr/bin/env", "hdiutil", "convert", *DEFAULT_OPTIONS, *, *, "-o", output, input) puts "Merged: #{output}" } end |