-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake-dmg.sh
More file actions
executable file
·186 lines (162 loc) · 5.68 KB
/
Copy pathmake-dmg.sh
File metadata and controls
executable file
·186 lines (162 loc) · 5.68 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/bin/zsh
set -euo pipefail
project_directory=${0:A:h}
application_name="Mac Display Connect"
application_directory=${APP_INPUT_PATH:-"$project_directory/.build/products/$application_name.app"}
dmg_path=${DMG_OUTPUT_PATH:-"$project_directory/dist/MacDisplayConnect.dmg"}
dmg_path=${dmg_path:A}
output_directory=${dmg_path:h}
temporary_directory=$(mktemp -d)
mounted_volume=
build_app=1
open_dmg=1
cleanup() {
if [[ -n "$mounted_volume" ]]; then
hdiutil detach "$mounted_volume" >/dev/null 2>&1 || true
fi
rm -rf "$temporary_directory"
}
trap cleanup EXIT
die() {
print -u2 "ERROR: $*"
exit 1
}
require_command() {
command -v "$1" >/dev/null 2>&1 || die "$2"
}
detach_mounted_copies() {
local image_info="$temporary_directory/image-info.plist"
local image_count image_index image_path
local entity_count entity_index mount_point
hdiutil info -plist > "$image_info"
image_count=$(plutil -extract images raw -o - "$image_info")
for (( image_index = 0; image_index < image_count; image_index++ )); do
image_path=$(
plutil -extract "images.$image_index.image-path" raw -o - \
"$image_info"
)
[[ "$image_path" == "$dmg_path" ]] || continue
entity_count=$(
plutil -extract "images.$image_index.system-entities" raw -o - \
"$image_info"
)
for (( entity_index = 0;
entity_index < entity_count;
entity_index++ )); do
mount_point=$(
plutil -extract \
"images.$image_index.system-entities.$entity_index.mount-point" \
raw -o - "$image_info" 2>/dev/null
) || continue
[[ -n "$mount_point" ]] || continue
print "Ejecting stale mounted copy at $mount_point"
hdiutil detach "$mount_point" >/dev/null \
|| die "Close files in $mount_point and try again."
done
done
}
usage() {
print "Usage: ./make-dmg.sh [--no-build] [--no-open]"
}
while (( $# > 0 )); do
case "$1" in
--no-build)
build_app=0
;;
--no-open)
open_dmg=0
;;
--help)
usage
exit 0
;;
*)
usage >&2
exit 1
;;
esac
shift
done
require_command create-dmg \
"create-dmg is required. Install it with: npm install --global create-dmg@7.1.0"
require_command gm \
"GraphicsMagick is required. Install it with: brew install graphicsmagick"
require_command convert \
"ImageMagick is required. Install it with: brew install imagemagick"
create_dmg_version=$(create-dmg --version)
[[ "$create_dmg_version" == 7.1.0 ]] \
|| die "create-dmg 7.1.0 is required; found $create_dmg_version."
if [[ "$build_app" == 1 ]]; then
APP_OUTPUT_PATH="$application_directory" \
BUILD_CONFIGURATION=release \
"$project_directory/scripts/build-app.sh"
fi
[[ -d "$application_directory" ]] \
|| {
print -u2 "Mac app not found at $application_directory"
exit 1
}
dmg_source="$temporary_directory/dmg"
temporary_dmg="$temporary_directory/MacDisplayConnect.dmg"
staged_application="$dmg_source/$application_name.app"
generated_dmg="$temporary_directory/$application_name.dmg"
mkdir -p "$dmg_source"
ditto "$application_directory" "$staged_application"
xattr -dr com.apple.FinderInfo "$staged_application" 2>/dev/null || true
xattr -dr com.apple.ResourceFork "$staged_application" 2>/dev/null || true
codesign --verify --deep --strict --verbose=2 "$staged_application"
plutil -lint "$staged_application/Contents/Info.plist" >/dev/null
create_dmg_output=
if ! create_dmg_output=$(
create-dmg \
--no-code-sign \
--no-version-in-filename \
--dmg-title="$application_name" \
"$staged_application" \
"$temporary_directory" 2>&1
); then
print -r -- "$create_dmg_output"
[[ -f "$generated_dmg" ]] \
|| die "create-dmg did not produce $generated_dmg"
fi
print -r -- "$create_dmg_output"
[[ -f "$generated_dmg" ]] \
|| die "create-dmg did not produce $generated_dmg"
mv "$generated_dmg" "$temporary_dmg"
hdiutil verify "$temporary_dmg"
verification_mount="$temporary_directory/verify"
mkdir -p "$verification_mount"
mounted_volume=$verification_mount
hdiutil attach "$temporary_dmg" \
-readonly \
-nobrowse \
-mountpoint "$verification_mount" >/dev/null
mounted_application="$verification_mount/$application_name.app"
background="$verification_mount/.background/dmg-background.tiff"
[[ -d "$mounted_application" && ! -L "$mounted_application" ]] \
|| die "The DMG does not contain $application_name.app."
[[ -L "$verification_mount/Applications" \
&& "$(readlink "$verification_mount/Applications")" == /Applications ]] \
|| die "The DMG does not contain the Applications shortcut."
[[ -f "$verification_mount/.DS_Store" ]] \
|| die "The DMG does not contain its Finder layout."
[[ -f "$background" ]] \
|| die "The DMG does not contain its background."
[[ -f "$verification_mount/.VolumeIcon.icns" ]] \
|| die "The DMG does not contain its volume icon."
[[ "$(sips -g pixelWidth "$background" |
awk '/pixelWidth:/ { print $2 }')" == 660 ]] \
|| die "The DMG background has the wrong width."
[[ "$(sips -g pixelHeight "$background" |
awk '/pixelHeight:/ { print $2 }')" == 400 ]] \
|| die "The DMG background has the wrong height."
codesign --verify --deep --strict --verbose=2 "$mounted_application"
hdiutil detach "$mounted_volume" >/dev/null
mounted_volume=
mkdir -p "$output_directory"
detach_mounted_copies
mv "$temporary_dmg" "$dmg_path"
print "Created $dmg_path"
if [[ "$open_dmg" == 1 ]]; then
open "$dmg_path"
fi