#!/bin/sh # A2 Tprompt installer for macOS and Linux. # # curl -fsSL https://a2tprompt.com/install.sh | sh # # Downloads the latest A2 Tprompt build from GitHub (a2-stuff/a2-tprompt-releases), checks its # SHA-256 checksum when the release has one, and installs it: # macOS the .dmg, copied to /Applications # Ubuntu / Debian the .deb, with apt (asks for your password) # Arch the package, with pacman (asks for your password) # anything else the AppImage, in ~/.local/bin with a menu entry # # Options (after "sh -s --"): # --version 0.2.0 install that version instead of the latest # --appimage on Linux, install the AppImage even if apt or pacman is available # --uninstall remove A2 Tprompt # Example: curl -fsSL https://a2tprompt.com/install.sh | sh -s -- --appimage set -eu REPO="a2-stuff/a2-tprompt-releases" APP="A2 Tprompt" PKG="a2-tprompt" VERSION="" MODE="" UNINSTALL=0 while [ $# -gt 0 ]; do case "$1" in --version) VERSION="${2#v}"; shift 2 ;; --version=*) VERSION="${1#*=}"; VERSION="${VERSION#v}"; shift ;; --appimage) MODE="appimage"; shift ;; --uninstall) UNINSTALL=1; shift ;; -h|--help) sed -n '2,22p' "$0" 2>/dev/null || true; exit 0 ;; *) echo "Unknown option: $1" >&2; exit 1 ;; esac done say() { printf ' %s\n' "$*"; } fail() { printf ' \033[31m%s\033[0m\n' "$*" >&2; exit 1; } need() { command -v "$1" >/dev/null 2>&1 || fail "This needs '$1'. Install it and run the installer again."; } sudo_run() { if [ "$(id -u)" -eq 0 ]; then "$@"; else need sudo; sudo "$@"; fi; } printf '\n \033[1m%s\033[0m\n' "$APP" OS="$(uname -s)" case "$(uname -m)" in x86_64|amd64) ARCH="x64" ;; arm64|aarch64) ARCH="arm64" ;; *) fail "Unsupported processor: $(uname -m)" ;; esac APPIMAGE_DIR="$HOME/.local/bin" APPIMAGE_FILE="$APPIMAGE_DIR/a2-tprompt.AppImage" DESKTOP_FILE="${XDG_DATA_HOME:-$HOME/.local/share}/applications/a2-tprompt.desktop" ICON_FILE="${XDG_DATA_HOME:-$HOME/.local/share}/icons/hicolor/512x512/apps/a2-tprompt.png" # ---------- uninstall ---------- if [ "$UNINSTALL" -eq 1 ]; then if [ "$OS" = "Darwin" ]; then pkill -x "$APP" 2>/dev/null || true if [ -d "/Applications/$APP.app" ]; then rm -rf "/Applications/$APP.app"; say "Removed /Applications/$APP.app."; else say "$APP is not in /Applications."; fi say "Settings are kept in ~/Library/Application Support/$APP; delete that folder to remove them too." else pkill -f a2-tprompt 2>/dev/null || true removed=0 if command -v dpkg >/dev/null 2>&1 && dpkg -s "$PKG" >/dev/null 2>&1; then sudo_run apt-get remove -y "$PKG"; removed=1; fi if command -v pacman >/dev/null 2>&1 && pacman -Q "$PKG" >/dev/null 2>&1; then sudo_run pacman -R --noconfirm "$PKG"; removed=1; fi if [ -f "$APPIMAGE_FILE" ]; then rm -f "$APPIMAGE_FILE" "$DESKTOP_FILE" "$ICON_FILE"; removed=1; fi [ "$removed" -eq 1 ] && say "Uninstalled." || say "$APP is not installed." say "Settings are kept in ~/.config/$APP; delete that folder to remove them too." fi exit 0 fi # ---------- find the release ---------- need curl if [ -n "$VERSION" ]; then API="https://api.github.com/repos/$REPO/releases/tags/v$VERSION"; else API="https://api.github.com/repos/$REPO/releases/latest"; fi JSON="$(curl -fsSL -H 'Accept: application/vnd.github+json' -H 'User-Agent: a2-tprompt-installer' "$API")" \ || fail "Could not find that release on GitHub. Check the version and your internet connection." URLS="$(printf '%s' "$JSON" | grep -o '"browser_download_url": *"[^"]*"' | sed 's/.*"\(https[^"]*\)"/\1/')" TAG="$(printf '%s' "$JSON" | grep -o '"tag_name": *"[^"]*"' | head -n 1 | sed 's/.*"\([^"]*\)"$/\1/')" pick() { printf '%s\n' "$URLS" | grep -E "$1" | head -n 1 || true; } TMP="$(mktemp -d)" trap 'rm -rf "$TMP"' EXIT download() { # url -> $TMP/, checked against the release's checksum list name="$(basename "$1")" say "Downloading $name..." curl -fL --progress-bar -o "$TMP/$name" "$1" || fail "Download failed." sums="$(pick "SHA256SUMS-$2")" if [ -n "$sums" ]; then curl -fsSL -o "$TMP/sums.txt" "$sums" || fail "Could not download the checksum list." expected="$(grep " \*\{0,1\}$name\$" "$TMP/sums.txt" | head -n 1 | cut -d ' ' -f 1)" [ -n "$expected" ] || fail "The checksum list does not include $name. Not installing." if command -v sha256sum >/dev/null 2>&1; then actual="$(sha256sum "$TMP/$name" | cut -d ' ' -f 1)"; else actual="$(shasum -a 256 "$TMP/$name" | cut -d ' ' -f 1)"; fi [ "$expected" = "$actual" ] || fail "Checksum does not match. The download may be damaged; not installing." say "Checksum OK." else say "This release has no checksum list; skipping the check." fi FILE="$TMP/$name" } # ---------- macOS ---------- if [ "$OS" = "Darwin" ]; then url="$(pick "mac-$ARCH\.dmg$")" [ -n "$url" ] || fail "Release $TAG has no macOS build for this Mac ($ARCH) yet." download "$url" mac say "Installing to /Applications..." MNT="$TMP/mnt"; mkdir -p "$MNT" hdiutil attach -nobrowse -quiet -mountpoint "$MNT" "$FILE" pkill -x "$APP" 2>/dev/null || true rm -rf "/Applications/$APP.app" cp -R "$MNT/$APP.app" /Applications/ hdiutil detach -quiet "$MNT" || true # The app isn't notarized by Apple yet, so macOS would block the first launch. Downloaded with # curl it isn't flagged anyway; clear the flag in case, and say so. xattr -dr com.apple.quarantine "/Applications/$APP.app" 2>/dev/null || true say "Installed $APP ${TAG#v} in /Applications." say "It runs in the menu bar. Control+Option+Space starts listening. macOS asks for the microphone the first time." open "/Applications/$APP.app" exit 0 fi [ "$OS" = "Linux" ] || fail "This installer is for macOS and Linux. On Windows, use: irm https://a2tprompt.com/install.ps1 | iex" [ "$ARCH" = "x64" ] || fail "There is no Linux build for $ARCH yet (x64 only)." # ---------- Linux ---------- if [ -z "$MODE" ]; then if command -v apt-get >/dev/null 2>&1 && command -v dpkg >/dev/null 2>&1; then MODE="deb" elif command -v pacman >/dev/null 2>&1; then MODE="pacman" else MODE="appimage"; fi fi case "$MODE" in deb) url="$(pick "linux-x64\.deb$")"; [ -n "$url" ] || fail "Release $TAG has no .deb package yet." download "$url" linux chmod 644 "$FILE" say "Installing with apt (it may ask for your password)..." sudo_run apt-get install -y "$FILE" say "Updates: run this installer again, or download the new .deb." ;; pacman) url="$(pick "linux-x64\.pacman$")"; [ -n "$url" ] || fail "Release $TAG has no Arch package yet." download "$url" linux say "Installing with pacman (it may ask for your password)..." sudo_run pacman -U --noconfirm "$FILE" say "Updates: run this installer again, or download the new package." ;; appimage) url="$(pick "linux-x64\.AppImage$")"; [ -n "$url" ] || fail "Release $TAG has no AppImage yet." download "$url" linux mkdir -p "$APPIMAGE_DIR" "$(dirname "$DESKTOP_FILE")" "$(dirname "$ICON_FILE")" mv "$FILE" "$APPIMAGE_FILE"; chmod +x "$APPIMAGE_FILE" curl -fsSL -o "$ICON_FILE" "https://a2tprompt.com/icon-512.png" 2>/dev/null || true cat > "$DESKTOP_FILE" </dev/null 2>&1 || say "If it doesn't start, install FUSE 2 (Ubuntu: sudo apt install libfuse2t64, Arch: sudo pacman -S fuse2)." ;; esac say "Installed $APP ${TAG#v}. Find it in your applications menu. Ctrl+Alt+Space starts listening." say "Note: Linux can't hide windows from screen recordings, so the prompter will show in recordings."