#!/usr/bin/env bash # StreamZH - one app for your whole media pipeline. # Copyright (c) 2026 The StreamZH Authors. # SPDX-License-Identifier: GPL-3.0-only # # Installs or updates StreamZH with one command: # # Linux: curl -fsSL https://streamzh.com/install.sh | sudo bash # macOS: curl -fsSL https://streamzh.com/install.sh | bash # # What it does: picks the right package for this system (.deb, .rpm or .tar.gz on Linux, x64 or arm64; the zip on # macOS), downloads the current release from GitHub, checks it against the release's SHA256SUMS, installs it and # starts StreamZH. Running it again updates StreamZH; settings and data stay. Nothing else is changed or sent. # Read it first if you like: https://streamzh.com/install.sh set -euo pipefail # Everything runs from main at the very end, so a download that breaks off half way does nothing. STREAMZH_SITE="${STREAMZH_SITE:-https://streamzh.com}" PORT=9797 say() { printf '\033[1;31m==>\033[0m \033[1m%s\033[0m\n' "$*"; } info() { printf ' %s\n' "$*"; } fail() { printf '\033[1;31mError:\033[0m %s\n' "$*" >&2; exit 1; } need() { command -v "$1" >/dev/null 2>&1 || fail "$1 is needed but not installed."; } # Downloads $1 (a /download/ address on the site) into $2 and prints the release file name. # The site only redirects to the release on GitHub; anything else is refused. fetch() { local url url=$(curl -fsS --retry 3 -o /dev/null -w '%{redirect_url}' "$STREAMZH_SITE/download/$1") \ || fail "Could not reach $STREAMZH_SITE/download/$1" case "$url" in https://github.com/StreamZH/StreamZH/releases/download/*) ;; *) fail "Unexpected download address for $1: ${url:-none}" ;; esac curl -fsSL --proto-redir '=https' --retry 3 -o "$2" "$url" || fail "Download failed: $url" basename "$url" } # Checks $1 (path) whose release name is $2 against SHA256SUMS in the same folder. verify() { local expected actual expected=$(awk -v f="$2" '$2 == f || $2 == "*" f { print $1 }' "$(dirname "$1")/SHA256SUMS") [ -n "$expected" ] || fail "$2 is not listed in SHA256SUMS." if command -v sha256sum >/dev/null 2>&1; then actual=$(sha256sum "$1" | awk '{ print $1 }') else actual=$(shasum -a 256 "$1" | awk '{ print $1 }') fi [ "$expected" = "$actual" ] || fail "Checksum mismatch for $2. Nothing was installed." info "Checksum OK ($2)" } wait_for_streamzh() { local _ for _ in $(seq 1 60); do if curl -fs -o /dev/null "http://127.0.0.1:$PORT/health"; then return 0; fi sleep 1 done return 1 } install_linux() { local arch="$1" tmp="$2" root="" target file kind if [ "$(id -u)" -ne 0 ]; then command -v sudo >/dev/null 2>&1 || fail "Run this as root: curl -fsSL $STREAMZH_SITE/install.sh | sudo bash" root="sudo" fi if command -v apt-get >/dev/null 2>&1 && command -v dpkg >/dev/null 2>&1; then kind=deb; target="linux-deb" elif command -v dnf >/dev/null 2>&1 || command -v yum >/dev/null 2>&1 || command -v zypper >/dev/null 2>&1; then kind=rpm; target="linux-rpm" else kind=tar; target="linux" fi if [ "$arch" = arm64 ]; then target="$target-arm64"; fi say "Downloading StreamZH for Linux ($arch, .$kind)" fetch checksums "$tmp/SHA256SUMS" >/dev/null file=$(fetch "$target" "$tmp/package") mv "$tmp/package" "$tmp/$file" verify "$tmp/$file" "$file" info "Version: $(printf '%s' "$file" | sed -E 's/^[Ss]tream[Zz][Hh][-_]//; s/(_amd64|_arm64)?\.(deb|rpm)$//; s/\.(x86_64|aarch64)$//; s/-linux-(x64|arm64)\.tar\.gz$//')" say "Installing" chmod 0755 "$tmp"; chmod 0644 "$tmp/$file" case "$kind" in deb) $root env DEBIAN_FRONTEND=noninteractive apt-get install -y -q "$tmp/$file" ;; rpm) if command -v dnf >/dev/null 2>&1; then $root dnf install -y "$tmp/$file" elif command -v zypper >/dev/null 2>&1; then $root zypper --non-interactive install --allow-unsigned-rpm "$tmp/$file" else $root yum install -y "$tmp/$file"; fi ;; tar) tar -xzf "$tmp/$file" -C "$tmp" $root bash "$(find "$tmp" -maxdepth 2 -name install-linux.sh | head -n 1)" ;; esac if [ ! -d /run/systemd/system ]; then say "Installed. systemd is not running here, so StreamZH was not started." info "Start it with: sudo -H -u streamzh env STREAMZH_DATA=/var/lib/streamzh /opt/streamzh/StreamZH" return 0 fi say "Starting StreamZH" if ! wait_for_streamzh; then info "StreamZH did not answer yet. See: sudo journalctl -u streamzh -n 50" return 0 fi local ip code ip=$(hostname -I 2>/dev/null | awk '{ print $1 }') code=$($root cat /var/lib/streamzh/setup-code 2>/dev/null || true) echo say "StreamZH is running." info "Open: http://${ip:-}:$PORT" if [ -n "$code" ]; then info "Setup code: $code" info "(The setup page asks for it once, to create the owner account.)" fi info "Give StreamZH access to your media, for example:" info " sudo setfacl -R -m u:streamzh:rwX -m d:u:streamzh:rwX /data/media /data/downloads" } install_macos() { local arch="$1" tmp="$2" target file dest="$HOME/Applications/StreamZH" [ "$(id -u)" -ne 0 ] || fail "On macOS run it without sudo: curl -fsSL $STREAMZH_SITE/install.sh | bash" target=macos if [ "$arch" = x64 ]; then target=macos-intel; fi say "Downloading StreamZH for macOS ($arch)" fetch checksums "$tmp/SHA256SUMS" >/dev/null file=$(fetch "$target" "$tmp/package") mv "$tmp/package" "$tmp/$file" verify "$tmp/$file" "$file" say "Installing to $dest" if pgrep -f "$dest/StreamZH" >/dev/null 2>&1; then info "Stopping the running StreamZH" pkill -f "$dest/StreamZH" || true sleep 2 fi need unzip unzip -q "$tmp/$file" -d "$tmp/unpacked" mkdir -p "$HOME/Applications" rm -rf "$dest" mv "$tmp/unpacked/StreamZH" "$dest" xattr -dr com.apple.quarantine "$dest" 2>/dev/null || true say "Starting StreamZH" mkdir -p "$HOME/Library/Logs" nohup "$dest/StreamZH" >"$HOME/Library/Logs/StreamZH.log" 2>&1 & if wait_for_streamzh; then open "http://localhost:$PORT" 2>/dev/null || true echo say "StreamZH is running: http://localhost:$PORT" info "Create the owner account in the browser that just opened." else info "StreamZH did not answer yet. Log: ~/Library/Logs/StreamZH.log" fi info "Start it again later with: $dest/StreamZH" info "Media info needs ffmpeg, for example: brew install ffmpeg" } main() { need curl local os arch os=$(uname -s) case "$(uname -m)" in x86_64|amd64) arch=x64 ;; aarch64|arm64) arch=arm64 ;; *) fail "StreamZH runs on x64 and arm64; this is $(uname -m)." ;; esac STREAMZH_TMP=$(mktemp -d) trap 'rm -rf "${STREAMZH_TMP:-}"' EXIT case "$os" in Linux) install_linux "$arch" "$STREAMZH_TMP" ;; Darwin) install_macos "$arch" "$STREAMZH_TMP" ;; *) fail "This script is for Linux and macOS. On Windows run in PowerShell: irm $STREAMZH_SITE/install.ps1 | iex" ;; esac } main "$@"