Class: Macinbox::Actions::CreateHDDFromImage
- Inherits:
-
Object
- Object
- Macinbox::Actions::CreateHDDFromImage
- Defined in:
- lib/macinbox/actions/create_hdd_from_image.rb
Instance Method Summary collapse
- #attach_image ⇒ Object
- #convert_image ⇒ Object
- #copy_input_image ⇒ Object
- #create_temp_dir ⇒ Object
- #eject_and_reattach_image ⇒ Object
-
#initialize(opts) ⇒ CreateHDDFromImage
constructor
A new instance of CreateHDDFromImage.
- #install_parallels_tools ⇒ Object
- #run ⇒ Object
- #save_image ⇒ Object
Constructor Details
#initialize(opts) ⇒ CreateHDDFromImage
Returns a new instance of CreateHDDFromImage.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/macinbox/actions/create_hdd_from_image.rb', line 17 def initialize(opts) @input_image = opts[:image_path] or raise ArgumentError.new(":image_path not specified") @output_path = opts[:hdd_path] or raise ArgumentError.new(":hdd_path not specified") @parallels_app = opts[:parallels_path] or raise ArgumentError.new(":parallels_path not specified") @collector = opts[:collector] or raise ArgumentError.new(":collector not specified") raise Macinbox::Error.new("input image not found") unless File.exist? @input_image raise Macinbox::Error.new("Parallels Desktop not found") unless File.exist? @parallels_app end |
Instance Method Details
#attach_image ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/macinbox/actions/create_hdd_from_image.rb', line 50 def attach_image Logger.info "Attaching the image..." do @disk = VirtualDisk.new(@image) @collector.on_cleanup { @disk.detach! } @image_mountpoint = "#{@temp_dir}/image_mountpoint" FileUtils.mkdir @image_mountpoint @disk.attach @disk.mount(at: @image_mountpoint, owners: true) end end |
#convert_image ⇒ Object
126 127 128 129 130 131 132 133 134 |
# File 'lib/macinbox/actions/create_hdd_from_image.rb', line 126 def convert_image Logger.info "Converting the image to HDD format..." do VMDK.create_raw_vmdk(@disk.device, "#{@temp_dir}/macinbox.vmdk") prl_convert = "#{@parallels_app}/Contents/MacOS/prl_convert" task_opts = $verbose ? {} : { :out => File::NULL } Task.run %W[ #{prl_convert} #{@temp_dir}/macinbox.vmdk --allow-no-os --dst=#{@temp_dir} ] + [task_opts] @disk.eject end end |
#copy_input_image ⇒ Object
43 44 45 46 47 48 |
# File 'lib/macinbox/actions/create_hdd_from_image.rb', line 43 def copy_input_image Logger.info "Copying the image..." do @image = "#{@temp_dir}/macinbox.sparseimage" Macinbox::copyfiles(from: @input_image, to: @image) end end |
#create_temp_dir ⇒ Object
38 39 40 41 |
# File 'lib/macinbox/actions/create_hdd_from_image.rb', line 38 def create_temp_dir @temp_dir = Task.backtick %W[ /usr/bin/mktemp -d -t create_hdd_from_image ] @collector.add_temp_dir @temp_dir end |
#eject_and_reattach_image ⇒ Object
119 120 121 122 123 124 |
# File 'lib/macinbox/actions/create_hdd_from_image.rb', line 119 def eject_and_reattach_image Logger.info "Reattaching the image..." do @disk.eject @disk.attach end end |
#install_parallels_tools ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/macinbox/actions/create_hdd_from_image.rb', line 61 def install_parallels_tools Logger.info "Installing the Parallels Tools..." do tools_image = "#{@parallels_app}/Contents/Resources/Tools/prl-tools-mac.iso" tools_disk = VirtualDisk.new(tools_image) @collector.on_cleanup { tools_disk.detach! } tools_mountpoint = "#{@temp_dir}/tools_mountpoint" FileUtils.mkdir tools_mountpoint tools_disk.attach tools_disk.mount(at: tools_mountpoint) tools_packages_dir = "#{tools_mountpoint}/Install.app/Contents/Resources/Install.mpkg/Contents/Packages" tools_packages = [ "Parallels Tools Audio 10.9.pkg", "Parallels Tools Coherence.pkg", "Parallels Tools CopyPaste.pkg", "Parallels Tools DragDrop.pkg", "Parallels Tools HostTime.pkg", "Parallels Tools InstallationAgent.pkg", "Parallels Tools Network 10.9.pkg", "Parallels Tools SharedFolders.pkg", "Parallels Tools TimeSync.pkg", "Parallels Tools ToolGate 10.9.pkg", "Parallels Tools Utilities.pkg", "Parallels Tools Video 10.9.pkg" ] = "#{@temp_dir}/tools_packages" FileUtils.mkdir tools_packages.each do |package| if File.exist? "#{tools_packages_dir}/#{package}" Task.run %W[ /usr/sbin/pkgutil --expand #{tools_packages_dir}/#{package} #{}/#{package} ] Task.run %W[ /usr/bin/ditto -x -z #{}/#{package}/Payload #{@image_mountpoint} ] end end prl_nettool_source = "/Library/Parallels Guest Tools/prl_nettool" prl_nettool_target = "#{@image_mountpoint}/usr/local/bin/prl_nettool" FileUtils.mkdir_p File.dirname(prl_nettool_target) FileUtils.ln_s prl_nettool_source, prl_nettool_target prl_fsd_plist = "#{@image_mountpoint}/Library/LaunchDaemons/com.parallels.vm.prl_fsd.plist" Task.run %W[ /usr/bin/sed -i #{''} s/PARALLELS_ADDITIONAL_ARGS/--share/ #{prl_fsd_plist} ] contents = "/Library/Parallels\ Guest\ Tools/dynres --enable-retina\n" File.write "#{@image_mountpoint}/private/etc/rc.vagrant", contents, mode: 'a' tools_disk.eject end def eject_and_reattach_image Logger.info "Reattaching the image..." do @disk.eject @disk.attach end end def convert_image Logger.info "Converting the image to HDD format..." do VMDK.create_raw_vmdk(@disk.device, "#{@temp_dir}/macinbox.vmdk") prl_convert = "#{@parallels_app}/Contents/MacOS/prl_convert" task_opts = $verbose ? {} : { :out => File::NULL } Task.run %W[ #{prl_convert} #{@temp_dir}/macinbox.vmdk --allow-no-os --dst=#{@temp_dir} ] + [task_opts] @disk.eject end end def save_image Logger.info "Moving the HDD to the destination..." do FileUtils.chown_R ENV["SUDO_USER"], nil, "#{@temp_dir}/macinbox.hdd" FileUtils.mv "#{@temp_dir}/macinbox.hdd", @output_path end end end |
#run ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/macinbox/actions/create_hdd_from_image.rb', line 28 def run create_temp_dir copy_input_image attach_image install_parallels_tools eject_and_reattach_image convert_image save_image end |
#save_image ⇒ Object
136 137 138 139 140 141 |
# File 'lib/macinbox/actions/create_hdd_from_image.rb', line 136 def save_image Logger.info "Moving the HDD to the destination..." do FileUtils.chown_R ENV["SUDO_USER"], nil, "#{@temp_dir}/macinbox.hdd" FileUtils.mv "#{@temp_dir}/macinbox.hdd", @output_path end end |