| 1 | #!/usr/bin/env bash |
| 2 | # Install (or update) the lchat server on this box. |
| 3 | # |
| 4 | # curl -fsSL https://github.com/elevenmessenger/releases/releases/download/server/install.sh | sudo bash |
| 5 | # |
| 6 | # Downloads the latest STABLE release for this machine's architecture from the |
| 7 | # public releases repo, verifies its sha256 against the published checksum, |
| 8 | # installs it at /opt/lchat/lchat, and runs `lchat bootstrap` (idempotent: it |
| 9 | # installs/refreshes the systemd units, creates /data, enables the router and |
| 10 | # the hourly auto-update timer, and installs the public status collectors + |
| 11 | # their viewer pages + 5-minute timers). Re-running this script updates the |
| 12 | # binary and refreshes the units; it never touches /data, so it's safe on a |
| 13 | # live box. |
| 14 | # |
| 15 | # After install, the box keeps itself current from the stable channel — see |
| 16 | # docs/self-hosting.md in the elevenmessenger/messenger repo. |
| 17 | set -euo pipefail |
| 18 | |
| 19 | REPO="${LCHAT_RELEASES_REPO:-elevenmessenger/releases}" |
| 20 | BASE="https://github.com/$REPO/releases/download/server" |
| 21 | |
| 22 | say() { printf '%s\n' "$*"; } |
| 23 | fail() { printf 'install: %s\n' "$*" >&2; exit 1; } |
| 24 | |
| 25 | # Everything runs from main(), invoked on the last line — so a truncated |
| 26 | # `curl | bash` transfer fails to parse and executes NOTHING, instead of |
| 27 | # running whatever prefix happened to arrive. |
| 28 | main() { |
| 29 | |
| 30 | [ "$(id -u)" = 0 ] || fail "must run as root (it installs systemd units and creates the service user) — re-run with sudo" |
| 31 | [ -d /run/systemd/system ] || fail "this box isn't running systemd — lchat's supervision, zero-downtime deploys, and auto-updates are all systemd units (Ubuntu and Debian are the tested platforms)" |
| 32 | [ -f /etc/debian_version ] || say "note: not a Debian-family system — Ubuntu/Debian are what we test on; continuing anyway" |
| 33 | |
| 34 | case "$(uname -m)" in |
| 35 | x86_64) ARCH=amd64 ;; |
| 36 | aarch64) ARCH=arm64 ;; |
| 37 | *) fail "unsupported architecture $(uname -m) — builds are published for x86_64 (amd64) and aarch64 (arm64)" ;; |
| 38 | esac |
| 39 | BIN="lchat-linux-$ARCH" |
| 40 | |
| 41 | TMP="$(mktemp -d)" |
| 42 | trap 'rm -rf "$TMP"' EXIT |
| 43 | |
| 44 | say "Downloading the latest stable lchat ($ARCH)..." |
| 45 | curl -fsSL "$BASE/$BIN" -o "$TMP/$BIN" || fail "download failed — is $BASE/$BIN reachable?" |
| 46 | curl -fsSL "$BASE/$BIN.sha256" -o "$TMP/$BIN.sha256" || fail "checksum download failed" |
| 47 | (cd "$TMP" && sha256sum -c "$BIN.sha256" >/dev/null) || fail "sha256 verification FAILED — refusing to install (a truncated download, or something is tampering with the download path)" |
| 48 | |
| 49 | # Temp + rename on the same filesystem, so a crash mid-install never leaves a |
| 50 | # half-written binary and a re-run always lands atomically over the old one. |
| 51 | mkdir -p /opt/lchat |
| 52 | install -m 0755 "$TMP/$BIN" /opt/lchat/lchat.new |
| 53 | mv /opt/lchat/lchat.new /opt/lchat/lchat |
| 54 | say "Installed $(/opt/lchat/lchat version) at /opt/lchat/lchat" |
| 55 | |
| 56 | say "Running bootstrap (systemd units, /data, router, auto-update timer)..." |
| 57 | /opt/lchat/lchat bootstrap |
| 58 | |
| 59 | cat <<'EOF' |
| 60 | |
| 61 | Done. Next: |
| 62 | |
| 63 | 1. Point a DNS A record at this box, e.g. chat.example.com -> this IP |
| 64 | (ports 80 and 443 must be open — TLS certs issue automatically). |
| 65 | 2. Create your chat: |
| 66 | |
| 67 | lchat add-instance chat.example.com |
| 68 | |
| 69 | It prints a one-click setup link — open it, and you're the admin. |
| 70 | |
| 71 | Add as many chats as you like (each is fully isolated). This box keeps itself |
| 72 | up to date from the stable channel automatically; see `lchat update status`. |
| 73 | Everything that matters lives in /data — back that up. |
| 74 | |
| 75 | Guide: https://github.com/elevenmessenger/releases#readme |
| 76 | EOF |
| 77 | |
| 78 | } |
| 79 | main "$@" |
| 80 | |