#!/bin/sh # Minerva installer for macOS and Linux. # # curl -fsSL https://aboutminerva.com/install.sh | sh # # Installs the latest release named by the per-platform manifest the app's own # auto-updater reads, so the script never changes per release. # # macOS Minerva.app into /Applications, or ~/Applications when that isn't # writable. A curl download carries no quarantine flag, so the ad-hoc # signed app opens straight away: no Gatekeeper prompt and no `xattr` # step, unlike the .dmg. # Linux the AppImage as ~/Applications/Minerva.AppImage, where the in-app # updater can replace it, plus a launcher in the applications menu. # # Optional environment: # MINERVA_INSTALL_DIR where Minerva goes instead of the folders above # MINERVA_UPDATES_URL release host (default: https://updates.aboutminerva.com) # # Windows: irm https://aboutminerva.com/install.ps1 | iex # # Everything runs inside main(), called on the last line, so a download cut off # part-way through runs nothing. set -eu say() { printf '%s\n' "$*" } die() { printf 'error: %s\n' "$*" >&2 exit 1 } # First "": "" value in a JSON document. Good enough for the # release manifests, which the release script writes with each key once. json_string() { printf '%s' "$2" | tr -d '\r\n' \ | grep -o "\"$1\"[[:space:]]*:[[:space:]]*\"[^\"]*\"" \ | head -n 1 \ | sed 's/.*"\([^"]*\)"$/\1/' } # The AppImage is built on Ubuntu 24.04 (research-platform's # docker/linux-build/Dockerfile), so its binaries need that release's glibc, # and its runtime mounts itself through libfuse 2, which Ubuntu no longer # installs by default. Check both before downloading rather than leave a # launcher that silently does nothing. check_linux() { glibc=$(getconf GNU_LIBC_VERSION 2>/dev/null | sed 's/^glibc //') [ -n "$glibc" ] || die "Minerva needs a glibc-based Linux distribution" oldest=$(printf '%s\n%s\n' "$glibc" 2.39 | sort -t . -k 1,1n -k 2,2n | head -n 1) [ "$oldest" = 2.39 ] || die "Minerva needs glibc 2.39 or newer (Ubuntu 24.04 or later); this system has $glibc" if ! { ldconfig -p 2>/dev/null || /sbin/ldconfig -p 2>/dev/null; } | grep -q 'libfuse\.so\.2'; then if command -v apt-get >/dev/null 2>&1; then die "Minerva needs FUSE 2 to run. Install it, then run this again: sudo apt install libfuse2t64" fi die "Minerva needs FUSE 2 (libfuse.so.2) to run. Install it with your package manager, then run this again" fi } install_macos() { if [ -n "${MINERVA_INSTALL_DIR:-}" ]; then dir=${MINERVA_INSTALL_DIR%/} elif [ -w /Applications ]; then dir=/Applications else dir=$HOME/Applications fi mkdir -p "$dir" || die "couldn't create $dir" app=$dir/Minerva.app current= if [ -d "$app" ]; then current=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "$app/Contents/Info.plist" 2>/dev/null || true) fi if [ -z "$current" ]; then say "Installing Minerva $version into $dir" elif [ "$current" = "$version" ]; then say "Reinstalling Minerva $version in $dir" else say "Updating Minerva $current to $version in $dir" fi curl -fL $progress -o "$tmp/Minerva.app.tar.gz" "$url" || die "download failed: $url" tar -xzf "$tmp/Minerva.app.tar.gz" -C "$tmp" || die "couldn't unpack $url" [ -d "$tmp/Minerva.app" ] || die "$url doesn't contain Minerva.app" # A running Minerva keeps working from the bundle it was launched from; # the new version starts the next time it's opened. Anchored: only a # process started from the bundle, not one that mentions its path. running= if pgrep -f "^$app/Contents/MacOS/" >/dev/null 2>&1; then running=1 fi # Swap bundles the way the app's updater does: move the old one aside, # move the new one in, and put the old one back if that fails. if [ -e "$app" ]; then mv "$app" "$tmp/Minerva.old.app" || die "couldn't replace $app. Delete it, then run this again" fi if ! mv "$tmp/Minerva.app" "$app"; then if [ -e "$tmp/Minerva.old.app" ]; then mv "$tmp/Minerva.old.app" "$app" fi die "couldn't move Minerva.app into $dir" fi # Nothing above sets the quarantine flag, but if this shell inherited it # (say, from a sandboxed parent app), the ad-hoc signed build would never # launch: AMFI kills it over the quarantined libpdfium.dylib before main(). xattr -dr com.apple.quarantine "$app" 2>/dev/null || true say "Minerva $version is installed in $dir." if [ -n "$running" ]; then say "Minerva is still running the previous version. Quit it (Cmd-Q) and open it again to finish." else say "Open it from Applications, or run: open \"$app\"" fi } install_linux() { dir=${MINERVA_INSTALL_DIR:-$HOME/Applications} dir=${dir%/} mkdir -p "$dir" || die "couldn't create $dir" app=$dir/Minerva.AppImage if [ -e "$app" ]; then say "Updating Minerva in $dir to $version" else say "Installing Minerva $version into $dir" fi # Download beside the old copy so the swap is one atomic rename: a failed # download never replaces a working copy, and a running Minerva keeps the # file it started from until it's reopened. part=$dir/.Minerva.AppImage.$$ curl -fL $progress -o "$part" "$url" || die "download failed: $url" chmod +x "$part" running= if pgrep -f "^$app" >/dev/null 2>&1; then running=1 fi mv -f "$part" "$app" || die "couldn't replace $app" # Launcher for the applications menu, mirroring the one inside the # AppImage: StartupWMClass ties the window to it, and the app registers # its own research-platform:// link handler when it runs. data=${XDG_DATA_HOME:-$HOME/.local/share} icon=$data/icons/hicolor/128x128/apps/minerva.png mkdir -p "$data/applications" "${icon%/*}" if (cd "$tmp" && "$app" --appimage-extract 'usr/share/icons/hicolor/128x128/apps/*.png' >/dev/null 2>&1); then for png in "$tmp"/squashfs-root/usr/share/icons/hicolor/128x128/apps/*.png; do if [ -f "$png" ]; then cp "$png" "$icon" break fi done fi cat >"$data/applications/minerva.desktop" </dev/null)" = 1 ]; then target=darwin-aarch64 machine="Apple Silicon Macs" else target=darwin-x86_64 machine="Intel Macs" fi ;; Linux) case "$(uname -m)" in x86_64 | amd64) target=linux-x86_64 machine="x86_64 Linux" ;; aarch64 | arm64) target=linux-aarch64 machine="ARM Linux" ;; *) die "unsupported architecture: $(uname -m)" ;; esac ;; MINGW* | MSYS* | CYGWIN*) die "on Windows, run this in PowerShell instead: irm https://aboutminerva.com/install.ps1 | iex" ;; *) die "unsupported operating system: $(uname -s)" ;; esac base=${MINERVA_UPDATES_URL:-https://updates.aboutminerva.com} manifest_url=${base%/}/updates/app/$target/latest.json # curl exits 22 when the server answers with an HTTP error, i.e. no # release is published for this platform. manifest=$(curl -fsSL "$manifest_url") || case $? in 22) die "there's no Minerva build for $machine yet" ;; *) die "couldn't reach ${base%/}. Check your connection and try again" ;; esac version=$(json_string version "$manifest") url=$(json_string url "$manifest") case "$target:$url" in darwin-*:*.app.tar.gz | linux-*:*.AppImage) ;; *) die "unexpected release manifest at $manifest_url" ;; esac [ -n "$version" ] || die "unexpected release manifest at $manifest_url" case "$target" in linux-*) check_linux ;; esac tmp=$(mktemp -d) || die "couldn't create a temporary directory" part= trap 'rm -rf "$tmp"; [ -z "$part" ] || rm -f "$part"' EXIT trap 'exit 1' HUP INT PIPE TERM if [ -t 2 ]; then progress=--progress-bar; else progress=-sS; fi case "$target" in darwin-*) install_macos ;; linux-*) install_linux ;; esac } main "$@"