-
Notifications
You must be signed in to change notification settings - Fork 76
/
mkdmg
executable file
·77 lines (63 loc) · 2.64 KB
/
mkdmg
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
#!/bin/sh
set -e
if [[ $# != 4 ]]; then
echo "Usage: mkdmg <source_dir> <size_blocks> <title> <version>"
exit 1
fi
source="$1"
size=$2
title="$3"
version="$4"
finalDMGName="${title}-${version}.dmg"
applicationName=applicationName
if (($size==0)); then
size=$(du -ks "$source" | awk '{print $1}')
size=$(($size+100))
fi
if (($size<600)); then
size=600
fi
echo "size $source $size "
#Create a R/W DMG. It must be larger than the result will be. In this example, the bash variable "size" contains the size in Kb and the contents of the folder in the "source" bash variable will be copied into the DMG:
rm -f pack.temp.dmg "$finalDMGName"
hdiutil create -srcfolder "${source}" -volname "${title}" -fs HFS+ \
-fsargs "-c c=64,a=16,e=16" -format UDRW -size ${size}k pack.temp.dmg
# Unmount old image
[[ -d "/Volumes/${title}" ]] && hdiutil detach "/Volumes/${title}"
#Mount the disk image, and store the device name (you might want to use sleep for a few seconds after this operation):
device=$(hdiutil attach -readwrite -noverify -noautoopen "pack.temp.dmg" | \
egrep '^/dev/' | sed 1q | awk '{print $1}')
sleep 3
#Use AppleScript to set the visual styles (name of .app must be in bash variable "applicationName", use variables for the other properties as needed):
echo '
activate application "Finder"
tell application "Finder"
tell disk "'${title}'"
open
set current view of container window to icon view
set toolbar visible of container window to true
set statusbar visible of container window to true
set the bounds of container window to {400, 100, 885, 430}
set theViewOptions to the icon view options of container window
set arrangement of theViewOptions to not arranged
set icon size of theViewOptions to 72
close
end tell
end tell
' | osascript
# open
# update without registering applications
# delay 5
# eject
# make new alias file at container window to POSIX file "/Applications" with properties {name:"Applications"}
# set position of item "'${applicationName}'" of container window to {100, 100}
# set position of item "Applications" of container window to {375, 100}
# set background picture of theViewOptions to file ".background:'${backgroundPictureName}'"
#Finialize the DMG by setting permissions properly, compressing and releasing it:
chmod -Rf go-w /Volumes/"${title}" || echo "chmod"
sync
sync
hdiutil detach ${device}
hdiutil convert "pack.temp.dmg" -format UDZO -imagekey zlib-level=9 -o "${finalDMGName}"
rm -rf pack.temp.dmg
exit 0