Skip to content

Commit 48380b4

Browse files
elibarzilayrmculpepper
authored andcommitted
Lots of improvements to DMG creation.
* Remove lots of sudoing, and instead use one to change the contents (of non-simple DMGs). Perhaps that's not needed too. (I think that there used to be some problem when the owner was a specific user in the installer script days, perhaps it caused some mess in the pre/post flight scripts. Maybe it's safe to not do this anymore.) * There was a fundamental weakness in the Finder script -- it tweaks the DMG by openning its mount, but the way to specify a disk is via its displayed name which is not unique. This can be problematic if there is already a mount that has the same name, and given that the DMG machine can be used by PLT people, it's even likely to happen. It is tricky to solve this, since there is no way that I see to refer to the disk by its mount point or device in the Finder, and no way to find out the name in the shell. I spent a ton of time searching the webs for a solution, but it seems that practically nobody is concerned (or even aware of this problem). Eventually, the hack I did is to mount the image onto a randomly named directory, then iterate over all disks and look for one whose `name' property is that directory name (apparently the `name' property is the name of the last component of the mount point). For safety, throw an error if no such disk is found, or if more than one is found. Incidentally, using a known mount point also simplifies things since there is no need to know the device name of the mount. * Use UDBZ instead of UDZO for the compressed image. The savings are not as big as I expected them to be for some reason, but the compatibility issues should be all gone now (UDBZ works only from 10.4 and up). * Unset $LD_LIBRARY_PATH to avoid some 10.8 bug. * Switch the build to happen on dublin, running 10.8. At least code-signing is broken on the 10.5.8 machine, and possibly also the osascript to identify the desired image disk. (cherry picked from commit 368ee6d)
1 parent 35879eb commit 48380b4

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

collects/meta/build/build

+34-17
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ workmachine="winooski"
5353
maindir="/home/scheme"
5454

5555
# machines for specific installer creations
56-
dmgmachine="weatherwax"
56+
dmgmachine="dublin"
5757
nsismachine="pitcairn"
5858

5959
# list of environment variables that should be carried over to ssh jobs
@@ -1726,42 +1726,54 @@ make_dmg() { # inputs: dir, dmg, bg-image
17261726
show "Making \"$tgtdmg\" from \"$srcdir\""
17271727
if [[ "x$tmpbg" != "x-" ]]; then _cp "$tmpbg" "$srcdir"; fi
17281728
_cd "$(dirname "$srcdir")"
1729-
_run sudo rm -f "$tgtdmg" "$tmpdmg"
1730-
# It should be possible to create dmgs normally, but they'd be created with
1731-
# the same user id of whoever runs this script...
1732-
_run sudo chown -R root:admin "$src"
1729+
_rm "$tgtdmg" "$tmpdmg"
17331730
# The following command should work fine, but it looks like hdiutil in 10.4
17341731
# is miscalculating the needed size, making it too big in our case (and too
17351732
# small with >8GB images). It seems that it works to first generate an
17361733
# uncompressed image and then convert it to a compressed one.
17371734
# _run sudo hdiutil create -format UDZO -imagekey zlib-level=9 -ov \
17381735
# -mode 555 -volname "$src" -srcfolder "$src" "$tgtdmg"
17391736
# so: [1] create an uncompressed image
1740-
_run sudo hdiutil create -format UDRW -ov \
1741-
-mode 755 -volname "$src" -srcfolder "$src" "$tmpdmg"
1737+
_run hdiutil create -format UDRW -ov \
1738+
-mode 755 -volname "$src" -srcfolder "$src" "$tmpdmg"
17421739
# [2] remove the source tree
1743-
_run sudo rm -rf "$src"
1740+
_rm "$src"
17441741
# [3] do the expected dmg layout (see below)
17451742
if [[ "x$tmpbg" != "x-" ]]; then
17461743
easy_dmg_layout "$tmpdmg" "$src" "$(basename "$tmpbg")"
17471744
fi
17481745
# [4] create the compressed image from the uncompressed image
1749-
_run sudo hdiutil convert -format UDZO -imagekey zlib-level=9 -ov \
1746+
_run hdiutil convert -format UDBZ -imagekey zlib-level=9 -ov \
17501747
"$tmpdmg" -o "$tgtdmg"
17511748
# [5] remove the uncompressed image
1752-
_run sudo chown "$myself" "$tgtdmg" "$tmpdmg"
17531749
_rm "$tmpdmg"
17541750
}
17551751
easy_dmg_layout() {
17561752
local tmpdmg="$1" volname="$2" bg="$3"; shift 3
17571753
show "Mounting image for layout"
1758-
local vol_dev="$(
1759-
sudo hdiutil attach -readwrite -noverify -noautoopen "$tmpdmg" \
1760-
| grep '/dev/' | head -1 | awk '{print $1}')"
1754+
local mnt="mounted-dmg-$$"
1755+
_run hdiutil attach -readwrite -noverify -noautoopen \
1756+
-mountpoint "$tmpdir/$mnt" "$tmpdmg"
17611757
show "Creating layout via Finder"
1762-
sudo /usr/bin/osascript <<-EOF
1758+
# see also https://github.com/andreyvit/yoursway-create-dmg
1759+
/usr/bin/osascript <<-EOF
17631760
tell application "Finder"
1764-
tell disk "$volname"
1761+
-- look for a single disk with the mount point as its name
1762+
-- (maybe this works only on newer osx versions?)
1763+
set myDisks to every disk of desktop
1764+
set theDMGDisk to ""
1765+
repeat with d in myDisks
1766+
if name of d = "$mnt"
1767+
if theDMGDisk = ""
1768+
set theDMGDisk to d
1769+
else
1770+
error "Too many attached DMGs found!"
1771+
end if
1772+
end if
1773+
end repeat
1774+
if theDMGDisk = "" then error "Attached DMG not found!"
1775+
-- found a single matching disk, continue
1776+
tell theDMGDisk
17651777
open
17661778
set current view of container window to icon view
17671779
set toolbar visible of container window to false
@@ -1786,7 +1798,9 @@ easy_dmg_layout() {
17861798
end tell
17871799
EOF
17881800
sync; sync
1789-
_run sudo hdiutil detach "$vol_dev"
1801+
_run sudo chown -R root:admin "$tmpdir/$mnt/"* "$tmpdir/$mnt/".[^.]*
1802+
sync; sync
1803+
_run hdiutil detach "$tmpdir/$mnt"
17901804
}
17911805
#----------------------------------------
17921806
do_tgz_to_dmg() {
@@ -1799,6 +1813,7 @@ do_tgz_to_dmg() {
17991813
distname="$distname $(name_of_dist_type "$ptype")"
18001814
fi
18011815
local savedpwd="$(pwd)"
1816+
unset LD_LIBRARY_PATH # no warnings (http://openradar.appspot.com/11894054)
18021817
_rm "$tmpdmg"
18031818
_rmcd "$tmpdir/tgz-to-dmg-$$"
18041819
_mcd "$distname"
@@ -1825,7 +1840,9 @@ tgz_to_dmg() {
18251840
_scp "$PLTHOME/$dmgbackground" "${dmgmachine}:$tmpbg"
18261841
fi
18271842
local script="-"
1828-
if [[ -e "$dmgscriptname" ]]; then script="$(cat "$dmgscriptname")"; fi
1843+
if [[ "$simpledmg" = "no" && -e "$dmgscriptname" ]]; then
1844+
script="$(cat "$dmgscriptname")"
1845+
fi
18291846
run_part "$dmgmachine" "do_tgz_to_dmg" \
18301847
"$tmptgz" "$tmpdmg" "$tmpbg" "$script" \
18311848
"$version" "$pname" "$ptype" "$srcplatform"

0 commit comments

Comments
 (0)