#!/bin/sh # Install Hotline from its latest GitHub release. # # curl -fsSL https://hotline.dev/install | sh the desktop app # curl -fsSL https://hotline.dev/install | sh -s -- --server the desk with no window # curl -fsSL https://hotline.dev/install | sh -s -- --server --relay # a relay only, for a Raspberry Pi say: no agents # # Server options, asked for when they are missing and a terminal is attached: # --listen IP:PORT one local address and a fixed port # --public-url https://HOST:PORT where phones reach the desk # --browser a web browser for teammates without a computer: # WebKitGTK, Xvfb and fonts, about 500 MB (apt only; # offered on a first install at a terminal) # A server installed with --relay stays a relay, and one without it keeps its # agents: a re-run says how to change which it is and stops. # And, on a first install of a full server: # --user NAME run the desk as this user, with their HOME and their # claude, codex and logins (default: whoever ran the # installer or sudo; as root alone, the one person's # account here, else the hotline service account; # --user hotline asks for the service account) # Either mode takes --version X.Y.Z, --yes (skip confirmation), and --force # (reinstall even the same version). For future server updates: sudo hotline update. # # Windows: irm https://hotline.dev/install.ps1 | iex # Docs: https://hotline.dev/docs/ # Everything is in functions and runs from the last line, so a download cut # short runs nothing. RELEASES=https://github.com/1broseidon/hotline/releases UNIT=/etc/systemd/system/hotline.service ROOM=/var/lib/hotline/room BINARY=/usr/local/bin/hotline say() { printf '%s\n' "$*"; } fail() { printf 'hotline: %s\n' "$*" >&2 exit 1 } need() { command -v "$1" >/dev/null 2>&1 || fail "this needs $1"; } fetch() { curl --proto '=https' --tlsv1.2 -fsSL -o "$2" "$1" || fail "could not download $1" } # Root runs commands itself; anyone else asks sudo. as_root() { if [ "$(id -u)" -eq 0 ]; then "$@"; else sudo "$@"; fi } # The user the unit runs the desk as: hotline, unless a drop-in changed it # (User=agent, to reach a signed-in CLI), and then only that user can read the room. # Whether the installed unit serves only a relay. agents,relay is a full server. unit_is_relay() { grep -Eq '^ExecStart=.* --capabilities relay( |$)' "$UNIT" } desk_user() { user=$(systemctl show -p User --value hotline 2>/dev/null || true) echo "${user:-hotline}" } as_desk() { if [ "$(id -u)" -eq 0 ]; then runuser -u "$(desk_user)" -- env HOTLINE_DATA_DIR="$ROOM" "$@" else sudo -u "$(desk_user)" env HOTLINE_DATA_DIR="$ROOM" "$@" fi } # Who runs the desk on a first install, in run_user (empty for the hotline # service account) and why, in run_because. The user asked for, else the person # installing: whoever ran the installer, or whoever ran sudo. They installed # claude and codex and signed in to them as themselves, and a desk under another # account can see neither their CLIs nor their logins. Root with nobody behind # it (a fresh VPS) gets the one person's account here if there is exactly one, # and the service account otherwise. The desk never runs as root. pick_user() { run_user= run_because= if [ -n "$run_as" ]; then run_user=$run_as elif [ "$(id -u)" -ne 0 ]; then run_user=$(id -un) run_because="who ran the installer" elif [ -n "${SUDO_USER:-}" ] && [ "$SUDO_USER" != root ]; then run_user=$SUDO_USER run_because="who ran sudo" else run_user=$(only_person) run_because="the only person's account here; the desk never runs as root" fi case "$run_user" in "" | hotline) run_user= return 0 ;; root) fail "the desk does not run as root; name the user whose claude and codex it should use" ;; esac printf '%s\n' "$run_user" | grep -Eq '^[A-Za-z_][A-Za-z0-9._-]*$' || fail "$run_user is not a user name" id -u "$run_user" >/dev/null 2>&1 || fail "there is no user $run_user on this machine" } # The one person with a login on this machine: a regular account (uid 1000 to # 59999) with a shell and a home. Prints nothing when there are none or several. only_person() { found= count=0 for person in $(getent passwd 2>/dev/null | awk -F: '$3 >= 1000 && $3 < 60000 && $7 !~ /(nologin|false)$/ { print $1 ":" $6 }'); do if [ -d "${person#*:}" ]; then found=${person%%:*} count=$((count + 1)) fi done if [ "$count" -eq 1 ]; then echo "$found" fi } # Edits the unit in place with sed expressions. A suffix joined to -i is the # one in-place form GNU and BSD sed both read; the copy it leaves is removed. edit_unit() { as_root sed -i.edit "$@" "$UNIT" as_root rm -f "$UNIT.edit" } # Points the unit just installed at another account: its user and group, its # HOME, and a PATH that starts where that person keeps their CLIs. Anything # else the person needs on PATH goes in with: sudo systemctl edit hotline. run_unit_as() { unit_path="$3/.local/bin:$3/.npm-global/bin:/usr/local/bin:/usr/bin:/bin" edit_unit \ -e "s|^User=.*|User=$1|" \ -e "s|^Group=.*|Group=$2|" \ -e "s|^Environment=HOME=.*|Environment=HOME=$3|" \ -e "s|^Environment=PATH=.*|Environment=PATH=$unit_path|" for line in "User=$1" "Group=$2" "Environment=HOME=$3" "Environment=PATH=$unit_path"; do grep -qxF "$line" "$UNIT" || fail "could not set $line in $UNIT" done } # Reads an answer from the terminal even though the script is on stdin. ask() { printf '%s [%s]: ' "$1" "$2" >/dev/tty read -r answer /dev/null; } latest_version() { fetch "$RELEASES/latest/download/latest.json" "$work/latest.json" sed -n 's/^ *"version": *"\([^"]*\)".*/\1/p' "$work/latest.json" | head -n 1 } sha256() { if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | cut -d ' ' -f 1 else shasum -a 256 "$1" | cut -d ' ' -f 1 fi } # Downloads one release asset into $work and checks it against checksums.txt. asset() { base="$RELEASES/download/desktop-v$version" [ -f "$work/checksums.txt" ] || fetch "$base/checksums.txt" "$work/checksums.txt" expected=$(awk -v f="$1" '$2 == f { print $1 }' "$work/checksums.txt") [ -n "$expected" ] || fail "release $version has no $1" say "Downloading $1" fetch "$base/$1" "$work/$1" [ "$(sha256 "$work/$1")" = "$expected" ] || fail "$1 does not match its checksum" } arch() { case "$(uname -m)" in x86_64 | amd64) echo x86_64 ;; aarch64 | arm64) echo aarch64 ;; *) fail "no Hotline build for $(uname -m)" ;; esac } # Never launch a desktop app to ask its version. Packages and app bundles carry # metadata; older standalone installs may have no readable version at all. installed_version() { installed= current= if [ "$mode" = server ]; then if [ -f "$BINARY" ] || [ -f "$UNIT" ]; then installed=1 if [ -x "$BINARY" ]; then current=$("$BINARY" --version 2>/dev/null | sed -n 's/^[Hh]otline \([0-9][^ ]*\)$/\1/p' | head -n 1) fi # Releases before --version exposed the running version in door.json. # Do not ask for sudo or contact a desk merely to detect an install. if [ -z "$current" ] && [ -r "$ROOM/door.json" ]; then pid=$(sed -n 's/.*"pid": *\([0-9][0-9]*\).*/\1/p' "$ROOM/door.json" | head -n 1) # A stale door, or an older process after binary replacement, is # not evidence of the version currently installed on disk. if [ -n "$pid" ] && [ "$BINARY" -ef "/proc/$pid/exe" ]; then current=$(sed -n 's/.*"version": *"\([^" ]*\)".*/\1/p' "$ROOM/door.json" | head -n 1) fi fi fi else case "$(uname -s)" in Darwin) target=/Applications [ -w "$target" ] || target="$HOME/Applications" app="$target/Hotline.app" if [ ! -d "$app" ] && [ -d /Applications/Hotline.app ]; then app=/Applications/Hotline.app fi if [ ! -d "$app" ] && [ -d "$HOME/Applications/Hotline.app" ]; then app="$HOME/Applications/Hotline.app" fi if [ -d "$app" ]; then installed=1 current=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "$app/Contents/Info.plist" 2>/dev/null || true) fi ;; Linux) if command -v dpkg-query >/dev/null 2>&1; then current=$(dpkg-query -W -f='${Status} ${Version}\n' hotline 2>/dev/null | sed -n 's/^install ok installed //p') # Debian epochs/revisions describe packaging, not the app. current=${current#*:} current=$(printf '%s\n' "$current" | sed 's/-[0-9][^-]*$//') fi if [ -z "$current" ] && command -v rpm >/dev/null 2>&1; then current=$(rpm -q --qf '%{VERSION}' hotline 2>/dev/null) || current= fi if [ -n "$current" ]; then installed=1 elif [ -f "$HOME/.local/bin/Hotline.AppImage" ]; then installed=1 if [ -r "$HOME/.local/bin/Hotline.AppImage.version" ]; then # The app's own updater can replace the binary without this # marker. Only trust a version bound to these exact bytes. marker="$HOME/.local/bin/Hotline.AppImage.version" recorded_hash=$(sed -n '2p' "$marker") if [ -n "$recorded_hash" ] && [ "$recorded_hash" = "$(sha256 "$HOME/.local/bin/Hotline.AppImage")" ]; then current=$(sed -n '1p' "$marker") fi fi fi ;; esac fi current=${current#v} [ -n "$current" ] || current=unknown } confirm_install() { installed_version if [ -n "$installed" ]; then say "Hotline $current is installed; $version is available." if [ "$current" = "$version" ] && [ -z "$force" ]; then say "Already up to date. Use --force to reinstall." return 1 fi else say "Hotline $version is available." return 0 fi if [ -z "$yes" ] && has_tty; then ask "Install Hotline $version? (y/N)" N case "$answer" in y | Y | yes | YES | Yes) ;; *) say "Not installed; nothing changed."; return 1 ;; esac fi } desktop_macos() { machine=$(arch) # A shell under Rosetta reports x86_64 on Apple silicon. [ "$(sysctl -n sysctl.proc_translated 2>/dev/null)" = 1 ] && machine=aarch64 file="hotline_${version}_macos_${machine}.app.tar.gz" asset "$file" tar -xzf "$work/$file" -C "$work" [ -d "$work/Hotline.app" ] || fail "$file has no Hotline.app" target=/Applications [ -w "$target" ] || target="$HOME/Applications" mkdir -p "$target" rm -rf "$target/Hotline.app" mv "$work/Hotline.app" "$target/Hotline.app" xattr -dr com.apple.quarantine "$target/Hotline.app" 2>/dev/null || true say "" say "Hotline $version is in $target. Open it with: open -a Hotline" } desktop_linux() { package="hotline_${version}_linux_$(arch)" if command -v apt-get >/dev/null 2>&1 && command -v dpkg >/dev/null 2>&1; then asset "${package}.deb" # apt reads a local package as its own sandbox user. chmod 0755 "$work" chmod 0644 "$work/${package}.deb" if [ -n "$force" ]; then as_root apt-get install --reinstall -y "$work/${package}.deb" else as_root apt-get install -y "$work/${package}.deb" fi elif command -v dnf >/dev/null 2>&1; then asset "${package}.rpm" if [ -n "$force" ] && [ "$current" = "$version" ]; then as_root dnf reinstall -y "$work/${package}.rpm" else as_root dnf install -y "$work/${package}.rpm" fi elif command -v zypper >/dev/null 2>&1; then asset "${package}.rpm" if [ -n "$force" ]; then as_root zypper --non-interactive install --force --allow-unsigned-rpm "$work/${package}.rpm" else as_root zypper --non-interactive install --allow-unsigned-rpm "$work/${package}.rpm" fi else asset "${package}.AppImage" mkdir -p "$HOME/.local/bin" install -m 0755 "$work/${package}.AppImage" "$HOME/.local/bin/Hotline.AppImage" printf '%s\n%s\n' "$version" "$(sha256 "$HOME/.local/bin/Hotline.AppImage")" >"$HOME/.local/bin/Hotline.AppImage.version" say "" say "Hotline $version is at ~/.local/bin/Hotline.AppImage." say "The tray needs libayatana-appindicator3 from your package manager." return fi say "" say "Hotline $version is installed. Open it from your applications menu, or run hotline-app." } # The address this host reaches the internet from: a good first guess for # both the listen address and the one phones connect to. host_address() { ip -4 route get 1.1.1.1 2>/dev/null | sed -n 's/.* src \([0-9.]*\).*/\1/p' | head -n 1 } # What hotline-browser, the teammates' browser on a server, runs on: # WebKitGTK, the private X display it draws on, and fonts for Chinese, # Japanese and Korean, emoji and the common web faces. Debian and Ubuntu name # them alike, on x86_64 and ARM. BROWSER_PACKAGES="libwebkit2gtk-4.1-0 xvfb fonts-wqy-microhei fonts-noto-color-emoji fonts-liberation2" # The desk is installed but the browser helper is not beside it. helper_missing() { [ -x /usr/local/bin/hotline ] && [ ! -x /usr/local/bin/hotline-browser ] } browser_packages() { if command -v apt-get >/dev/null 2>&1; then say "Installing the browser's packages: $BROWSER_PACKAGES" as_root apt-get update -q # shellcheck disable=SC2086 # one word per package as_root env DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends $BROWSER_PACKAGES else say "For the teammates' browser, install WebKitGTK 4.1, Xvfb and fonts with your" say "package manager (Debian and Ubuntu: $BROWSER_PACKAGES)," say "then: sudo systemctl restart hotline" fi } server() { [ "$(uname -s)" = Linux ] || fail "the server install is for Linux with systemd; see https://hotline.dev/docs/server/" command -v systemctl >/dev/null 2>&1 || fail "the server install needs systemd; see https://hotline.dev/docs/server/install/" [ "$(id -u)" -eq 0 ] || need sudo fresh=1 [ -f "$UNIT" ] && fresh= # Who runs the desk is chosen once, at the first install. Moving an # installed desk to another user means moving its room, which is not for # an installer to do unasked, and sudo's name is no reason to. # A re-run never changes what the server is. Turning a relay into a full # server opens a new room, and turning a full server into a relay shuts # its teammates out; each is a deliberate edit of the unit, not a flag # left off or added to an update. if [ -z "$fresh" ] && unit_is_relay && [ -z "$relay" ]; then fail "this server runs only a relay; update it with --relay, or to run agents there too see https://hotline.dev/docs/server/relay/#run-agents-there-later" fi if [ -z "$fresh" ] && ! unit_is_relay && [ -n "$relay" ]; then fail "this server runs agents, and --relay would leave them unreachable; update it without --relay, or change its unit's --capabilities by hand" fi # A relay runs no teammates, so it has no one's CLIs to reach and runs as # the hotline service account. run_user= if [ -n "$relay" ] && [ -n "$browser" ]; then fail "a relay runs no teammates, so it has no browser; leave out --browser" fi if [ -n "$relay" ] && [ -n "$run_as" ]; then fail "a relay runs no agents and runs as the hotline service account; leave out --user" elif [ -n "$fresh" ] && [ -z "$relay" ]; then pick_user elif [ -z "$fresh" ] && [ -n "$run_as" ]; then fail "the desk is already installed and runs as $(desk_user); --user is for a first install (see https://hotline.dev/docs/server/ to move one)" fi if [ -n "$run_user" ]; then run_home=$(getent passwd "$run_user" | cut -d: -f6) run_group=$(id -gn "$run_user") case "$run_home" in /?*) ;; *) fail "$run_user has no home folder" ;; esac [ -d "$run_home" ] || fail "$run_user's home $run_home does not exist" printf '%s\n' "$run_home" | grep -Eq '^/[A-Za-z0-9._/+-]+$' || fail "$run_user's home $run_home has characters the unit cannot carry" printf '%s\n' "$run_group" | grep -Eq '^[A-Za-z_][A-Za-z0-9._-]*$' || fail "$run_user's group $run_group is not a group name" say "The desk will run as $run_user${run_because:+ ($run_because)}, with their home and their installed CLIs and logins." say "For a separate service account instead, run again with --user hotline." fi # The browser is opt-in: asked for, or offered once, on a first full # install at a terminal. if [ -n "$fresh" ] && [ -z "$relay" ] && [ -z "$browser" ] && has_tty; then ask "Give teammates without a computer a web browser? It installs WebKitGTK and Xvfb, about 500 MB (y/N)" N case "$answer" in [Yy]*) browser=1 ;; esac fi machine=$(arch) dir="hotline-server_${version}_linux_${machine}" asset "$dir.tar.gz" tar -xzf "$work/$dir.tar.gz" -C "$work" if [ -n "$fresh" ] || [ -n "$listen$public_url" ]; then guess=$(host_address) if [ -z "$listen" ]; then has_tty || fail "pass --listen IP:PORT (and --public-url) when no terminal is attached" ask "Listen on" "${guess:-127.0.0.1}:9443" listen=$answer fi if [ -z "$public_url" ]; then has_tty || fail "pass --public-url https://HOST:PORT when no terminal is attached" port=${listen##*:} ask "Phones connect to" "https://${guess:-${listen%:*}}:$port" public_url=$answer fi fi as_root install -m 0755 "$work/$dir/hotline" /usr/local/bin/hotline # The browser helper always goes beside it; without its packages it is # never started, and the desk offers no browser. if [ -f "$work/$dir/hotline-browser" ]; then as_root install -m 0755 "$work/$dir/hotline-browser" /usr/local/bin/hotline-browser fi [ -z "$browser" ] || browser_packages if [ -n "$run_user" ]; then # The room stays where `hotline pair` and `status` look for it. Its # parent is open to enter and the room itself is the user's alone. as_root install -d -m 0755 /var/lib/hotline as_root install -d -o "$run_user" -g "$run_group" -m 0700 "$ROOM" elif ! id hotline >/dev/null 2>&1; then nologin=$(command -v nologin || echo /usr/sbin/nologin) as_root useradd --system --create-home --home-dir /var/lib/hotline --shell "$nologin" hotline fi unit_file=hotline.service capabilities= if [ -n "$relay" ]; then # Installed under hotline.service all the same, the name pair, status # and update look for. unit_file=hotline-relay.service capabilities="--capabilities relay " fi if [ -n "$fresh" ]; then as_root install -m 0644 "$work/$dir/$unit_file" "$UNIT" if [ -n "$run_user" ]; then run_unit_as "$run_user" "$run_group" "$run_home" fi fi if [ -z "$fresh" ] && [ -n "$listen" ]; then as_root cp "$UNIT" "$UNIT.previous" fi if [ -n "$listen" ]; then exec_start="ExecStart=/usr/local/bin/hotline serve --store file $capabilities--listen $listen --public-url $public_url" edit_unit -e '/^# Replace this documentation address/d' \ -e "s|^ExecStart=.*|$exec_start|" fi as_root systemctl daemon-reload if [ -n "$fresh" ]; then as_root systemctl enable --now hotline else as_root systemctl restart hotline fi tries=0 until as_desk /usr/local/bin/hotline status >/dev/null 2>&1; do tries=$((tries + 1)) if [ "$tries" -ge 20 ] || ! as_root systemctl is-active --quiet hotline; then as_root journalctl -u hotline -n 20 --no-pager >&2 || true if [ -f "$UNIT.previous" ]; then as_root mv "$UNIT.previous" "$UNIT" as_root systemctl daemon-reload as_root systemctl restart hotline || true fail "the desk did not start with those settings, so the previous unit is back; the log is above" fi fail "the desk did not start; the log is above, the unit is $UNIT" fi sleep 1 done say "" as_desk /usr/local/bin/hotline status || true say "" say "Next time, update with: sudo hotline update (or sudo hotline update --check)" if [ -z "$fresh" ]; then as_root rm -f "$UNIT.previous" say "Hotline $version is running, with the same room and pairings." return fi if [ -n "$relay" ]; then say "Open the port for your desktop and phones and nothing else." say "" if has_tty; then as_desk /usr/local/bin/hotline pair --link /dev/null 2>&1; then as_root systemctl restart hotline say "The browser is added and the desk restarted. Check: journalctl -u hotline | grep Browser:" fi fi return 0 fi case "$mode" in server) server ;; desktop) case "$(uname -s)" in Darwin) desktop_macos ;; Linux) desktop_linux ;; *) fail "on Windows, run: irm https://hotline.dev/install.ps1 | iex" ;; esac ;; esac } main "$@"