Skip to content

Instantly share code, notes, and snippets.

@staticfloat
Created September 19, 2019 22:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save staticfloat/62369d705f265c0b35ff8888b2e1d76c to your computer and use it in GitHub Desktop.
Save staticfloat/62369d705f265c0b35ff8888b2e1d76c to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
set -x
if [[ -z "$MACOS_CODESIGN_IDENTITY" ]]; then
echo "ERROR: Must export MACOS_CODESIGN_IDENTITY" > &2
exit 1
fi
# detach anything that's old
hdiutil detach /Volumes/Julia-* || true
# Mount target dmg, storing modifications in shadow file; find all disk names:
DISKS="$(hdiutil attach -owners on "$1" -fs HFS+ -shadow | awk '{ print $1 }' | grep -E '/dev/disk\d+$' | sort | uniq)"
# Codesign the app
codesign -s "$MACOS_CODESIGN_IDENTITY" --deep -v /Volumes/Julia*/Julia*.app
# Create "new" DMG from mounted disk
hdiutil create "${1%.*}-new.dmg" -size 1t -fs HFS+ -ov -volname "Julia" -imagekey zlib-level=9 -srcfolder /Volumes/Julia*/
# Unmount the disks
for DISK in ${DISKS}; do
hdiutil detach "${DISK}" || true
done
# cleanup
mv "${1%.*}-new.dmg" "$1"
rm -f "$1.shadow"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment