#!/bin/sh # tofa native installer — https://get.tofa.tv # # curl -fsSL https://get.tofa.tv | sh # # Downloads the latest beta build for your OS/arch, installs it as a background # service, and points you at http://localhost:33333 to claim the server to your # tofa account. Supports Linux (x86_64 / arm64, systemd) and macOS (Apple # Silicon). For Docker, Windows, or Intel Macs, see: # https://docs.tofa.tv/run-your-server.html # # This is readable on purpose — you're piping it to a shell, so read it first. set -eu DIST_BASE="https://github.com/tofatv/tofa-dist/releases/download/beta" PORT=33333 say() { printf '\033[1;36m==>\033[0m %s\n' "$1"; } warn() { printf '\033[1;33mwarning:\033[0m %s\n' "$1" >&2; } die() { printf '\033[1;31merror:\033[0m %s\n' "$1" >&2; exit 1; } # --- privilege helper (installer touches /opt, systemd, /Applications) ------- SUDO="" if [ "$(id -u)" -ne 0 ]; then if command -v sudo >/dev/null 2>&1; then SUDO="sudo" else die "need root to install a system service — re-run as root, or install sudo." fi fi command -v curl >/dev/null 2>&1 || die "curl is required." # --- detect platform --------------------------------------------------------- OS="$(uname -s)" ARCH="$(uname -m)" case "$OS" in Linux) case "$ARCH" in x86_64|amd64) PLATFORM="linux-x64" ;; aarch64|arm64) PLATFORM="linux-arm64" ;; *) die "unsupported Linux arch '$ARCH' (need x86_64 or aarch64)." ;; esac command -v systemctl >/dev/null 2>&1 || \ die "this installer targets systemd distros. For others, see https://docs.tofa.tv/run-your-server.html" ;; Darwin) case "$ARCH" in arm64) PLATFORM="macos-arm64" ;; *) die "Intel Macs aren't supported natively yet — use Docker: https://docs.tofa.tv/run-your-server.html" ;; esac ;; *) die "unsupported OS '$OS'. See https://docs.tofa.tv/run-your-server.html" ;; esac TARBALL="tofa-beta-${PLATFORM}.tar.gz" URL="${DIST_BASE}/${TARBALL}" say "Installing tofa (beta) for ${PLATFORM}" # --- download + verify checksum ---------------------------------------------- TMP="$(mktemp -d)" trap 'rm -rf "$TMP"' EXIT cd "$TMP" say "Downloading ${TARBALL}" curl -fsSL "$URL" -o "$TARBALL" || die "download failed: $URL" curl -fsSL "${URL}.sha256" -o "sum" || die "checksum download failed." say "Verifying checksum" EXPECTED="$(awk '{print $1}' sum)" if command -v sha256sum >/dev/null 2>&1; then ACTUAL="$(sha256sum "$TARBALL" | awk '{print $1}')" else ACTUAL="$(shasum -a 256 "$TARBALL" | awk '{print $1}')" fi [ "$EXPECTED" = "$ACTUAL" ] || die "checksum mismatch — refusing to install." tar xzf "$TARBALL" SRC="tofa-beta-${PLATFORM}" # --- install ----------------------------------------------------------------- if [ "$OS" = "Darwin" ]; then say "Installing tofa.app + launchd service (you'll be asked for your password)" $SUDO sh "${SRC}/install.sh" else say "Installing to /opt/tofa + systemd service" if ! getent passwd tofa >/dev/null 2>&1; then $SUDO useradd --system --user-group --shell /usr/sbin/nologin \ --home-dir /home/tofa --create-home tofa fi $SUDO mkdir -p /opt/tofa/lib /home/tofa/.tofa /etc/tofa $SUDO cp "${SRC}/tofa" /opt/tofa/tofa [ -f "${SRC}/tofa-updater" ] && $SUDO cp "${SRC}/tofa-updater" /opt/tofa/tofa-updater [ -f "${SRC}/package_info" ] && $SUDO cp "${SRC}/package_info" /opt/tofa/package_info [ -d "${SRC}/lib" ] && $SUDO cp "${SRC}/lib/"* /opt/tofa/lib/ $SUDO chmod 755 /opt/tofa/tofa [ -f /etc/tofa/tofa.env ] || printf '# tofa environment overrides (read by tofa.service)\n' | $SUDO tee /etc/tofa/tofa.env >/dev/null $SUDO cp "${SRC}/systemd/tofa.service" /etc/systemd/system/tofa.service $SUDO chown -R tofa:tofa /opt/tofa /home/tofa/.tofa say "Starting the tofa service" $SUDO systemctl daemon-reload $SUDO systemctl enable tofa.service >/dev/null 2>&1 || true $SUDO systemctl restart tofa.service fi # --- wait for health, then point at the claim page --------------------------- say "Waiting for tofa to come up (first run downloads its database, ~1 min)…" i=0 until curl -fsS "http://localhost:${PORT}/api/v1/health" >/dev/null 2>&1; do i=$((i + 1)) if [ "$i" -gt 150 ]; then warn "tofa didn't answer on :${PORT} within ~2.5 min." [ "$OS" = "Linux" ] && warn "check: sudo journalctl -u tofa -n 50" exit 1 fi sleep 1 done LOCAL="http://localhost:${PORT}" printf '\n\033[1;32mtofa is running.\033[0m\n' printf 'Open \033[1;36m%s\033[0m and sign in to claim this server to your account.\n' "$LOCAL" [ "$OS" = "Darwin" ] && command -v open >/dev/null 2>&1 && open "$LOCAL" 2>/dev/null || true [ "$OS" = "Linux" ] && command -v xdg-open >/dev/null 2>&1 && xdg-open "$LOCAL" >/dev/null 2>&1 || true