From 548cc3ce16edf1803da94fd75c3e8d4dd94f9cbd Mon Sep 17 00:00:00 2001 From: Michael Kuzmin Date: Sun, 4 Mar 2018 14:24:36 +0300 Subject: [PATCH] macOS example --- examples/macos/macos-10.13.json | 49 +++++++++++++++++++++++++++++++ examples/macos/setup/.gitignore | 1 + examples/macos/setup/iso-macos.sh | 15 ++++++++++ examples/macos/setup/iso-setup.sh | 23 +++++++++++++++ examples/macos/setup/postinstall | 24 +++++++++++++++ examples/macos/setup/setup.sh | 12 ++++++++ 6 files changed, 124 insertions(+) create mode 100644 examples/macos/macos-10.13.json create mode 100644 examples/macos/setup/.gitignore create mode 100755 examples/macos/setup/iso-macos.sh create mode 100755 examples/macos/setup/iso-setup.sh create mode 100755 examples/macos/setup/postinstall create mode 100755 examples/macos/setup/setup.sh diff --git a/examples/macos/macos-10.13.json b/examples/macos/macos-10.13.json new file mode 100644 index 000000000..6e36c439c --- /dev/null +++ b/examples/macos/macos-10.13.json @@ -0,0 +1,49 @@ +{ + "builders": [ + { + "type": "vsphere-iso", + + "vcenter_server": "vcenter.vsphere65.test", + "username": "root", + "password": "jetbrains", + "insecure_connection": "true", + + "vm_name": "macos-packer", + "host": "esxi-mac.vsphere65.test", + + "guest_os_type": "darwin16_64Guest", + + "CPUs": 1, + "RAM": 4096, + + "disk_size": 32, + "disk_thin_provisioned": true, + + "network_card": "e1000e", + "usb_controller": true, + + "configuration_parameters": { + "ich7m.present": "TRUE", + "smc.present": "TRUE" + }, + + "iso_paths": [ + "[datastore-mac] ISO/macOS 10.13.3.iso", + "[datastore-mac] ISO/setup.iso", + "[datastore-mac] ISO/VMware Tools/10.2.0/darwin.iso" + ], + + "boot_order": "disk,cdrom", + + "boot_wait": "4m", + "boot_command": [ + "", + "ut", + "/Volumes/setup/setup.sh" + ], + + "ssh_username": "jetbrains", + "ssh_password": "jetbrains" + } + ] +} diff --git a/examples/macos/setup/.gitignore b/examples/macos/setup/.gitignore new file mode 100644 index 000000000..89f9ac04a --- /dev/null +++ b/examples/macos/setup/.gitignore @@ -0,0 +1 @@ +out/ diff --git a/examples/macos/setup/iso-macos.sh b/examples/macos/setup/iso-macos.sh new file mode 100755 index 000000000..fa24728f4 --- /dev/null +++ b/examples/macos/setup/iso-macos.sh @@ -0,0 +1,15 @@ +#!/bin/sh +set -eux + +# Based on +# https://gist.github.com/agentsim/00cc38c693e7d0e1b36a2080870d955b#gistcomment-2304505 + +mkdir -p out + +hdiutil create -o out/HighSierra.cdr -size 5530m -layout SPUD -fs HFS+J +hdiutil attach out/HighSierra.cdr.dmg -noverify -mountpoint /Volumes/install_build +sudo /Applications/Install\ macOS\ High\ Sierra.app/Contents/Resources/createinstallmedia --volume /Volumes/install_build --nointeraction +hdiutil detach /Volumes/Install\ macOS\ High\ Sierra +hdiutil convert out/HighSierra.cdr.dmg -format UDTO -o out/HighSierra.iso +mv out/HighSierra.iso.cdr out/HighSierra.iso +rm out/HighSierra.cdr.dmg diff --git a/examples/macos/setup/iso-setup.sh b/examples/macos/setup/iso-setup.sh new file mode 100755 index 000000000..ede079b75 --- /dev/null +++ b/examples/macos/setup/iso-setup.sh @@ -0,0 +1,23 @@ +#!/bin/sh +set -eux + +mkdir -p out/pkgroot +rm -rf /out/pkgroot/* + +mkdir -p out/scripts +rm -rf /out/scripts/* +cp postinstall out/scripts/ + +pkgbuild \ + --identifier io.packer.install \ + --root out/pkgroot \ + --scripts out/scripts \ + out/postinstall.pkg + +mkdir -p out/iso +rm -rf out/iso/* +cp setup.sh out/iso/ +productbuild --package out/postinstall.pkg out/iso/postinstall.pkg + +rm out/setup.iso +hdiutil makehybrid -iso -joliet -default-volume-name setup -o out/setup.iso out/iso diff --git a/examples/macos/setup/postinstall b/examples/macos/setup/postinstall new file mode 100755 index 000000000..819c21922 --- /dev/null +++ b/examples/macos/setup/postinstall @@ -0,0 +1,24 @@ +#!/bin/sh +set -eu + +# Create user account +USERNAME=jetbrains +PASSWORD=jetbrains +dscl . -create "/Users/${USERNAME}" +dscl . -create "/Users/${USERNAME}" UserShell /bin/bash +dscl . -create "/Users/${USERNAME}" RealName "${USERNAME}" +dscl . -create "/Users/${USERNAME}" UniqueID 510 +dscl . -create "/Users/${USERNAME}" PrimaryGroupID 20 +dscl . -create "/Users/${USERNAME}" NFSHomeDirectory "/Users/${USERNAME}" +dscl . -passwd "/Users/${USERNAME}" "${PASSWORD}" +dscl . -append /Groups/admin GroupMembership "${USERNAME}" +createhomedir -c + +# Start VMware Tools daemon explicitly +launchctl load /Library/LaunchDaemons/com.vmware.launchd.tools.plist + +# Enable SSH +systemsetup -setremotelogin on + +# Disable the welcome screen +touch "$3/private/var/db/.AppleSetupDone" diff --git a/examples/macos/setup/setup.sh b/examples/macos/setup/setup.sh new file mode 100755 index 000000000..6f28af424 --- /dev/null +++ b/examples/macos/setup/setup.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +# Format partition +diskutil eraseDisk JHFS+ Disk disk0 + +# Packages are installed in reversed order - why? +"/Volumes/Image Volume/Install macOS High Sierra.app/Contents/Resources/startosinstall" \ + --volume /Volumes/Disk \ + --converttoapfs no \ + --agreetolicense \ + --installpackage "/Volumes/setup/postinstall.pkg" \ + --installpackage "/Volumes/VMware Tools/Install VMware Tools.app/Contents/Resources/VMware Tools.pkg"