forked from eXist-db/exist
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-dmg-mac.sh
More file actions
executable file
·84 lines (67 loc) · 2.54 KB
/
Copy pathcreate-dmg-mac.sh
File metadata and controls
executable file
·84 lines (67 loc) · 2.54 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
#!/usr/bin/env bash
#
# eXist-db Open Source Native XML Database
# Copyright (C) 2001 The eXist-db Authors
#
# info@exist-db.org
# http://www.exist-db.org
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# $1 is .app dir
# $2 is app name e.g. VolName
# $3 is background image
# $4 is Volume icons
# $5 is DS_Store
# $6 is the output DMG file path and name
set -e
set -x
# cleanup any previous DMG before creating a new DMG
if [[ -f "${6}" ]]; then
echo "Removing previous DMG"
rm -v "${6}"
fi
tmp_dmg=/tmp/$2-dmg-tmp
tmp_dmg_mount=$tmp_dmg-mount
final_app_dir="$(dirname "$1")/$2.app"
# Copy the produced .app to `volname`.app
cp -r "$1" "$final_app_dir"
# Create a temporary Disk Image
/usr/bin/hdiutil create -fs HFS+ -srcfolder "$final_app_dir" -volname "$2" -ov "$tmp_dmg" -format UDRW
# Attach the temporary image
/usr/bin/hdiutil attach "$tmp_dmg.dmg" -mountroot "$tmp_dmg_mount"
# Copy the background, the volume icon and DS_Store files
mkdir -p "$tmp_dmg_mount/$2/.DropDMGBackground"
cp "$3" "$tmp_dmg_mount/$2/.DropDMGBackground/"
cp "$4" "$tmp_dmg_mount/$2/.VolumeIcon.icns"
cp "$5" "$tmp_dmg_mount/$2/.DS_Store"
# Set the kHasCustomIcon (0x0400) Finder flag so Finder uses .VolumeIcon.icns.
# Uses xattr to write the 32-byte com.apple.FinderInfo blob directly, replacing
# the SetFile tool that was removed in Xcode 12.
xattr -wx com.apple.FinderInfo \
"0000000000000000040000000000000000000000000000000000000000000000" \
"$tmp_dmg_mount/$2"
# Add a symbolic link to the Applications directory
ln -s /Applications "$tmp_dmg_mount/$2/Applications"
# Detach the temporary image
/usr/bin/hdiutil detach "$tmp_dmg_mount/$2"
# Compress it to a new image
/usr/bin/hdiutil convert "$tmp_dmg.dmg" -format UDZO -o "$6"
# Delete the temporary image
rm "$tmp_dmg.dmg"
# Delete the mount point
rm -r "$tmp_dmg_mount"
# Delete the copied `volname`.app used for the DMG
rm -r "$final_app_dir"