#!/bin/bash set -euo pipefail VERSION='0.1.16' SHA256='9e5d9f9e2d8efa73fd1bd37d3a703ed2672d53dd740dacc9f809032434583ab5' URL="https://octopus.click/releases/$VERSION/Octopus-$VERSION-arm64.zip" fail() { printf 'Octopus: %s\n' "$*" >&2; exit 1; } [ "$(uname -s)" = Darwin ] || fail 'This preview requires macOS.' [ "$(uname -m)" = arm64 ] || fail 'This preview requires Apple Silicon. Run from a native terminal, not Rosetta.' [ "$(sw_vers -productVersion | cut -d. -f1)" -ge 13 ] || fail 'macOS 13 or newer is required.' [ "$(id -u)" -ne 0 ] || fail 'Run as your normal user, without sudo.' DEST="$HOME/Applications/Octopus.app" if pgrep -f "$DEST/Contents/MacOS/octopus-desktop" >/dev/null; then fail 'Quit Octopus before installing an update.'; fi mkdir -p "$HOME/Applications" STAGE=$(mktemp -d "$HOME/Applications/.octopus-install.XXXXXX") trap 'rm -rf "$STAGE"' EXIT printf 'Downloading Octopus %s…\n' "$VERSION" curl --fail --location --proto '=https' --tlsv1.2 --retry 3 "$URL" -o "$STAGE/Octopus.zip" printf '%s %s\n' "$SHA256" "$STAGE/Octopus.zip" | shasum -a 256 -c - >/dev/null || fail 'Download checksum does not match.' ditto -x -k "$STAGE/Octopus.zip" "$STAGE/unpacked" APP="$STAGE/unpacked/Octopus.app" [ -d "$APP" ] || fail 'App bundle missing from download.' codesign --verify --deep --strict "$APP" || fail 'App signature verification failed.' IDENTIFIER=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' "$APP/Contents/Info.plist") [ "$IDENTIFIER" = 'com.octopus.desktop' ] || fail 'Unexpected application identifier.' BACKUP='' if [ -e "$DEST" ]; then mkdir -p "$HOME/Applications/.octopus-backups.noindex" BACKUP="$HOME/Applications/.octopus-backups.noindex/Octopus-backup-$(date +%Y%m%d-%H%M%S)-$$.app" mv "$DEST" "$BACKUP" fi if ! mv "$APP" "$DEST"; then [ -z "$BACKUP" ] || mv "$BACKUP" "$DEST" fail 'Installation failed; the previous app was restored.' fi LSREGISTER='/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister' if [ -x "$LSREGISTER" ]; then [ -z "$BACKUP" ] || "$LSREGISTER" -u "$BACKUP" >/dev/null 2>&1 || true "$LSREGISTER" -f "$DEST" >/dev/null 2>&1 || true fi printf '\nInstalled: %s\n' "$DEST" [ -z "$BACKUP" ] || printf 'Previous version preserved at: %s\n' "$BACKUP" printf 'Open Octopus from Applications. On first launch, macOS may require approval in System Settings → Privacy & Security.\n' printf 'Your existing project data is unchanged.\n'