From 4057f6baa61fae80b8559b7804b1a69d7f289cda Mon Sep 17 00:00:00 2001 From: Adeel Ahmad Date: Sat, 10 Oct 2026 16:34:51 +0000 Subject: [PATCH] feat(install): list the prerequisites and ask before installing them At a terminal, install.sh now says what it will install (Docker or OrbStack, Homebrew, microsandbox, the KVM module and access, the Compose plugin) and asks once; without a terminal, or with LENS_YES=1, it goes ahead as before. It also installs Homebrew on a Mac that has none, loads the KVM module when /dev/kvm is missing, and installs a missing Compose plugin with apt or dnf. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01VvAGWoQxiwkGkk374pvkSh --- docs/get-started.md | 4 ++- install.sh | 64 ++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 63 insertions(+), 5 deletions(-) diff --git a/docs/get-started.md b/docs/get-started.md index 7cd8a1be3..aa5eb5fc5 100644 --- a/docs/get-started.md +++ b/docs/get-started.md @@ -6,7 +6,9 @@ curl -fsSL https://raw.githubusercontent.com/adeelahmad/lense/main/install.sh | sh ``` -On Linux or a Mac, this installs Docker if it's missing (get.docker.com on Linux; OrbStack with Homebrew on a Mac), +On Linux or a Mac, this installs Docker if it's missing (get.docker.com on Linux; OrbStack with Homebrew on a Mac, +and Homebrew too if needed), after listing what it will install and asking (only at a terminal; `LENS_YES=1` skips +the question), gets Lens into `~/lens`, writes the secrets once, builds and starts the stack, and opens the setup page with the setup code already filled in. On a server without a desktop, Lens is reachable from the network and the link uses the server's address. Run the same line again to update: the secrets, the database and the archive are kept. Settings go diff --git a/install.sh b/install.sh index e979e1200..9ef83cc9e 100755 --- a/install.sh +++ b/install.sh @@ -18,6 +18,7 @@ # when microsandbox can run here (Linux with KVM, or a Mac with Apple silicon); default: docker # GITHUB_TOKEN a GitHub token to use when downloading (not needed; avoids GitHub's rate limits) # LENS_NO_OPEN 1: don't open a browser +# LENS_YES 1: install what Lens needs without asking (it only asks at a terminal) set -eu # All in a function, so nothing runs until the whole script has arrived (curl | sh streams it). @@ -44,14 +45,17 @@ os="$(uname -s)" sudo_ok() { [ "$(id -u)" = 0 ] && echo "" || echo sudo; } # --- What runs it: Docker, or a microsandbox microVM ---------------------------------------------------------------- -# microsandbox needs hardware virtualization: KVM on 64-bit Linux, Apple silicon on a Mac +# microsandbox needs hardware virtualization: KVM on 64-bit Linux (or a CPU that has it, whose module isn't loaded +# yet), Apple silicon on a Mac msb_ok() { case "$os/$(uname -m)" in - Linux/x86_64 | Linux/aarch64) [ -e /dev/kvm ] ;; + Linux/x86_64) [ -e /dev/kvm ] || grep -Eqw 'vmx|svm' /proc/cpuinfo 2>/dev/null ;; + Linux/aarch64) [ -e /dev/kvm ] ;; Darwin/arm64) true ;; *) false ;; esac } +tty_ok() { [ "${LENS_YES:-0}" != 1 ] && (: /dev/null; } BACKEND="${LENS_BACKEND:-}" if [ -z "$BACKEND" ] && [ -f "$DIR/.env" ]; then # an existing install keeps what it runs on (its data is there) BACKEND="$(grep '^LENS_BACKEND=' "$DIR/.env" | cut -d= -f2- || true)" @@ -60,7 +64,7 @@ fi if [ -z "$BACKEND" ]; then BACKEND=docker # asked only when there's someone to ask: piped into sh, the answer comes from the terminal, not stdin - if msb_ok && (: /dev/null; then + if msb_ok && tty_ok; then printf '\n\033[1mHow should Lens run?\033[0m\n' echo " 1) Docker (default): a container for each part, the usual way" echo " 2) microsandbox: one lightweight virtual machine, no Docker needed" @@ -75,15 +79,56 @@ case "$BACKEND" in *) fail "LENS_BACKEND is docker or microsandbox, not $BACKEND." ;; esac +# --- What's missing: listed, and installed once you say yes --------------------------------------------------------- +# Asked only at a terminal; piped in by a script or CI (no terminal, or LENS_YES=1) it goes ahead, as before. +export PATH="$HOME/.local/bin:$HOME/.microsandbox/bin:$PATH" +plan="" +need() { plan="$plan + - $*"; } +if [ "$BACKEND" = microsandbox ]; then + have msb || need "microsandbox (from install.microsandbox.dev, into ~/.microsandbox)" + if [ "$os" = Linux ]; then + [ -e /dev/kvm ] || need "the KVM kernel module (modprobe, with sudo)" + { [ -r /dev/kvm ] && [ -w /dev/kvm ]; } || need "access to KVM for $(id -un) (the kvm group, with sudo)" + fi +else + if ! have docker; then + case "$os" in + Linux) need "Docker Engine with Compose (from get.docker.com, with sudo)" ;; + Darwin) + have brew || need "Homebrew (from brew.sh, asks for your password)" + need "OrbStack, which runs Docker on a Mac (with Homebrew)" + ;; + esac + elif ! docker compose version >/dev/null 2>&1 && + ! have docker-compose && [ "$os" = Linux ]; then + need "the Docker Compose plugin (with your package manager, with sudo)" + fi +fi +if [ -n "$plan" ]; then + printf '\n\033[1mLens needs these, and will install them:\033[0m%s\n' "$plan" + if tty_ok; then + printf 'Install them now? [Y/n] ' + read -r answer /dev/null || $(sudo_ok) modprobe kvm_amd 2>/dev/null || $(sudo_ok) modprobe kvm 2>/dev/null || true + [ -e /dev/kvm ] || fail "KVM didn't load. Turn on virtualization (VT-x or AMD-V) in the firmware settings, or use LENS_BACKEND=docker." +fi if [ "$os" = Linux ] && ! { [ -r /dev/kvm ] && [ -w /dev/kvm ]; }; then say "Letting $(id -un) use KVM (the kvm group)..." $(sudo_ok) usermod -aG kvm "$(id -un)" 2>/dev/null || true @@ -102,6 +147,11 @@ if ! have docker; then $(sudo_ok) systemctl enable --now docker 2>/dev/null || true ;; Darwin) + if ! have brew && tty_ok; then + say "Installing Homebrew (brew.sh)..." + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" /dev/null 2>&1; then COMPOSE="$DOCKER compose" elif have docker-compose; then COMPOSE="docker-compose" +elif [ "$os" = Linux ] && { + if have apt-get; then $(sudo_ok) apt-get install -y -q docker-compose-plugin + elif have dnf; then $(sudo_ok) dnf install -y -q docker-compose-plugin + else false; fi +} >/dev/null 2>&1 && $DOCKER compose version >/dev/null 2>&1; then + COMPOSE="$DOCKER compose" else fail "Docker Compose is missing. Install the Compose plugin (docker-compose-plugin), then run this again." fi