#!/bin/sh # Install Maru (desktop) on a Mac: curl -fsSL https://maru.audio/install.sh | sh # # Picks your Mac's chip, downloads the current release, and installs it only if # Apple accepts it as notarized and it is signed by Maru. Read it before running # it if you like; the same download is on https://maru.audio/apps. # # MARU_INSTALL_DIR where to install (default /Applications, else ~/Applications) # MARU_DOWNLOADS_BASE download site (https, or http on this machine, for testing) # MARU_INSTALL_NO_OPEN set to 1 to install without opening the app # Everything is in functions and main runs on the last line, so a download that # is cut short runs nothing. set -eu BUNDLE_ID="audio.maru.desktop" TEAM_ID="THB8W8Z8GV" APPS_PAGE="https://maru.audio/apps" workspace="" mounted="" staging="" say() { printf '%s\n' "$*" >&2; } fail() { say "Maru install failed: $*"; exit 1; } # Removes only the temporary folders this script made. cleanup() { if [ -n "$mounted" ]; then hdiutil detach -quiet "$mounted" /dev/null || echo 0)" = "1" ]; then echo arm64 else echo x64 fi } downloads_base() { base="${MARU_DOWNLOADS_BASE:-https://maru.audio}" case "$base" in https://* | http://127.0.0.1:* | http://localhost:*) echo "${base%/}" ;; *) fail "MARU_DOWNLOADS_BASE must use https." ;; esac } install_dir() { if [ -n "${MARU_INSTALL_DIR:-}" ]; then mkdir -p "$MARU_INSTALL_DIR" echo "$MARU_INSTALL_DIR" elif [ -w /Applications ]; then echo /Applications else mkdir -p "$HOME/Applications" echo "$HOME/Applications" fi } app_version() { defaults read "$1/Contents/Info" CFBundleShortVersionString 2>/dev/null || true } # Downloads made with curl skip the check macOS gives a browser download, so this # stands in for it. Refuse anything Apple or the signature does not vouch for. verify_app() { unsigned="This release is not signed and notarized, so it can't be installed this way. Download it from $APPS_PAGE instead." [ "$(defaults read "$1/Contents/Info" CFBundleIdentifier 2>/dev/null || true)" = "$BUNDLE_ID" ] || fail "$unsigned" codesign --verify --deep --strict "$1" 2>/dev/null || fail "$unsigned" team="$(codesign -dv "$1" 2>&1 | sed -n 's/^TeamIdentifier=//p')" [ "$team" = "$TEAM_ID" ] || fail "$unsigned" spctl --assess --type execute "$1" 2>/dev/null || fail "$unsigned" } main() { if [ "$(uname -s)" != "Darwin" ]; then fail "this script is for macOS. See $APPS_PAGE for other platforms." fi trap cleanup EXIT trap 'exit 130' INT TERM workspace="$(mktemp -d)" arch="$(mac_arch)" url="$(downloads_base)/downloads/latest/macos/$arch" destination="$(install_dir)" say "Downloading Maru for $arch..." curl -fL --retry 3 --progress-bar -o "$workspace/Maru.dmg" "$url" /dev/null 2>&1; then fail "Maru is running. Quit it and run this again." fi if [ -d "$target" ]; then mv "$target" "$staging/previous.app"; fi if ! mv "$staging/$name" "$target"; then if [ -d "$staging/previous.app" ]; then mv "$staging/previous.app" "$target"; fi fail "couldn't move Maru into $destination." fi say "Installed Maru $version at $target" fi if [ "${MARU_INSTALL_NO_OPEN:-}" != "1" ]; then open "$target"; fi } main "$@"