#!/bin/sh # Install Tavsin on macOS or Linux: # # curl -fsSL https://www.tavsin.xyz/install.sh | sh # # Downloads this release's installer for your system from www.tavsin.xyz, # checks its SHA-256 against https://www.tavsin.xyz/downloads/checksums.txt, # and installs it: # macOS Tavsin.app into /Applications (or ~/Applications if that is not # writable). No sudo. # Linux the AppImage into ~/.local/share/tavsin, linked as ~/.local/bin/tavsin. # No sudo. Pass --deb to install the .deb with apt instead (asks for # sudo): curl -fsSL https://www.tavsin.xyz/install.sh | sh -s -- --deb # # Settings: TAVSIN_APP_DIR (macOS destination), TAVSIN_HOME (Linux prefix, # default ~/.local). set -eu BASE="${TAVSIN_BASE_URL:-https://www.tavsin.xyz}" FORMAT=appimage for arg in "$@"; do case "$arg" in --deb) FORMAT=deb ;; --appimage) FORMAT=appimage ;; -h|--help) sed -n '2,18p' "$0" 2>/dev/null || true; exit 0 ;; *) printf 'tavsin install: unknown option %s\n' "$arg" >&2; exit 2 ;; esac done say() { printf '%s\n' "$*"; } fail() { printf 'tavsin install: %s\n' "$*" >&2; exit 1; } need() { command -v "$1" >/dev/null 2>&1 || fail "this needs $1, which is not installed"; } need curl need uname tmp=$(mktemp -d 2>/dev/null || mktemp -d -t tavsin) mnt="" cleanup() { if [ -n "$mnt" ]; then hdiutil detach -quiet "$mnt" >/dev/null 2>&1 || true; fi rm -rf "$tmp" } trap cleanup EXIT INT TERM sha256_of() { if command -v shasum >/dev/null 2>&1; then shasum -a 256 "$1" | cut -d' ' -f1 elif command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | cut -d' ' -f1 else fail "this needs shasum or sha256sum to check the download"; fi } # One line of checksums.txt whose file name matches the pattern. pick() { grep -E "^[0-9a-f]{64} $1\$" "$tmp/sums" | head -n 1 || true } fetch() { # $1 route under /downloads, $2 checksum line want=$(printf '%s' "$2" | cut -d' ' -f1) file=$(printf '%s' "$2" | cut -d' ' -f3) say "Downloading $file" curl -fL --progress-bar "$BASE/downloads/$1" -o "$tmp/$file" || fail "download failed" got=$(sha256_of "$tmp/$file") [ "$got" = "$want" ] || fail "checksum mismatch for $file (expected $want, got $got); nothing was installed" say "Checksum matches." path="$tmp/$file" } os=$(uname -s) arch=$(uname -m) curl -fsSL "$BASE/downloads/checksums.txt" -o "$tmp/sums" || fail "could not read $BASE/downloads/checksums.txt" version=$(sed -n 's/^# Tavsin \([^ ]*\).*/\1/p' "$tmp/sums" | head -n 1) say "Tavsin ${version:-(latest)}" case "$os" in Darwin) need hdiutil # A shell running under Rosetta reports x86_64 on Apple Silicon. if [ "$arch" = "arm64" ] || [ "$(sysctl -n sysctl.proc_translated 2>/dev/null || echo 0)" = "1" ]; then line=$(pick 'Tavsin-[0-9][0-9A-Za-z.]*-arm64\.dmg'); route=mac else line=$(pick 'Tavsin-[0-9][0-9A-Za-z.]*\.dmg'); route=mac-intel fi [ -n "$line" ] || fail "this release has no installer for macOS on $arch" fetch "$route" "$line" mnt="$tmp/mnt" mkdir -p "$mnt" hdiutil attach -quiet -nobrowse -readonly -mountpoint "$mnt" "$path" || { mnt=""; fail "could not open the disk image"; } app=$(find "$mnt" -maxdepth 1 -name '*.app' | head -n 1) [ -n "$app" ] || fail "the disk image holds no app" dest="${TAVSIN_APP_DIR:-/Applications}" if [ -z "${TAVSIN_APP_DIR:-}" ] && [ ! -w "$dest" ]; then dest="$HOME/Applications"; fi mkdir -p "$dest" name=$(basename "$app") if [ -e "$dest/$name" ]; then pgrep -xq Tavsin 2>/dev/null && fail "Tavsin is running; quit it and run this again" rm -rf "$dest/$name" fi cp -R "$app" "$dest/" say "Installed $dest/$name" say "Open it from Launchpad or with: open \"$dest/$name\"" ;; Linux) case "$arch" in x86_64|amd64) ;; *) fail "Tavsin for Linux is built for x86_64; this machine is $arch" ;; esac if [ "$FORMAT" = deb ]; then need apt-get line=$(pick 'tavsin_[0-9][0-9A-Za-z.]*_amd64\.deb') [ -n "$line" ] || fail "this release has no .deb" fetch linux-deb "$line" chmod 644 "$path" if [ "$(id -u)" = 0 ]; then apt-get install -y "$path"; else need sudo; sudo apt-get install -y "$path"; fi say "Installed. Run it with: tavsin" else line=$(pick 'Tavsin-[0-9][0-9A-Za-z.]*\.AppImage') [ -n "$line" ] || fail "this release has no AppImage" fetch linux "$line" prefix="${TAVSIN_HOME:-$HOME/.local}" mkdir -p "$prefix/share/tavsin" "$prefix/bin" install -m 755 "$path" "$prefix/share/tavsin/Tavsin.AppImage" ln -sf "$prefix/share/tavsin/Tavsin.AppImage" "$prefix/bin/tavsin" if [ -d "$HOME/.local/share/applications" ] || [ -z "${TAVSIN_HOME:-}" ]; then mkdir -p "$prefix/share/applications" cat > "$prefix/share/applications/tavsin.desktop" </dev/null | grep -q 'libfuse\.so\.2'); then say "AppImages need FUSE 2. On Debian or Ubuntu: sudo apt install libfuse2 (or libfuse2t64)." fi fi ;; *) fail "unsupported system $os. On Windows, run in PowerShell: irm $BASE/install.ps1 | iex" ;; esac