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 368ee6d8b5)
This commit is contained in:
Eli Barzilay 2013-01-13 16:51:31 -05:00 committed by Ryan Culpepper
parent 35879ebfb2
commit 48380b48c2

View File

@ -53,7 +53,7 @@ workmachine="winooski"
maindir="/home/scheme"
# machines for specific installer creations
dmgmachine="weatherwax"
dmgmachine="dublin"
nsismachine="pitcairn"
# list of environment variables that should be carried over to ssh jobs
@ -1726,10 +1726,7 @@ make_dmg() { # inputs: dir, dmg, bg-image
show "Making \"$tgtdmg\" from \"$srcdir\""
if [[ "x$tmpbg" != "x-" ]]; then _cp "$tmpbg" "$srcdir"; fi
_cd "$(dirname "$srcdir")"
_run sudo rm -f "$tgtdmg" "$tmpdmg"
# It should be possible to create dmgs normally, but they'd be created with
# the same user id of whoever runs this script...
_run sudo chown -R root:admin "$src"
_rm "$tgtdmg" "$tmpdmg"
# The following command should work fine, but it looks like hdiutil in 10.4
# is miscalculating the needed size, making it too big in our case (and too
# small with >8GB images). It seems that it works to first generate an
@ -1737,31 +1734,46 @@ make_dmg() { # inputs: dir, dmg, bg-image
# _run sudo hdiutil create -format UDZO -imagekey zlib-level=9 -ov \
# -mode 555 -volname "$src" -srcfolder "$src" "$tgtdmg"
# so: [1] create an uncompressed image
_run sudo hdiutil create -format UDRW -ov \
_run hdiutil create -format UDRW -ov \
-mode 755 -volname "$src" -srcfolder "$src" "$tmpdmg"
# [2] remove the source tree
_run sudo rm -rf "$src"
_rm "$src"
# [3] do the expected dmg layout (see below)
if [[ "x$tmpbg" != "x-" ]]; then
easy_dmg_layout "$tmpdmg" "$src" "$(basename "$tmpbg")"
fi
# [4] create the compressed image from the uncompressed image
_run sudo hdiutil convert -format UDZO -imagekey zlib-level=9 -ov \
_run hdiutil convert -format UDBZ -imagekey zlib-level=9 -ov \
"$tmpdmg" -o "$tgtdmg"
# [5] remove the uncompressed image
_run sudo chown "$myself" "$tgtdmg" "$tmpdmg"
_rm "$tmpdmg"
}
easy_dmg_layout() {
local tmpdmg="$1" volname="$2" bg="$3"; shift 3
show "Mounting image for layout"
local vol_dev="$(
sudo hdiutil attach -readwrite -noverify -noautoopen "$tmpdmg" \
| grep '/dev/' | head -1 | awk '{print $1}')"
local mnt="mounted-dmg-$$"
_run hdiutil attach -readwrite -noverify -noautoopen \
-mountpoint "$tmpdir/$mnt" "$tmpdmg"
show "Creating layout via Finder"
sudo /usr/bin/osascript <<-EOF
# see also https://github.com/andreyvit/yoursway-create-dmg
/usr/bin/osascript <<-EOF
tell application "Finder"
tell disk "$volname"
-- look for a single disk with the mount point as its name
-- (maybe this works only on newer osx versions?)
set myDisks to every disk of desktop
set theDMGDisk to ""
repeat with d in myDisks
if name of d = "$mnt"
if theDMGDisk = ""
set theDMGDisk to d
else
error "Too many attached DMGs found!"
end if
end if
end repeat
if theDMGDisk = "" then error "Attached DMG not found!"
-- found a single matching disk, continue
tell theDMGDisk
open
set current view of container window to icon view
set toolbar visible of container window to false
@ -1786,7 +1798,9 @@ easy_dmg_layout() {
end tell
EOF
sync; sync
_run sudo hdiutil detach "$vol_dev"
_run sudo chown -R root:admin "$tmpdir/$mnt/"* "$tmpdir/$mnt/".[^.]*
sync; sync
_run hdiutil detach "$tmpdir/$mnt"
}
#----------------------------------------
do_tgz_to_dmg() {
@ -1799,6 +1813,7 @@ do_tgz_to_dmg() {
distname="$distname $(name_of_dist_type "$ptype")"
fi
local savedpwd="$(pwd)"
unset LD_LIBRARY_PATH # no warnings (http://openradar.appspot.com/11894054)
_rm "$tmpdmg"
_rmcd "$tmpdir/tgz-to-dmg-$$"
_mcd "$distname"
@ -1825,7 +1840,9 @@ tgz_to_dmg() {
_scp "$PLTHOME/$dmgbackground" "${dmgmachine}:$tmpbg"
fi
local script="-"
if [[ -e "$dmgscriptname" ]]; then script="$(cat "$dmgscriptname")"; fi
if [[ "$simpledmg" = "no" && -e "$dmgscriptname" ]]; then
script="$(cat "$dmgscriptname")"
fi
run_part "$dmgmachine" "do_tgz_to_dmg" \
"$tmptgz" "$tmpdmg" "$tmpbg" "$script" \
"$version" "$pname" "$ptype" "$srcplatform"