#!/usr/bin/env bash # tsplay installer — builds the terminal Jellyfin player from source and drops # the binary in ~/.local/bin. On Arch/Omarchy it installs the dependencies it # needs (mpv at run-time, go at build-time) via pacman; on other distros it # falls back to telling you what to install. set -euo pipefail REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" BIN_DIR="${HOME}/.local/bin" BIN="${BIN_DIR}/tsplay" bold() { printf '\033[1m%s\033[0m\n' "$1"; } warn() { printf '\033[33m%s\033[0m\n' "$1" >&2; } err() { printf '\033[31m%s\033[0m\n' "$1" >&2; } # pkg_for maps a required command to its Arch package name (same here, but kept # explicit so it's obvious what gets installed). pkg_for() { case "$1" in go) echo "go" ;; mpv) echo "mpv" ;; *) echo "$1" ;; esac } # ensure_dep makes sure a command exists, installing it via pacman on Arch if # missing. $2 = "build" or "run" just tweaks the wording. ensure_dep() { local cmd="$1" kind="$2" pkg command -v "$cmd" >/dev/null 2>&1 && return 0 pkg="$(pkg_for "$cmd")" if command -v pacman >/dev/null 2>&1; then bold "Installing missing ${kind} dependency: ${pkg}" sudo pacman -S --needed --noconfirm "$pkg" else err "Missing ${kind} dependency '${cmd}'. Install the '${pkg}' package and re-run." exit 1 fi } # Build-time and run-time deps. mpv is the only thing tsplay needs at run time; # everything else is compiled into the Go binary. ensure_dep go build ensure_dep mpv run bold "Building tsplay…" cd "$REPO_DIR" mkdir -p "$BIN_DIR" go build -o "$BIN" ./cmd/tsplay bold "Installed: $BIN" case ":$PATH:" in *":$BIN_DIR:"*) ;; *) warn "Note: $BIN_DIR is not on your PATH. Add it to use 'tsplay' directly." ;; esac echo "Run 'tsplay' to sign in to your Jellyfin server (it auto-detects LAN servers)."