public static Pack CreateHyperVIso(MachineConfig m, string builderName, string vmName) { var pack = new Pack { builders = { new Builder { type = builderName, iso_url = "{{ user `iso_url` }}", iso_checksum = "{{ user `iso_checksum` }}", iso_checksum_type = "sha1", disk_size = 50 * 1024, enable_dynamic_memory = true, floppy_files = new string[0], guest_additions_mode = "{{ user `guest_additions_mode` }}", guest_additions_path = "C:/Windows/System32/vmguest.iso", ram_size = 2 * 1024, shutdown_command = "C:/windows/system32/sysprep/sysprep.exe /generalize /oobe /unattend:C:/Windows/Panther/Unattend/unattend.xml /quiet /shutdown", shutdown_timeout = "15m", communicator = "winrm", winrm_username = "******", winrm_password = "******", winrm_port = 5985, winrm_timeout = "24h", } }, /* provisioners = { * new Provisioner { * type = "powershell", * script = "scripts/provision.ps1" * } * }, */ post_processors = { new PostProcessor { type = "vagrant", keep_input_artifact = true, output = "windows7-{{.Provider}}.box", vagrantfile_template = "vagrantfile-windows.template" } }, variables = new Variables { guest_additions_mode = "attach" } }; var builder = pack.builders.First(); if (!string.IsNullOrWhiteSpace(vmName)) { builder.vm_name = vmName; } builder.vboxmanage = null; return(pack); }
public static Pack CreateVirtualBoxIso(MachineConfig m, string builderName, string vmName) { var pack = new Pack { builders = { new Builder { type = builderName, vboxmanage = { new [] { "modifyvm", "{{.Name}}", "--memory", m.Memory + "" }, new [] { "modifyvm", "{{.Name}}", "--vram", m.Vram + "" }, new [] { "modifyvm", "{{.Name}}", "--cpus", m.Cpus + "" } }, guest_additions_mode = "{{ user `guest_additions_mode` }}", guest_additions_path = "C:/users/vagrant/VBoxGuestAdditions.iso", guest_os_type = PatchOSIfNeeded(m.OperatingSystem), iso_url = "{{ user `iso_url` }}", iso_checksum = "{{ user `iso_checksum` }}", iso_checksum_type = "sha1", communicator = "winrm", headless = "{{ user `headless` }}", winrm_username = "******", winrm_password = "******", winrm_port = 5985, winrm_timeout = "24h", shutdown_command = "C:/windows/system32/sysprep/sysprep.exe /generalize /oobe /unattend:C:/Windows/Panther/Unattend/unattend.xml /quiet /shutdown", shutdown_timeout = "15m", floppy_files = new string[0] } }, /* provisioners = { * new Provisioner { * type = "powershell", * script = "scripts/provision.ps1" * } * }, */ post_processors = { new PostProcessor { type = "vagrant", keep_input_artifact = true, output = "windows7-{{.Provider}}.box", vagrantfile_template = "vagrantfile-windows.template" } }, variables = new Variables { guest_additions_mode = "attach", headless = "false" } }; var builder = pack.builders.First(); if (!string.IsNullOrWhiteSpace(vmName)) { builder.vm_name = vmName; } foreach (var forward in m.Forwardings) { builder.vboxmanage.Insert(0, new[] { "modifyvm", "{{.Name}}", "--natpf1", forward.ToString() }); } return(pack); }
public static void Main(string[] args) { BasicConfigurator.Configure(); var config = Configs.BuildConfig(ref args); var root = Path.GetFullPath(config["root"] ?? Environment.CurrentDirectory); log.InfoFormat("Root folder => {0}", root); var packerExe = Path.Combine(root, "packer.exe"); log.InfoFormat("Looking for => {0}", packerExe); if (!File.Exists(packerExe)) { Shell.DownloadPacker(root, config); } var assPlace = Assembly.GetEntryAssembly().Location; var appRoot = Directory.GetParent(Path.GetFullPath(assPlace)).FullName; var templRoot = Path.Combine(appRoot, "templates"); log.InfoFormat("Template root => {0}", templRoot); var machine = new MachineConfig(); GuestOS machineGuest; if (!Enum.TryParse(config["guest"], true, out machineGuest)) { var help = string.Join(" | ", Enum.GetNames(typeof(GuestOS))); log.ErrorFormat("Not valid guest type! ( {0} )", help); return; } machine.OperatingSystem = machineGuest; var machRoot = Path.Combine(templRoot, machine.OperatingSystem + ""); var answerSrc = Path.Combine(machRoot, "unattend.xml"); var answerDst = Path.Combine(root, "Autounattend.xml"); var builder = config["builder"]; var name = config["name"]; var packMeths = typeof(Defaults).GetMethods(); var packMeth = packMeths.FirstOrDefault(m => m.Name.EndsWith(builder.Replace("-", ""), StringComparison.InvariantCultureIgnoreCase)); if (packMeth == null) { throw new InvalidOperationException($"No pack definition for '{builder}' found!"); } var pack = (Pack)packMeth.Invoke(null, new object[] { machine, builder, name }); Answers.CopyReplace(templRoot, answerSrc, answerDst, config); pack.builders.First().AddFloppyFile(answerDst); foreach (var afile in Reflections.GetAssemblyFiles <BootProgram>()) { pack.builders.First().AddFloppyFile(afile); } const string vagrantFile = "vagrantfile-windows.template"; var vagrantSrc = Path.Combine(templRoot, vagrantFile); var vagrantDst = Path.Combine(root, vagrantFile); File.Copy(vagrantSrc, vagrantDst, overwrite: true); var isoStore = Path.GetFullPath(config["isoStore"]); var machIsoStore = Path.Combine(isoStore, machine.OperatingSystem + ""); log.InfoFormat("ISO store => {0}", machIsoStore); var machIso = Shell.FindNewestFile(machIsoStore, "*.iso"); if (string.IsNullOrWhiteSpace(machIso)) { log.ErrorFormat("No ISO found!"); return; } pack.variables.iso_url = machIso.Replace('\\', '/'); pack.variables.iso_checksum = Shell.GetOrCreateHash(machIso); var packFile = Path.Combine(root, "winbox.json"); log.InfoFormat("Generating => {0}", packFile); File.WriteAllText(packFile, pack.ToString()); Shell.ExecutePacker(root, packerExe, packFile, config); log.InfoFormat("Have a nice day!"); Environment.Exit(0); }