#!/bin/bash set -euo pipefail # Installs the unsigned Pickware Games test build for the current user. # Removes quarantine only from the newly downloaded app, never globally. fail() { printf '%s\n' "$*" >&2; exit 1; } [[ "$(uname -s)" == Darwin ]] || fail 'This installer requires macOS.' case "$(uname -m)" in arm64) arch=arm64 ;; x86_64) if [[ "$(sysctl -in sysctl.proc_translated 2>/dev/null || true)" == 1 ]]; then arch=arm64; else arch=x64; fi ;; *) fail 'Unsupported Mac architecture.' ;; esac printf '%s\n' 'Installing the unsigned Pickware Games test build.' 'This removes download quarantine for this app only. No administrator password is needed.' if pgrep -f '/Pickware Games.app/Contents/MacOS/' >/dev/null; then fail 'Quit Pickware Games and run this command again.' fi apps="$HOME/Applications" target="$apps/Pickware Games.app" mkdir -p "$apps" [[ ! -L "$target" ]] || fail 'The destination is a symbolic link. Remove it before installing.' if [[ -e "$target" ]]; then identifier=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' "$target/Contents/Info.plist" 2>/dev/null || true) [[ "$identifier" == com.pickware.games ]] || fail 'The destination contains a different app; leaving it untouched.' fi work=$(mktemp -d "$apps/.pickware-install.XXXXXX") mounted=false replaced=false success=false cleanup() { if [[ "$mounted" == true ]]; then hdiutil detach "$work/mount" -quiet || true; fi if [[ "$replaced" == true && "$success" != true && ! -e "$target" ]]; then mv "$work/previous.app" "$target" || return; fi rm -rf "$work" } trap cleanup EXIT trap 'exit 130' INT trap 'exit 143' TERM curl --fail --show-error --location --proto '=https' --proto-redir '=https' --retry 2 \ "https://games.pickware.com/api/downloads/launcher/darwin-$arch" -o "$work/installer.dmg" mkdir "$work/mount" hdiutil attach "$work/installer.dmg" -readonly -nobrowse -mountpoint "$work/mount" -quiet mounted=true source_app="$work/mount/Pickware Games.app" identifier=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' "$source_app/Contents/Info.plist") [[ "$identifier" == com.pickware.games ]] || fail 'Unexpected app in installer.' [[ -x "$source_app/Contents/MacOS/Pickware Games" ]] || fail 'The installer is missing the app executable.' ditto "$source_app" "$work/new.app" # Unsigned test builds require this explicit exception to download quarantine. xattr -dr com.apple.quarantine "$work/new.app" hdiutil detach "$work/mount" -quiet mounted=false if [[ -e "$target" ]]; then mv "$target" "$work/previous.app"; replaced=true; fi mv "$work/new.app" "$target" success=true printf 'Installed: %s\n' "$target" open "$target"