#!/bin/bash # Startwell Capture installer for macOS and Linux (Windows: install.ps1). # # curl -fsSL https://capture.startwellventures.com/install.sh | bash # # Installs or updates Startwell Capture. Re-run it any time to update in place. # On macOS (into /Applications), in order: # 1. checks this Mac (macOS 15 or later, Apple silicon) # 2. reads the release feed (latest-mac.yml) and downloads the app's .zip # 3. verifies the download against the feed's SHA-512 and checks the app's # code signature (the Startwell Capture certificate) before installing # 4. quits a running Startwell Capture, then swaps the new app in atomically # 5. clears the download quarantine flag and opens the app # On Linux (x86-64, glibc 2.39 or later: Ubuntu 24.04, Debian 13, Fedora 40 or # newer): reads latest-linux.yml and verifies the SHA-512. With apt # (Debian, Ubuntu, Mint, Pop!_OS) it installs the .deb with sudo apt-get; # anywhere else it puts the AppImage in ~/.local/opt/startwell-capture with # a menu entry and icon. # # Uninstall: curl -fsSL https://capture.startwellventures.com/install.sh | bash -s -- --uninstall # --uninstall remove the app, keep your captures and settings # --uninstall --purge also remove the app's data: on macOS Application Support, # the "Startwell Capture Safe Storage" Keychain item and the # app's privacy permissions (asks first; needs a terminal) # # Needs only what ships with the OS: curl, and openssl, ditto, xattr, codesign # (macOS) or coreutils (Linux). # Speech: on Linux and macOS 15-25 it also fetches the Whisper models the app # would pick for this machine (SHA-256 checked, resumable): # --model only that model --model none no model # Environment (for testing): SWC_FEED_URL, SWC_APP_DIR, SWC_NO_OPEN=1, # SWC_MODEL_BASE, and on Linux SWC_LINUX_FORMAT=deb|appimage. set -euo pipefail APP_NAME="Startwell Capture" BUNDLE_ID="com.startwellventures.capture" FEED_URL="${SWC_FEED_URL:-https://capture-updates.startwellventures.com}" FEED_URL="${FEED_URL%/}" # The certificate every release is signed with (SHA-1). Developer ID builds, # if they ever ship, are accepted too. CERT_SHA1="0a8b25fce2acb2aaa911925539514808417aa2a5" REQUIREMENT="identifier \"$BUNDLE_ID\" and (certificate leaf = H\"$CERT_SHA1\" or anchor apple generic)" SUPPORT_DIR="$HOME/Library/Application Support/$APP_NAME" SITE="https://capture.startwellventures.com" if [ -t 1 ]; then BOLD=$'\033[1m'; DIM=$'\033[2m'; RED=$'\033[31m'; GREEN=$'\033[32m'; RESET=$'\033[0m' else BOLD=""; DIM=""; RED=""; GREEN=""; RESET="" fi say() { printf '%s\n' "$*"; } has_tty() { (: /dev/null; } step() { printf '%s==>%s %s\n' "$BOLD" "$RESET" "$*"; } ok() { printf ' %s✓%s %s\n' "$GREEN" "$RESET" "$*"; } die() { printf '%sError:%s %s\n' "$RED" "$RESET" "$*" >&2 exit 1 } WORK="" cleanup() { if [ -n "$WORK" ]; then rm -rf "$WORK"; fi; } trap cleanup EXIT # ------------------------------------------------------------------- checks check_mac() { [ "$(uname -s)" = "Darwin" ] || die "Startwell Capture is a Mac app; this installer only runs on macOS." local version major version="$(sw_vers -productVersion)" major="${version%%.*}" if [ "$major" -lt 15 ]; then die "Startwell Capture needs macOS 15 Sequoia or later. This Mac runs macOS $version. Update in System Settings > General > Software Update, then run this again." fi # uname -m says x86_64 under Rosetta, so ask the hardware if [ "$(sysctl -n hw.optional.arm64 2>/dev/null || echo 0)" != "1" ]; then die "Startwell Capture needs a Mac with Apple silicon (M1 or later). Intel Macs are not supported yet." fi } # --------------------------------------------------------------- locations # Where the app lives: SWC_APP_DIR, else an existing ~/Applications install, # else /Applications. install_dir() { if [ -n "${SWC_APP_DIR:-}" ]; then printf '%s' "${SWC_APP_DIR%/}" elif [ ! -d "/Applications/$APP_NAME.app" ] && [ -d "$HOME/Applications/$APP_NAME.app" ]; then printf '%s' "$HOME/Applications" else printf '%s' "/Applications" fi } app_pids() { # the main process of any installed copy (helpers have their own names) pgrep -f "/$APP_NAME\\.app/Contents/MacOS/$APP_NAME( |\$)" 2>/dev/null || true } quit_app() { local pids i pids="$(app_pids)" [ -n "$pids" ] || return 0 step "Quitting $APP_NAME" # SIGTERM is a normal quit for Electron apps (the same path as Cmd-Q), # and needs no Automation permission for this terminal. # shellcheck disable=SC2086 # word-splitting the pid list is intended kill -TERM $pids 2>/dev/null || true for i in $(seq 1 100); do [ -z "$(app_pids)" ] && break sleep 0.2 done if [ -n "$(app_pids)" ]; then die "$APP_NAME is still running. Quit it (Cmd-Q) and run this again." fi # an update the app was about to install on quit: let it finish first for i in $(seq 1 150); do pgrep -f 'swc-update-.*/swap\.sh' >/dev/null 2>&1 || break [ "$i" = 1 ] && say " ${DIM}waiting for the app's own updater to finish${RESET}" sleep 0.4 done ok "quit" } # ----------------------------------------------------------------- install # Parse latest-mac.yml: print " " of the arm64 .zip. feed_zip() { awk ' /^files:/ { infiles = 1; next } infiles && /^[^ ]/ { infiles = 0 } !infiles { next } /^ *- url:/ { url = $3; next } /^ +sha512:/ && url != "" { if (url ~ /arm64.*\.zip$/ && best == "") best = url " " $2 else if (url ~ /\.zip$/ && any == "") any = url " " $2 url = "" } END { if (best != "") print best; else if (any != "") print any } ' } sha512_b64() { /usr/bin/openssl dgst -sha512 -binary "$1" | /usr/bin/openssl base64 -A } # run a command, with sudo when the install folder needs it as_owner() { if [ "${USE_SUDO:-0}" = 1 ]; then sudo "$@"; else "$@"; fi } install_app() { local dir app feed zip_url zip_sha zip version got new staged stale check_mac dir="$(install_dir)" app="$dir/$APP_NAME.app" WORK="$(mktemp -d "${TMPDIR:-/tmp}/swc-install.XXXXXX")" step "Checking for the latest release" feed="$(curl -fsSL --retry 3 "$FEED_URL/latest-mac.yml?t=$(date +%s)")" || die "Could not reach the release feed at $FEED_URL. Check your connection and try again." version="$(printf '%s\n' "$feed" | awk '/^version:/ { gsub(/["'"'"']/, "", $2); print $2; exit }')" read -r zip_url zip_sha </dev/null || echo unknown)" say " ${DIM}installed: $current, at $app${RESET}" fi step "Downloading" zip="$WORK/app.zip" curl -fL --retry 3 --progress-bar -o "$zip" "$FEED_URL/$zip_url" || die "Download failed: $FEED_URL/$zip_url" got="$(sha512_b64 "$zip")" [ "$got" = "$zip_sha" ] || die "The download does not match the release feed's SHA-512 (got $got). Nothing was installed." ok "SHA-512 verified" step "Checking the app" /usr/bin/ditto -x -k "$zip" "$WORK/x" new="$WORK/x/$APP_NAME.app" [ -d "$new/Contents/MacOS" ] || die "The download does not contain $APP_NAME.app. Nothing was installed." /usr/bin/codesign --verify --deep --strict -R="$REQUIREMENT" "$new" || die "The app's code signature is not the Startwell Capture certificate. Nothing was installed." ok "code signature verified" # where can we write? USE_SUDO=0 if [ ! -d "$dir" ]; then mkdir -p "$dir" 2>/dev/null || true fi if [ ! -w "$dir" ] || { [ -d "$app" ] && [ ! -w "$app" ]; }; then if [ "$dir" != "/Applications" ]; then die "Cannot write to $dir." elif has_tty; then say " /Applications is not writable by your account, so moving the app there needs" say " your Mac password (sudo, used for the move only). To install just for you" say " instead, press Ctrl-C and run: curl -fsSL $SITE/install.sh | SWC_APP_DIR=~/Applications bash" sudo -v || die "sudo was not granted. Nothing was installed." USE_SUDO=1 else dir="$HOME/Applications" app="$dir/$APP_NAME.app" mkdir -p "$dir" say " /Applications is not writable and there is no terminal to ask for a password;" say " installing to $dir instead." fi fi quit_app step "Installing to $app" staged="$dir/.$APP_NAME.app.new.$$" stale="$dir/.$APP_NAME.app.old.$$" as_owner rm -rf "$staged" "$stale" # copy next to the destination first (same volume), so the swap is a rename as_owner /usr/bin/ditto "$new" "$staged" || { as_owner rm -rf "$staged" die "Could not copy the app into $dir. Nothing was changed." } if [ -e "$app" ]; then as_owner mv "$app" "$stale" || { as_owner rm -rf "$staged" die "Could not move the old app aside. Nothing was changed." } fi if ! as_owner mv "$staged" "$app"; then [ -e "$stale" ] && as_owner mv "$stale" "$app" as_owner rm -rf "$staged" die "Could not move the new app into place. The previous version was restored." fi as_owner rm -rf "$stale" as_owner xattr -dr com.apple.quarantine "$app" 2>/dev/null || true if xattr -pr com.apple.quarantine "$app" 2>/dev/null | grep -q .; then die "Could not clear the quarantine flag on $app." fi ok "quarantine flag cleared" /usr/bin/codesign --verify --deep --strict "$app" || die "The installed app failed its signature check." ok "installed app verified" open_mac_app "$app" say "" say "${BOLD}$APP_NAME $version is installed.${RESET}" say "" say "What happens next:" say " - macOS asks once for each permission when you first use the feature that" say " needs it: Microphone, Screen Recording, Accessibility and Automation." say " Your answers are kept across updates." say " - The app updates itself. To update by hand, run this command again." say " - Uninstall: curl -fsSL $SITE/install.sh | bash -s -- --uninstall" } # --------------------------------------------------------------- uninstall uninstall_app() { local purge="$1" dir removed=0 answer if [ "$purge" = 1 ]; then has_tty || die "--purge deletes your captures and settings, so it asks first and needs a terminal. Run it from Terminal." say "This removes $APP_NAME and ALL of its data:" say " $SUPPORT_DIR (captures, topics, settings)" say " the \"$APP_NAME Safe Storage\" Keychain item" say " the app's privacy permissions" say "Context packs you exported to ~/Startwell Capture are kept." printf 'Type "delete" to continue: ' read -r answer /dev/null 2>&1; do :; done ok "removed the Keychain item" tccutil reset All "$BUNDLE_ID" >/dev/null 2>&1 || true ok "reset privacy permissions" else say " Your captures and settings are kept in $SUPPORT_DIR." fi say "${BOLD}$APP_NAME is uninstalled.${RESET}" } # ============================================================= speech model # Whisper transcribes on Windows, Linux and macOS 15-25 (macOS 26 has Apple's # own transcriber, so nothing is fetched there). By default the installer # fetches the pair the app would pick for this machine (recommendSpeechModels): # one model for recordings and one for live words, the same one on light # machines. The app checks and uses what it finds, and downloads anything # missing itself. # --model only that model --model none no model (get one in Settings) # The tables are the app's own registry, generated between the markers. # >>> speech models: generated by apps/desktop/scripts/gen-speech-models-json.mjs from packages/shared/src/speech-models.ts; do not edit # the source (pinned commit), then Startwell's mirror; a file is used only if its SHA-256 matches WHISPER_BASE="${SWC_MODEL_BASE:-https://huggingface.co/ggerganov/whisper.cpp/resolve/5359861c739e955e79d9a303bcbc70fb988958b1}" WHISPER_MIRROR="https://capture-updates.startwellventures.com/models/whisper" # id bytes sha256 (file: ggml-.bin) WHISPER_MODELS=" tiny 77691713 be07e048e1e599ad46341c8d2a135645097a538221678b7acdd1b1919c6e1b21 tiny.en 77704715 921e4cf8686fdd993dcd081a5da5b6c365bfde1162e72b08d75ac75289920b1f base 147951465 60ed5bc3dd14eea856493d334349b405782ddcaf0028d4b5df4088345fba2efe base.en 147964211 a03779c86df3323075f5e796cb2ce5029f00ec8869eee3fdfb897afe36c6d002 small 487601967 1be3a9b2063867b937e64e2ec7483364a79917e157fa98c5d94b5c1fffea987b small.en 487614201 c6138d6d58ecc8322097e0f987c32f1be8bb0a18532a3f88f734d1bbf9c41e5d small-q5_1 190085487 ae85e4a935d7a567bd102fe55afc16bb595bdb618e11b2fc7591bc08120411bb small.en-q5_1 190098681 bfdff4894dcb76bbf647d56263ea2a96645423f1669176f4844a1bf8e478ad30 medium-q5_0 539212467 19fea4b380c3a618ec4723c3eef2eb785ffba0d0538cf43f8f235e7b3b34220f medium.en-q5_0 539225533 76733e26ad8fe1c7a5bf7531a9d41917b2adc0f20f2e4f5531688a8c6cd88eb0 large-v3-turbo-q5_0 574041195 394221709cd5ad1f40c46e6031ca61bce88931e6e088c188294c6d5a55ffa7e2 large-v3-turbo 1624555275 1fc70f774d38eb169993ac391eea357ef47c88757ef72ee5943879b7e8e2bc69 " # min memory (tenths of a GB) min logical processors for recordings for live words; first match wins WHISPER_TIERS=" 150 8 large-v3-turbo-q5_0 base 70 4 small-q5_1 base 35 2 base tiny 0 0 tiny tiny " # <<< speech models MODEL_ARG="" whisper_row() { printf '%s\n' "$WHISPER_MODELS" | awk -v id="$1" '$1 == id { print; exit }'; } # Logical processors and memory in tenths of a GB, rounded like the app reads them # (Node's os.cpus().length and os.totalmem()), then the first tier this machine # meets. The app also counts a graphics card; the installer doesn't look. recommended_models() { local cores=1 tenths=0 bytes kib if [ "$(uname -s)" = Darwin ]; then cores="$(sysctl -n hw.logicalcpu 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 1)" bytes="$(sysctl -n hw.memsize 2>/dev/null || echo 0)" tenths=$(((bytes * 10 + 536870912) / 1073741824)) else cores="$(getconf _NPROCESSORS_ONLN 2>/dev/null || nproc 2>/dev/null || echo 1)" if [ -r /proc/meminfo ]; then kib="$(awk '/^MemTotal:/ { print $2; exit }' /proc/meminfo)" tenths=$(((${kib:-0} * 10 + 524288) / 1048576)) fi fi pick_speech_tier "$cores" "$tenths" } # pick_speech_tier : the models to fetch pick_speech_tier() { printf '%s\n' "$WHISPER_TIERS" | awk -v c="$1" -v r="$2" \ 'NF == 4 && r + 0 >= $1 + 0 && c + 0 >= $2 + 0 { if ($3 == $4) print $3; else print $3, $4; exit }' } check_model_arg() { [ -z "$MODEL_ARG" ] || [ "$MODEL_ARG" = none ] || [ -n "$(whisper_row "$MODEL_ARG")" ] || die "Unknown speech model \"$MODEL_ARG\". Use one of:$(printf '%s\n' "$WHISPER_MODELS" | awk 'NF { printf " %s", $1 }'), or none." } sha256_hex() { if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | cut -c1-64; else shasum -a 256 "$1" | cut -c1-64; fi } file_size() { wc -c <"$1" | tr -d ' '; } # fetch_part : resumable; a server that cannot resume gets one fresh try fetch_part() { curl -fL --retry 3 -C - --progress-bar -o "$2" "$1" && return 0 rm -f "$2" curl -fL --retry 3 --progress-bar -o "$2" "$1" } # install_one_model : never fails the install; a problem is a warning install_one_model() { local dir="$1" id="$2" row bytes sha file part mb url got row="$(whisper_row "$id")" [ -n "$row" ] || { say " speech model $id is not in this installer's list; get one in the app's Settings."; return 0; } read -r _ bytes sha <: the --model choice, else the pair recommended for this machine install_model() { local dir="$1" id if [ "$MODEL_ARG" = none ]; then say " ${DIM}speech model: none (--model none); get one in the app's Settings${RESET}" return 0 fi for id in ${MODEL_ARG:-$(recommended_models)}; do install_one_model "$dir" "$id"; done } # macOS: only before macOS 26 (from 26 on Apple's transcriber is used) mac_uses_whisper() { local major major="$(sw_vers -productVersion 2>/dev/null | cut -d. -f1)" [ -n "$major" ] && [ "$major" -lt 26 ] } install_model_mac() { mac_uses_whisper || return 0 install_model "$SUPPORT_DIR/models/whisper" } # The app resumes any half-done model download (.part) seconds after it # starts, so it must not run while this installer is still writing one: two # writers on one .part spoil it for both. While models are being fetched the # app opens after them (OPEN_AFTER_MODELS=1 keeps the path in OPEN_LATER). OPEN_AFTER_MODELS="" OPEN_LATER="" mac_launch() { /usr/bin/open "$1"; } open_mac_app() { [ "${SWC_NO_OPEN:-0}" != 1 ] || return 0 if [ -n "$OPEN_AFTER_MODELS" ]; then OPEN_LATER="$1"; return 0; fi step "Opening $APP_NAME" mac_launch "$1" } # ==================================================================== Linux # Linux only; the macOS functions above are not used there. LINUX_PKG="startwell-capture" CONTACT="team@startwellventures.com" linux_appimage_dir() { printf '%s' "${SWC_APP_DIR:-$HOME/.local/opt/$LINUX_PKG}"; } linux_data_home() { printf '%s' "${XDG_DATA_HOME:-$HOME/.local/share}"; } linux_desktop_file() { printf '%s' "$(linux_data_home)/applications/$LINUX_PKG.desktop"; } linux_icon_file() { printf '%s' "$(linux_data_home)/icons/hicolor/512x512/apps/$LINUX_PKG.png"; } linux_config_dir() { printf '%s' "${XDG_CONFIG_HOME:-$HOME/.config}/$APP_NAME"; } # The Linux build is made on Ubuntu 24.04, so it needs that system's C library # (glibc) or newer. On anything older the app would not start. LINUX_MIN_GLIBC="2.39" # version_at_least : true when (major.minor) is or later version_at_least() { awk -v have="$1" -v need="$2" 'BEGIN { split(have, h, "."); split(need, n, ".") exit !((h[1] + 0 > n[1] + 0) || (h[1] + 0 == n[1] + 0 && h[2] + 0 >= n[2] + 0)) }' } # Reads `ldd --version` output on stdin; prints the glibc version, or nothing # when it is not glibc (musl prints "musl libc") or there is no ldd. # ldd (Ubuntu GLIBC 2.39-0ubuntu8.3) 2.39 ldd (GNU libc) 2.40 linux_glibc_version() { awk 'NR == 1 { if (tolower($0) ~ /glibc|gnu libc|gnu c library/ && $NF ~ /^[0-9]+\.[0-9]+/) print $NF exit }' } check_linux_glibc() { local out have out="$(ldd --version 2>&1)" || true have="$(printf '%s\n' "$out" | linux_glibc_version)" if [ -z "$have" ]; then if printf '%s\n' "$out" | grep -qi musl; then die "Startwell Capture for Linux needs glibc $LINUX_MIN_GLIBC or later, and this system uses musl (Alpine and similar). It can't run here." fi say " ${DIM}Could not tell this system's glibc version; it needs $LINUX_MIN_GLIBC or later. Carrying on.${RESET}" return 0 fi version_at_least "$have" "$LINUX_MIN_GLIBC" || die "Startwell Capture for Linux needs glibc $LINUX_MIN_GLIBC or later (Ubuntu 24.04, Debian 13, Fedora 40 or newer). This system has glibc $have, so the app would not start. Nothing was installed." ok "glibc $have" } check_linux() { local arch arch="$(uname -m)" case "$arch" in x86_64 | amd64) ;; aarch64 | arm64) die "Startwell Capture for Linux on ARM (aarch64) is not available yet. Email $CONTACT if you need it." ;; *) die "Startwell Capture for Linux needs a 64-bit Intel or AMD (x86-64) computer; this one is $arch." ;; esac check_linux_glibc } # base64 of the file's SHA-512, as electron-builder writes it into the feed linux_sha512_b64() { local hex if command -v sha512sum >/dev/null 2>&1; then hex="$(sha512sum "$1" | cut -c1-128)" else hex="$(shasum -a 512 "$1" | cut -c1-128)" fi # shellcheck disable=SC2059 # the format is the \x-escaped digest, on purpose printf "$(printf '%s' "$hex" | sed 's/../\\x&/g')" | base64 | tr -d '\n' } # Parse latest-linux.yml: print " " of the first file ending in $1. linux_feed_file() { awk -v want="$1" ' /^files:/ { infiles = 1; next } infiles && /^[^ ]/ { infiles = 0 } !infiles { next } /^ *- url:/ { url = $3; next } /^ +sha512:/ && url != "" { if (found == "" && substr(url, length(url) - length(want) + 1) == want) found = url " " $2 url = "" } END { if (found != "") print found } ' } linux_app_pids() { # the .deb's /opt copy, a mounted AppImage, or the extracted one pgrep -f "(/opt/$APP_NAME/|/\\.mount_[^/]*/|squashfs-root/)$LINUX_PKG( |\$)" 2>/dev/null || true } linux_quit_app() { local pids i pids="$(linux_app_pids)" [ -n "$pids" ] || return 0 step "Quitting $APP_NAME" # shellcheck disable=SC2086 # word-splitting the pid list is intended kill -TERM $pids 2>/dev/null || true for i in $(seq 1 100); do [ -z "$(linux_app_pids)" ] && break sleep 0.2 done [ -z "$(linux_app_pids)" ] || die "$APP_NAME is still running. Quit it from its tray menu and run this again." ok "quit" } linux_open() { [ "${SWC_NO_OPEN:-0}" != 1 ] || return 0 # after the speech models (see open_mac_app) if [ -n "$OPEN_AFTER_MODELS" ]; then OPEN_LATER="$1"; return 0; fi if [ -z "${DISPLAY:-}" ] && [ -z "${WAYLAND_DISPLAY:-}" ]; then say " ${DIM}no desktop session in this terminal: start $APP_NAME from your app menu${RESET}" return 0 fi step "Opening $APP_NAME" (cd "$HOME" && nohup "$@" >/dev/null 2>&1 &) || true } # Root, or sudo with a terminal to ask on, or sudo that needs no password. linux_can_sudo() { [ "$(id -u)" = 0 ] && return 0 command -v sudo >/dev/null 2>&1 || return 1 has_tty || sudo -n true 2>/dev/null } linux_sudo() { if [ "$(id -u)" = 0 ]; then "$@"; else sudo "$@"; fi; } # AppImages need FUSE 2. Say how to get it, for this distribution only. linux_libfuse_hint() { local f family="" for f in /usr/lib/x86_64-linux-gnu/libfuse.so.2 /lib/x86_64-linux-gnu/libfuse.so.2 /usr/lib64/libfuse.so.2 /usr/lib/libfuse.so.2 /lib64/libfuse.so.2; do [ -e "$f" ] && return 0 done if command -v ldconfig >/dev/null 2>&1 && ldconfig -p 2>/dev/null | grep -q 'libfuse\.so\.2'; then return 0; fi # shellcheck disable=SC1091 [ -r /etc/os-release ] && family="$(. /etc/os-release && printf ' %s %s ' "${ID:-}" "${ID_LIKE:-}")" say "" say "${BOLD}One more step:${RESET} AppImages need FUSE 2 (libfuse2), which this system does not have." case "$family" in *" debian "* | *" ubuntu "*) say " sudo apt install libfuse2t64 (Ubuntu 22.04, Debian 12 and older: libfuse2)" ;; *" fedora "* | *" rhel "* | *" centos "*) say " sudo dnf install fuse-libs" ;; *" arch "*) say " sudo pacman -S fuse2" ;; *" suse "* | *" opensuse "*) say " sudo zypper install libfuse2" ;; *) say " Debian/Ubuntu: sudo apt install libfuse2t64 Fedora: sudo dnf install fuse-libs" say " Arch: sudo pacman -S fuse2 openSUSE: sudo zypper install libfuse2" ;; esac } # linux_download : download that file and verify it; sets DL_FILE and DL_NAME linux_download() { local url sha got read -r url sha </dev/null 2>&1) || true icon="$(find "$WORK/squashfs-root" -path '*/512x512/apps/*.png' 2>/dev/null | head -n1 || true)" [ -n "$icon" ] || icon="$(find "$WORK/squashfs-root" -maxdepth 1 -name '*.png' 2>/dev/null | head -n1 || true)" linux_quit_app step "Installing to $target" staged="$dir/.Startwell-Capture.AppImage.new.$$" if ! cp "$DL_FILE" "$staged" || ! chmod 755 "$staged"; then rm -f "$staged" die "Could not copy the app into $dir. Nothing was changed." fi mv -f "$staged" "$target" || { rm -f "$staged"; die "Could not move the new app into place. Nothing was changed."; } ok "installed" if [ -n "$icon" ] && cp "$icon" "$icon_file"; then ok "icon"; fi cat >"$desktop" </dev/null 2>&1; then update-desktop-database "$(dirname "$desktop")" >/dev/null 2>&1 || true fi linux_libfuse_hint linux_open "$target" } install_linux() { local feed version format check_linux WORK="$(mktemp -d "${TMPDIR:-/tmp}/swc-install.XXXXXX")" step "Checking for the latest release" feed="$(curl -fsSL --retry 3 "$FEED_URL/latest-linux.yml?t=$(date +%s)")" || die "Could not reach the release feed at $FEED_URL. Check your connection and try again." version="$(printf '%s\n' "$feed" | awk '/^version:/ { gsub(/["'"'"']/, "", $2); print $2; exit }')" ok "$APP_NAME $version" format="${SWC_LINUX_FORMAT:-}" if [ -z "$format" ]; then if command -v apt-get >/dev/null 2>&1 && command -v dpkg >/dev/null 2>&1; then if linux_can_sudo; then format=deb else say " ${DIM}apt is here, but a .deb needs sudo and there is no terminal to ask on: using the AppImage${RESET}" format=appimage fi else format=appimage fi fi case "$format" in deb) linux_install_deb "$feed" ;; appimage) linux_install_appimage "$feed" ;; *) die "SWC_LINUX_FORMAT must be deb or appimage." ;; esac say "" say "${BOLD}$APP_NAME $version is installed.${RESET}" say "" say "What happens next:" say " - It lives in the system tray. GNOME shows tray icons only with the" say " AppIndicator extension; without it, open the app from your app menu." say " - On Wayland your desktop asks each time a recording shares the screen," say " and some context (the page address, window names) needs the browser add-on." say " - The app updates itself. To update by hand, run this command again." say " - Uninstall: curl -fsSL $SITE/install.sh | bash -s -- --uninstall" } uninstall_linux() { local purge="$1" removed=0 answer dir config config="$(linux_config_dir)" if [ "$purge" = 1 ]; then has_tty || die "--purge deletes your captures and settings, so it asks first and needs a terminal." say "This removes $APP_NAME and ALL of its data:" say " $config (captures, topics, settings)" say "Context packs you exported to ~/Startwell Capture are kept." printf 'Type "delete" to continue: ' read -r answer /dev/null 2>&1 && dpkg -s "$LINUX_PKG" >/dev/null 2>&1; then step "Removing the $LINUX_PKG package (sudo)" linux_sudo apt-get remove -y "$LINUX_PKG" || die "apt could not remove $LINUX_PKG." ok "removed the $LINUX_PKG package" removed=1 fi dir="$(linux_appimage_dir)" if [ -e "$dir/Startwell-Capture.AppImage" ]; then rm -f "$dir/Startwell-Capture.AppImage" rmdir "$dir" 2>/dev/null || true ok "removed $dir/Startwell-Capture.AppImage" removed=1 fi if [ -e "$(linux_desktop_file)" ] || [ -e "$(linux_icon_file)" ]; then rm -f "$(linux_desktop_file)" "$(linux_icon_file)" ok "removed the menu entry" fi [ "$removed" = 1 ] || say " $APP_NAME was not found (no $LINUX_PKG package, no AppImage in $dir)." if [ "$purge" = 1 ]; then rm -rf "$config" ok "removed app data" say " The \"$APP_NAME Safe Storage\" entry in your keyring is kept; remove it in your passwords app if you like." else say " Your captures and settings are kept in $config." fi say "${BOLD}$APP_NAME is uninstalled.${RESET}" } main() { local mode=install purge=0 arg while [ $# -gt 0 ]; do arg="$1" shift case "$arg" in --uninstall) mode=uninstall ;; --purge) purge=1 ;; --model) [ $# -gt 0 ] || die "--model needs a model id, or none." MODEL_ARG="$1" shift ;; --model=*) MODEL_ARG="${arg#--model=}" ;; -h | --help) sed -n '2,32p' "$0" 2>/dev/null | sed 's/^# \{0,1\}//' || true say "Usage: install.sh [--model |none] | --uninstall [--purge]" exit 0 ;; *) die "Unknown option: $arg (try --help)" ;; esac done if [ "$purge" = 1 ] && [ "$mode" != uninstall ]; then die "--purge only goes with --uninstall." fi check_model_arg # SWC_OS: testing only (runs the Linux branch elsewhere) case "${SWC_OS:-$(uname -s)}" in Linux) if [ "$mode" = uninstall ]; then uninstall_linux "$purge" else [ "$MODEL_ARG" = none ] || OPEN_AFTER_MODELS=1 install_linux && install_model "$(linux_config_dir)/models/whisper" OPEN_AFTER_MODELS="" [ -z "$OPEN_LATER" ] || linux_open "$OPEN_LATER" fi return ;; MINGW* | MSYS* | CYGWIN*) die "On Windows, install from PowerShell instead: irm $SITE/install.ps1 | iex" ;; esac if [ "$mode" = uninstall ]; then uninstall_app "$purge" else if [ "$MODEL_ARG" != none ] && mac_uses_whisper; then OPEN_AFTER_MODELS=1; fi install_app install_model_mac OPEN_AFTER_MODELS="" [ -z "$OPEN_LATER" ] || open_mac_app "$OPEN_LATER" fi } # everything above only defines functions: a truncated download runs nothing main "$@"