Class: Macinbox::Actions::CreateBoxFromHDD
- Inherits:
-
Object
- Object
- Macinbox::Actions::CreateBoxFromHDD
- Defined in:
- lib/macinbox/actions/create_box_from_hdd.rb
Instance Method Summary collapse
-
#initialize(opts) ⇒ CreateBoxFromHDD
constructor
A new instance of CreateBoxFromHDD.
- #run ⇒ Object
Constructor Details
#initialize(opts) ⇒ CreateBoxFromHDD
Returns a new instance of CreateBoxFromHDD.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/macinbox/actions/create_box_from_hdd.rb', line 14 def initialize(opts) @input_hdd = opts[:hdd_path] or raise ArgumentError.new(":hdd_path not specified") @output_path = opts[:box_path] or raise ArgumentError.new(":box_path not specified") @box_name = opts[:box_name] or raise ArgumentError.new(":box_name not specified") @cpu_count = opts[:cpu_count] or raise ArgumentError.new(":cpu_count not specified") @memory_size = opts[:memory_size] or raise ArgumentError.new(":memory_size not specified") @gui = opts[:gui] @fullscreen = opts[:fullscreen] @hidpi = opts[:hidpi] @collector = opts[:collector] or raise ArgumentError.new(":collector not specified") @debug = opts[:debug] raise Macinbox::Error.new("HDD not found") unless File.exist? @input_hdd end |
Instance Method Details
#run ⇒ Object
32 33 34 35 36 37 38 39 40 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 71 72 73 74 75 76 77 78 79 |
# File 'lib/macinbox/actions/create_box_from_hdd.rb', line 32 def run @temp_dir = Task.backtick %W[ /usr/bin/mktemp -d -t create_box_from_hdd ] @collector.add_temp_dir @temp_dir Logger.info "Assembling the box contents..." do @box_dir = "#{@temp_dir}/#{@box_name}.box" FileUtils.mkdir @box_dir File.write "#{@box_dir}/metadata.json", " {\"provider\": \"parallels\"}\n EOF\n\n File.write \"\#{@box_dir}/Vagrantfile\", <<~EOF\n Vagrant.configure(2) do |config|\n config.vm.box_check_update = false\n config.vm.network :forwarded_port, guest: 22, host: 2222, id: \"ssh\", disabled: true\n config.vm.synced_folder \".\", \"/vagrant\", disabled: true\n config.vm.provider \"parallels\" do |prl|\n prl.customize [\"set\", :id, \"--startup-view\", \"\#{@gui ? (@fullscreen ? \"fullscreen\" : \"window\") : \"headless\"}\"]\n end\n end\n EOF\n\n task_opts = @debug ? {} : { :out => File::NULL }\n\n Task.run %W[ prlctl create macinbox -o macos --no-hdd --dst \#{@box_dir} ] + [task_opts]\n\n @collector.on_cleanup do\n Task.run %W[ prlctl unregister macinbox ] + [task_opts]\n end\n\n Task.run %W[ /bin/cp -r \#{@input_hdd} \#{@box_dir}/macinbox.pvm/macinbox.hdd ] + [task_opts]\n Task.run %W[ prl_disk_tool convert --merge --hdd \#{@box_dir}/macinbox.pvm/macinbox.hdd ] + [task_opts]\n Task.run %W[ prlctl set macinbox --device-add hdd --image \#{@box_dir}/macinbox.pvm/macinbox.hdd ] + [task_opts]\n Task.run %W[ prlctl set macinbox --high-resolution \#{@hidpi ? \"on\" : \"off\"} ] + [task_opts]\n Task.run %W[ prlctl set macinbox --cpus \#{@cpu_count} ] + [task_opts]\n Task.run %W[ prlctl set macinbox --memsize \#{@memory_size} ] + [task_opts]\n\n end\n\n Logger.info \"Moving the box to the destination...\" do\n FileUtils.chown ENV[\"SUDO_USER\"], nil, @box_dir\n FileUtils.mv @box_dir, @output_path\n end\n\nend\n" |