From 4e37814019facfe2378134fab52cea2b28a97e75 Mon Sep 17 00:00:00 2001 From: "Julian C. Dunn" Date: Mon, 11 May 2015 12:43:01 -0400 Subject: [PATCH] Add Mac OS X 10.10 template. --- macosx-10.10.json | 214 ++++++++++++++++++++++++++++++++ scripts/macosx/minimize.sh | 16 +++ scripts/macosx/networking.sh | 31 +++++ scripts/macosx/vmtools.sh | 35 ++++++ vagrantfile_templates/macosx.rb | 6 +- 5 files changed, 301 insertions(+), 1 deletion(-) create mode 100644 macosx-10.10.json create mode 100644 scripts/macosx/minimize.sh create mode 100644 scripts/macosx/networking.sh create mode 100644 scripts/macosx/vmtools.sh diff --git a/macosx-10.10.json b/macosx-10.10.json new file mode 100644 index 000000000..320f78e53 --- /dev/null +++ b/macosx-10.10.json @@ -0,0 +1,214 @@ +{ + "builders": [ + { + "boot_wait": "2s", + "disk_size": 20480, + "guest_os_type": "darwin12-64", + "iso_checksum": "{{user `iso_checksum`}}", + "iso_checksum_type": "md5", + "iso_url": "{{user `iso_url`}}", + "output_directory": "packer-macosx-10.10-vmware", + "shutdown_command": "echo 'vagrant'|sudo -S shutdown -h now", + "skip_compaction": true, + "ssh_password": "vagrant", + "ssh_port": 22, + "ssh_username": "vagrant", + "ssh_wait_timeout": "10000s", + "tools_upload_flavor": "darwin", + "tools_upload_path": "/tmp/vmtools.iso", + "type": "vmware-iso", + "vm_name": "packer-macosx-10.10-vmware", + "vmx_data": { + "cpuid.coresPerSocket": "1", + "ehci.present": "TRUE", + "firmware": "efi", + "hpet0.present": "TRUE", + "ich7m.present": "TRUE", + "keyboardAndMouseProfile": "macProfile", + "memsize": "2048", + "numvcpus": "1", + "smc.present": "TRUE", + "usb.present": "TRUE" + } + }, + { + "boot_wait": "2s", + "disk_size": 20480, + "guest_additions_mode": "disable", + "guest_os_type": "MacOS109_64", + "hard_drive_interface": "sata", + "iso_checksum": "{{user `iso_checksum`}}", + "iso_checksum_type": "md5", + "iso_url": "{{user `iso_url`}}", + "output_directory": "packer-macosx-10.10-virtualbox", + "shutdown_command": "echo 'vagrant'|sudo -S shutdown -h now", + "ssh_password": "vagrant", + "ssh_port": 22, + "ssh_username": "vagrant", + "ssh_wait_timeout": "10000s", + "type": "virtualbox-iso", + "vboxmanage": [ + [ + "modifyvm", + "{{.Name}}", + "--audiocontroller", + "hda" + ], + [ + "modifyvm", + "{{.Name}}", + "--boot1", + "dvd" + ], + [ + "modifyvm", + "{{.Name}}", + "--boot2", + "disk" + ], + [ + "modifyvm", + "{{.Name}}", + "--chipset", + "ich9" + ], + [ + "modifyvm", + "{{.Name}}", + "--cpus", + "1" + ], + [ + "modifyvm", + "{{.Name}}", + "--firmware", + "efi" + ], + [ + "modifyvm", + "{{.Name}}", + "--hpet", + "on" + ], + [ + "modifyvm", + "{{.Name}}", + "--keyboard", + "usb" + ], + [ + "modifyvm", + "{{.Name}}", + "--memory", + "2048" + ], + [ + "modifyvm", + "{{.Name}}", + "--mouse", + "usbtablet" + ], + [ + "modifyvm", + "{{.Name}}", + "--vram", + "9" + ], + [ + "storageattach", + "{{.Name}}", + "--storagectl", + "SATA Controller", + "--port", + "1", + "--type", + "dvddrive", + "--medium", + "{{user `iso_url`}}" + ] + ], + "vboxmanage_post": [ + [ + "storageattach", + "{{.Name}}", + "--storagectl", + "SATA Controller", + "--port", + "1", + "--type", + "dvddrive", + "--medium", + "none" + ], + [ + "storagectl", + "{{.Name}}", + "--name", + "IDE Controller", + "--remove" + ] + ], + "virtualbox_version_file": ".vbox_version", + "vm_name": "packer-macosx-10.10-virtualbox" + } + ], + "min_packer_version": "0.6.0", + "post-processors": [ + { + "output": "builds/{{user `box_basename`}}.{{.Provider}}.box", + "type": "vagrant", + "vagrantfile_template": "vagrantfile_templates/macosx.rb" + } + ], + "provisioners": [ + { + "destination": "/tmp/bento-metadata.json", + "source": "{{user `metadata`}}", + "type": "file" + }, + { + "destination": "/private/tmp/kcpassword", + "source": "scripts/macosx/support/kcpassword", + "type": "file" + }, + { + "execute_command": "echo 'vagrant'| {{.Vars}} sudo -E -S sh '{{.Path}}'", + "scripts": [ + "scripts/common/metadata.sh", + "scripts/macosx/hostname.sh", + "scripts/macosx/update.sh", + "scripts/macosx/networking.sh", + "scripts/macosx/vagrant.sh", + "scripts/macosx/vmtools.sh", + "scripts/macosx/cleanup.sh", + "scripts/macosx/minimize.sh" + ], + "type": "shell" + }, + { + "execute_command": "echo 'vagrant'| {{.Vars}} sudo -E -S sh '{{.Path}}'", + "inline": [ + "[ -z \"{{user `autologin_vagrant_user`}}\" ] && exit", + "echo \"Enabling automatic GUI login for the 'vagrant' user..\"", + "cp /private/tmp/kcpassword /private/etc/kcpassword", + "/usr/bin/defaults write /Library/Preferences/com.apple.loginwindow autoLoginUser vagrant" + ], + "type": "shell" + } + ], + "variables": { + "arch": "64", + "autologin_vagrant_user": "", + "box_basename": "macosx-10.10", + "build_timestamp": "{{isotime \"20060102150405\"}}", + "git_revision": "__unknown_git_revision__", + "iso_checksum": "6d878aeb58aad23d2be00774d4da3b3d", + "iso_checksum_type": "md5", + "iso_url": "http://fakeurl/OSX_InstallESD_10.10.3_14D136.dmg", + "metadata": "floppy/dummy_metadata.json", + "name": "macosx-10.10", + "template": "macosx-10.10", + "version": "2.0.TIMESTAMP" + } +} + diff --git a/scripts/macosx/minimize.sh b/scripts/macosx/minimize.sh new file mode 100644 index 000000000..2965d2b80 --- /dev/null +++ b/scripts/macosx/minimize.sh @@ -0,0 +1,16 @@ +#!/bin/sh -eux + +# disable swap +launchctl unload -wF /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist; + +rm -f /private/var/vm/swapfile*; +rm -f /private/var/vm/sleepimage; + +dd if=/dev/zero of=/EMPTY bs=1000000 || echo "dd exit code $? is suppressed"; +rm -f /EMPTY; +# Block until the empty file has been removed, otherwise, Packer +# will try to kill the box while the disk is still full and that's bad +sync; + +# re-enable swap +launchctl load -wF /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist; diff --git a/scripts/macosx/networking.sh b/scripts/macosx/networking.sh new file mode 100644 index 000000000..a172a66b2 --- /dev/null +++ b/scripts/macosx/networking.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +# Thank you to https://github.com/timsutton/osx-vm-templates +# for the implementation + +# This script adds a Mac OS Launch Daemon, which runs every time the +# machine is booted. The daemon will re-detect the attached network +# interfaces. If this is not done, network devices may not work. +PLIST=/Library/LaunchDaemons/com.github.timsutton.osx-vm-templates.detectnewhardware.plist +cat < "${PLIST}" + + + + + Label + com.github.timsutton.osx-vm-templates.detectnewhardware + ProgramArguments + + /usr/sbin/networksetup + -detectnewhardware + + RunAtLoad + + + +EOF + +# These should be already set as follows, but since they're required +# in order to load properly, we set them explicitly. +/bin/chmod 644 "${PLIST}" +/usr/sbin/chown root:wheel "${PLIST}" diff --git a/scripts/macosx/vmtools.sh b/scripts/macosx/vmtools.sh new file mode 100644 index 000000000..ab3cbe5eb --- /dev/null +++ b/scripts/macosx/vmtools.sh @@ -0,0 +1,35 @@ +#!/bin/sh -eux + +case "$PACKER_BUILDER_TYPE" in + +virtualbox-iso|virtualbox-ovf) + echo "VirtualBox not currently supported, sadface"; + ;; + +vmware-iso|vmware-vmx) + iso_name="/tmp/vmtools.iso"; + mount_point="`mktemp -d /tmp/vmware-tools.XXXX`"; + #Run install, unmount ISO and remove it + hdiutil attach "$iso_name" -mountpoint "$mount_point"; + installer -pkg "$mount_point/Install VMware Tools.app/Contents/Resources/VMware Tools.pkg" -target /; + # This usually fails + hdiutil detach "$mount_point" || true; + rm -f "$iso_name"; + rmdir "$mount_point"; + + # Point Linux shared folder root to that used by OS X guests, + # useful for the Hashicorp vmware_fusion Vagrant provider plugin + mkdir /mnt; + ln -sf /Volumes/VMware\ Shared\ Folders /mnt/hgfs; + ;; + +parallels-iso|parallels-pvm) + echo "Parallels not currently supported, sadface"; + ;; + +*) + echo "Unknown Packer Builder Type >>${PACKER_BUILDER_TYPE}<< selected."; + echo "Known are virtualbox-iso|virtualbox-ovf|vmware-iso|vmware-vmx|parallels-iso|parallels-pvm."; + ;; + +esac diff --git a/vagrantfile_templates/macosx.rb b/vagrantfile_templates/macosx.rb index 9bf0fc693..502545dc1 100644 --- a/vagrantfile_templates/macosx.rb +++ b/vagrantfile_templates/macosx.rb @@ -1,4 +1,8 @@ -Vagrant.configure('2') do |config| +Vagrant.configure(2) do |config| + # disabled until https://github.com/mitchellh/vagrant/pull/5326 makes it + # into a release following 1.7.2 + config.ssh.insert_key = false + config.vm.provider 'virtualbox' do |_, override| override.vm.synced_folder '.', '/vagrant', type: 'rsync' end