#!/bin/sh # Installs CLIDE on macOS or Linux. # # curl -fsSL https://downloads.clide.tools/install.sh | sh # # What it does: reads latest/latest.json, downloads the installer for this computer, checks # its SHA-256, and installs it. macOS: CLIDE.app goes in /Applications (or ~/Applications # when that is not writable). Linux: CLIDE's own installer puts it in ~/.local/share and adds # a menu entry. # # Why a script: CLIDE is free during the beta and not signed by Apple. A file a browser # downloads is flagged, and macOS then refuses to open it until you allow it in System # Settings. A file curl downloads is not flagged, so CLIDE opens like any other app. set -eu DOWNLOADS="${CLIDE_DOWNLOADS:-https://downloads.clide.tools}" say() { printf '%s\n' "$*"; } fail() { printf 'CLIDE install: %s\n' "$*" >&2; exit 1; } case "$(uname -s)" in Darwin) os=macos ;; Linux) os=linux ;; *) fail "this script is for macOS and Linux. On Windows, see https://clide.tools/#download" ;; esac case "$(uname -m)" in arm64 | aarch64) arch=arm64 ;; x86_64 | amd64) arch=x64 ;; *) fail "no CLIDE build for $(uname -m)" ;; esac platform="$os-$arch" work="$(mktemp -d)" cleanup() { if [ -n "${mounted:-}" ]; then hdiutil detach "$mounted" -quiet >/dev/null 2>&1 || true; fi rm -rf "$work" } trap cleanup EXIT INT TERM curl -fsSL "$DOWNLOADS/latest/latest.json?$(date +%s)" -o "$work/latest.json" || fail "could not reach $DOWNLOADS" # latest.json is written by scripts/publish.ts, one field per line, so plain text tools read it. field() { sed -n "/\"$platform\"/,/}/p" "$work/latest.json" | grep "\"$1\"" | head -1 | cut -d'"' -f4; } # Each installer says which release it is from: platforms are published one at a time. version="$(field version)" [ -n "$version" ] || version="$(grep '"version"' "$work/latest.json" | head -1 | cut -d'"' -f4)" file="$(field file)" sha="$(field sha256)" [ -n "$file" ] || fail "no CLIDE build for $platform yet" url="$DOWNLOADS/latest/$file" say "Downloading CLIDE $version for $platform…" curl -fL --progress-bar "$url" -o "$work/$file" || fail "download failed" if command -v sha256sum >/dev/null 2>&1; then got="$(sha256sum "$work/$file" | cut -d' ' -f1)" else got="$(shasum -a 256 "$work/$file" | cut -d' ' -f1)"; fi [ "$got" = "$sha" ] || fail "the download's checksum does not match ($got, expected $sha). Nothing was installed." if [ "$os" = macos ]; then dest="${CLIDE_INSTALL_DIR:-/Applications}" [ -w "$dest" ] || { dest="$HOME/Applications"; mkdir -p "$dest"; } mounted="$work/mnt" mkdir -p "$mounted" hdiutil attach "$work/$file" -nobrowse -readonly -quiet -mountpoint "$mounted" || fail "could not open the disk image" app="$(find "$mounted" -maxdepth 1 -name '*.app' | head -1)" [ -n "$app" ] || fail "no app in the disk image" name="$(basename "$app")" if pgrep -xq CLIDE 2>/dev/null || pgrep -fq "$dest/$name/" 2>/dev/null; then say "Quitting CLIDE to replace it…" osascript -e 'quit app "CLIDE"' >/dev/null 2>&1 || true sleep 2 fi rm -rf "${dest:?}/$name" ditto "$app" "$dest/$name" # Nothing set this flag (curl does not), but a copy made some other way might carry it. xattr -dr com.apple.quarantine "$dest/$name" 2>/dev/null || true say "Installed CLIDE $version in $dest. Opening it…" open "$dest/$name" else tar -xzf "$work/$file" -C "$work" installer="$(find "$work" -type f -name installer | head -1)" [ -n "$installer" ] || fail "no installer in the download" chmod +x "$installer" say "Installing CLIDE $version…" "$installer" say "Installed CLIDE $version. Find it in your applications menu." fi