#!/bin/sh # USD.NET for Mac: curl -fsSL usd.net/i | sh # Read it first: https://usd.net/install?raw=1 set -eu URL="https://usd.net/mac/USD.NET-0.3.0.dmg" SHA="5aaa2eecd6a48d6196b1b129f559d7b9a75af2422d193e8d1b31b1680177fddf" VERSION="0.3.0" TEAM="CCKXS9W488" BUNDLE="net.usd.wallet" say() { printf '%s\n' "$*"; } fail() { printf 'USD.NET: %s\n' "$*" >&2; exit 1; } [ "$(uname -s)" = "Darwin" ] || fail "USD.NET for Mac runs on macOS." [ "$(sysctl -n hw.optional.arm64 2>/dev/null || echo 0)" = "1" ] || fail "USD.NET needs a Mac with Apple silicon (M1 or later)." major=$(sw_vers -productVersion | cut -d. -f1) [ "$major" -ge 14 ] 2>/dev/null || fail "USD.NET needs macOS 14 Sonoma or later. This Mac has macOS $(sw_vers -productVersion)." tmp=$(mktemp -d "${TMPDIR:-/tmp}/usdnet.XXXXXX") mnt="" cleanup() { [ -n "$mnt" ] && hdiutil detach "$mnt" -quiet -force >/dev/null 2>&1 || true rm -rf "$tmp" } trap cleanup EXIT INT TERM say "Downloading USD.NET ${VERSION}…" curl -fL --proto '=https' --progress-bar "$URL" -o "$tmp/USD.NET.dmg" || fail "The download didn't finish. Check your connection and try again." got=$(shasum -a 256 "$tmp/USD.NET.dmg" | awk '{print $1}') [ "$got" = "$SHA" ] || fail "The download doesn't match the published checksum. Nothing was installed." mnt="$tmp/mnt" mkdir -p "$mnt" hdiutil attach -nobrowse -readonly -noautoopen -quiet -mountpoint "$mnt" "$tmp/USD.NET.dmg" || { mnt=""; fail "The disk image couldn't be opened."; } app="$mnt/USD.NET.app" [ -d "$app" ] || fail "The disk image doesn't hold USD.NET." say "Checking the signature…" codesign --verify --deep --strict "$app" 2>/dev/null || fail "The app's signature doesn't check out. Nothing was installed." team=$(codesign -dv "$app" 2>&1 | sed -n 's/^TeamIdentifier=//p') [ "$team" = "$TEAM" ] || fail "The app isn't signed by USD.NET (team $TEAM). Nothing was installed." id=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' "$app/Contents/Info.plist" 2>/dev/null || true) [ "$id" = "$BUNDLE" ] || fail "Unexpected app ($id). Nothing was installed." spctl --assess --type execute "$app" 2>/dev/null || fail "Gatekeeper didn't accept the app. Nothing was installed." # is $1 at least $2 (a.b.c, numerically)? atleast() { awk -v a="$1" -v b="$2" 'BEGIN { n = split(a, x, "."); m = split(b, y, "."); k = n > m ? n : m for (i = 1; i <= k; i++) { p = x[i] + 0; q = y[i] + 0; if (p > q) exit 0; if (p < q) exit 1 } exit 0 }' } dest="/Applications" [ -w "$dest" ] || { dest="$HOME/Applications"; mkdir -p "$dest"; } target="$dest/USD.NET.app" installed="" for p in "/Applications/USD.NET.app" "$HOME/Applications/USD.NET.app"; do if [ -d "$p" ] && [ "$(/usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' "$p/Contents/Info.plist" 2>/dev/null || true)" = "$BUNDLE" ]; then installed="$p"; break fi done if [ -n "$installed" ] && atleast "$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "$installed/Contents/Info.plist" 2>/dev/null || echo 0)" "$VERSION"; then say "USD.NET is already up to date in $(dirname "$installed")." target="$installed" else if pgrep -xq USD.NET; then say "Closing the running USD.NET…" osascript -e 'tell application id "net.usd.wallet" to quit' >/dev/null 2>&1 || true i=0; while pgrep -xq USD.NET && [ $i -lt 20 ]; do sleep 0.5; i=$((i + 1)); done fi say "Installing USD.NET $VERSION in ${dest}…" rm -rf "$target.installing" ditto "$app" "$target.installing" || fail "Couldn't copy USD.NET to $dest." if [ -n "$installed" ] && [ "$installed" != "$target" ]; then rm -rf "$installed"; fi rm -rf "$target" mv "$target.installing" "$target" xattr -dr com.apple.quarantine "$target" 2>/dev/null || true fi hdiutil detach "$mnt" -quiet -force >/dev/null 2>&1 || true mnt="" open "$target" say "USD.NET $VERSION is open: look for its icon in the menu bar."