#!/usr/bin/env bash set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "$ROOT" APP_BUNDLE="${ROOT}/.build/Redline.app" STAGING="${ROOT}/.build/dmg-staging" DMG="${ROOT}/.build/Redline.dmg" MOUNT_POINT="${ROOT}/.build/dmg-mnt" SKIP_SIGN=0 for arg in "$@"; do case "${arg}" in --skip-sign) SKIP_SIGN=1 ;; *) echo "Unknown argument: ${arg}" >&2 echo "Usage: $0 [--skip-sign]" >&2 exit 1 ;; esac done echo "==> Building Redline.app" if [[ "${SKIP_SIGN}" -eq 1 ]]; then ./scripts/build-app.sh --skip-sign else ./scripts/build-app.sh fi if [[ ! -d "${APP_BUNDLE}" ]]; then echo "App bundle not found at ${APP_BUNDLE}" >&2 exit 1 fi echo "==> Staging DMG contents" rm -rf "${STAGING}" mkdir -p "${STAGING}" ditto "${APP_BUNDLE}" "${STAGING}/Redline.app" ln -s /Applications "${STAGING}/Applications" echo "==> Creating ${DMG}" mkdir -p "$(dirname "${DMG}")" hdiutil create -volname "Redline" -srcfolder "${STAGING}" -ov -format UDZO "${DMG}" MOUNTED=0 detach_dmg() { if [[ "${MOUNTED}" -eq 1 ]]; then hdiutil detach "${MOUNT_POINT}" || hdiutil detach "${MOUNT_POINT}" -force || true MOUNTED=0 fi } trap detach_dmg EXIT if [[ -d "${MOUNT_POINT}" ]] && /sbin/mount | grep -F -q "${MOUNT_POINT}"; then hdiutil detach "${MOUNT_POINT}" || hdiutil detach "${MOUNT_POINT}" -force fi rm -rf "${MOUNT_POINT}" mkdir -p "${MOUNT_POINT}" echo "==> Verifying ${DMG}" hdiutil attach "${DMG}" -nobrowse -readonly -mountpoint "${MOUNT_POINT}" MOUNTED=1 echo "==> Mount contents" ls -la "${MOUNT_POINT}" if [[ ! -d "${MOUNT_POINT}/Redline.app" ]]; then echo "Verification failed: Redline.app missing from mounted DMG" >&2 exit 1 fi if [[ ! -L "${MOUNT_POINT}/Applications" ]]; then echo "Verification failed: Applications symlink missing from mounted DMG" >&2 exit 1 fi if [[ "$(readlink "${MOUNT_POINT}/Applications")" != "/Applications" ]]; then echo "Verification failed: Applications does not point at /Applications" >&2 exit 1 fi echo "==> codesign --verify --deep" codesign --verify --deep --verbose=2 "${MOUNT_POINT}/Redline.app" echo "==> Detaching ${MOUNT_POINT}" hdiutil detach "${MOUNT_POINT}" MOUNTED=0 trap - EXIT SHA256="$(shasum -a 256 "${DMG}" | awk '{print $1}')" echo echo "DMG path: ${DMG}" echo "SHA256: ${SHA256}"