-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from jonanh/create_prepare_vdi_based_on_autodmg
Support for installing macOS like AutoDMG
- Loading branch information
Showing
12 changed files
with
736 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/bin/bash | ||
|
||
SCRIPT_DIR="$(cd "$(dirname "$0")"; pwd)" | ||
SUPPORT_DIR="$SCRIPT_DIR/support" | ||
|
||
# Parse the optional command line switches | ||
USER="vagrant" | ||
PASSWORD="vagrant" | ||
IMAGE_PATH="$SUPPORT_DIR/vagrant.jpg" | ||
|
||
# Flags | ||
DISABLE_REMOTE_MANAGEMENT=0 | ||
DISABLE_SCREEN_SHARING=0 | ||
DISABLE_SIP=0 | ||
|
||
render_template() { | ||
eval "echo \"$(cat "$1")\"" | ||
} | ||
|
||
create_firstboot_pkg() { | ||
# payload items | ||
mkdir -p "$SUPPORT_DIR/pkgroot/private/var/db/dslocal/nodes/Default/users" | ||
mkdir -p "$SUPPORT_DIR/pkgroot/private/var/db/shadow/hash" | ||
BASE64_IMAGE=$(openssl base64 -in "$IMAGE_PATH") | ||
ShadowHashData=$($SCRIPT_DIR/../scripts/support/generatehash.py "$PASSWORD") | ||
# Replace USER and BASE64_IMAGE in the user.plist file with the actual user and image | ||
render_template "$SUPPORT_DIR/user.plist" > "$SUPPORT_DIR/pkgroot/private/var/db/dslocal/nodes/Default/users/$USER.plist" | ||
USER_GUID=$(/usr/libexec/PlistBuddy -c 'Print :generateduid:0' "$SUPPORT_DIR/user.plist") | ||
# Generate a shadowhash from the supplied password | ||
"$SUPPORT_DIR/generate_shadowhash" "$PASSWORD" > "$SUPPORT_DIR/pkgroot/private/var/db/shadow/hash/$USER_GUID" | ||
|
||
# postinstall script | ||
mkdir -p "$SUPPORT_DIR/tmp/Scripts" | ||
cat "$SUPPORT_DIR/pkg-postinstall" \ | ||
| sed -e "s/__USER__PLACEHOLDER__/${USER}/" \ | ||
| sed -e "s/__DISABLE_REMOTE_MANAGEMENT__/${DISABLE_REMOTE_MANAGEMENT}/" \ | ||
| sed -e "s/__DISABLE_SCREEN_SHARING__/${DISABLE_SCREEN_SHARING}/" \ | ||
| sed -e "s/__DISABLE_SIP__/${DISABLE_SIP}/" \ | ||
> "$SUPPORT_DIR/tmp/Scripts/postinstall" | ||
chmod a+x "$SUPPORT_DIR/tmp/Scripts/postinstall" | ||
|
||
# build it | ||
BUILT_COMPONENT_PKG="$SUPPORT_DIR/tmp/veewee-config-component.pkg" | ||
BUILT_PKG="$SUPPORT_DIR/tmp/veewee-config.pkg" | ||
pkgbuild --quiet \ | ||
--root "$SUPPORT_DIR/pkgroot" \ | ||
--scripts "$SUPPORT_DIR/tmp/Scripts" \ | ||
--identifier com.vagrantup.veewee-config \ | ||
--version 0.1 \ | ||
"$BUILT_COMPONENT_PKG" | ||
productbuild \ | ||
--package "$BUILT_COMPONENT_PKG" \ | ||
"$BUILT_PKG" | ||
rm -rf "$SUPPORT_DIR/pkgroot" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#!/bin/sh -e | ||
|
||
usage() { | ||
cat <<EOF | ||
Usage: | ||
$(basename "$0") "/path/to/diskimage.vdi" | ||
Description: | ||
Creates and exports a machine image (OVF) from virtual disk image | ||
EOF | ||
} | ||
|
||
cleanup() { | ||
if [ -n "$VM" ] && VBoxManage list vms | grep -q "$VM"; then | ||
# Detach the diskimage before deleting the virtual image | ||
VBoxManage storageattach "$VM" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium none | ||
VBoxManage unregistervm "$VM" --delete || echo > /dev/null | ||
fi | ||
} | ||
|
||
trap cleanup EXIT INT TERM | ||
|
||
msg_status() { | ||
echo "\033[0;32m-- $1\033[0m" | ||
} | ||
|
||
msg_error() { | ||
echo "\033[0;31m-- $1\033[0m" | ||
} | ||
|
||
render_template() { | ||
eval "echo \"$(cat "$1")\"" | ||
} | ||
|
||
if [ ! -f "$1" ]; then | ||
usage | ||
exit 1 | ||
fi | ||
|
||
TIMESTAMP=$(date +"%s") | ||
VM="macOS_${TIMESTAMP}" | ||
HARDDRIVE="$1" | ||
OUTPUT="${HARDDRIVE%.vdi}.ovf" | ||
|
||
msg_status "Creating new virtual machine" | ||
VBoxManage createvm --name "$VM" --ostype "MacOS_64" --register | ||
|
||
msg_status "Adding SATA Controller" | ||
VBoxManage storagectl "$VM" --name "SATA Controller" --add sata --controller IntelAHCI | ||
|
||
msg_status "Attaching vdi" | ||
VBoxManage storageattach "$VM" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium "$HARDDRIVE" | ||
|
||
msg_status "Setting up virtual machine" | ||
VBoxManage modifyvm "$VM" --audiocontroller "hda" | ||
VBoxManage modifyvm "$VM" --chipset "ich9" | ||
VBoxManage modifyvm "$VM" --firmware "efi" | ||
VBoxManage modifyvm "$VM" --cpus "2" | ||
VBoxManage modifyvm "$VM" --hpet "on" | ||
VBoxManage modifyvm "$VM" --keyboard "usb" | ||
VBoxManage modifyvm "$VM" --memory "4096" | ||
VBoxManage modifyvm "$VM" --mouse "usbtablet" | ||
VBoxManage modifyvm "$VM" --vram "128" | ||
|
||
msg_status "Exporting the virtual machine" | ||
VBoxManage export "$VM" --output "$OUTPUT" | ||
|
||
msg_status "Done. Virtual machine export located at $OUTPUT." |
Oops, something went wrong.