forked from huygn/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
osx_create_installer
executable file
·65 lines (47 loc) · 2.05 KB
/
osx_create_installer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
#!/usr/bin/env bash
if [[ ! "$1" || "$1" == "-h" || "$1" == "--help" ]]; then cat <<HELP
Create an OS X "USB Install Stick" from InstallESD.dmg
http://benalman.com/
Usage: sudo $(basename "$0") source_image target_path
Before running this script, open Disk Utility and partition a USB Stick like:
* 1 Partition
* Options -> GUID Partition Table
* Mac OS Extended (Journaled)
* Name: Foobar
Then run this script like: sudo $(basename "$0") InstallESD.dmg /Volumes/Foobar
Copyright (c) 2012 "Cowboy" Ben Alman
Licensed under the MIT license.
http://benalman.com/about/license/
HELP
[[ "$1" ]]; exit; fi
dmg_path="$1"
usb_path="${2%/}"
[[ $UID != 0 ]] && echo "Error: please run with sudo" && exit 1
[[ ! -e "$dmg_path" ]] && echo "Error: source \"$dmg_path\" not found" && exit 2
[[ ! -e "$usb_path" ]] && echo "Error: target \"$usb_path\" not found" && exit 3
usb_device="$(df | grep -w "$usb_path" | awk '{print $1}')"
# Mount image (invisibly)
dmg_mount="$(hdiutil attach "$dmg_path" -nobrowse | perl -ne 'm#(/Volumes/.*)# && print $1')"
# Restore image
asr -restore -source "$dmg_path" -target $usb_device -erase -format HFS+
# Unmount image
hdiutil detach "$dmg_mount"
# Mount usb stick (invisibly)
hdiutil attach $usb_device -nobrowse
usb_name="$(diskutil info $usb_device | perl -ne 'm#Volume Name:\s+(.*)# && print $1')"
usb_mount="$(diskutil info $usb_device | perl -ne 'm#Mount Point:\s+(.*)# && print $1')"
final_name="$(basename "$usb_mount/Install "*.app .app)"
# Add a drive icon (note: 1024x1024 icons don't appear in the boot screen on older macs)
srcicon=("$usb_mount"/*.app/Contents/Resources/InstallAssistant.icns)
volicon="$usb_mount/.VolumeIcon.icns"
cp "$srcicon" "$volicon"
# Set some properties to ensure the icon works
SetFile -c icnC "$volicon"
SetFile -a C "$usb_mount"
# Give it the proper boot screen name and keep the folder from auto-opening
bless --folder "$usb_mount" -label "$final_name"
# Rename drive
diskutil rename "$usb_name" "$final_name"
# Re-mount usb stick so that it's visible
diskutil unmount $usb_device
hdiutil attach $usb_device