From 3987706f2d081d1f3d5d7ca45f079b531f3ca770 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sun, 22 Nov 2026 23:02:38 +0400 Subject: [PATCH] refac --- README.md | 2 +- docs/configuration.md | 17 +++++++++++++++++ open_terminal/cli.py | 11 +++++++---- open_terminal/utils/packages.py | 24 +++++++++++++++--------- 4 files changed, 40 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 4f44ed3..af95e8f 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ open-terminal run --host 0.0.0.0 --port 8000 The [Open Machine alias package](packages/open-machine) provides the same CLI as `open-machine` and depends on `open-terminal`. -Linux defaults to a separate XFCE desktop. Select GNOME explicitly with `--desktop-environment gnome`. See [desktop setup](docs/configuration.md#desktop) for required packages. Keep your existing display manager if prompted during installation. Docker `latest` includes XFCE and its dependencies. Sharing your actual logged-in desktop requires `--desktop-mode host`. +Linux defaults to a separate XFCE desktop. Select GNOME explicitly with `--desktop-environment gnome`. On Debian and Ubuntu, `open-terminal install-deps` installs the packages for the desktop and Chrome tabs; see [desktop setup](docs/configuration.md#desktop) for other systems. Keep your existing display manager if prompted during installation. Docker `latest` includes XFCE and its dependencies. Sharing your actual logged-in desktop requires `--desktop-mode host`. If no API key is configured, one is generated and printed at startup. For Docker, find it with `docker logs open-terminal`. diff --git a/docs/configuration.md b/docs/configuration.md index b1aa83f..c09da03 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -50,6 +50,23 @@ open-terminal run # XFCE (default) open-terminal run --desktop-environment gnome # Explicit GNOME ``` +On **Debian and Ubuntu**, one command installs what the default XFCE desktop and +Chrome tabs need: + +```sh +open-terminal install-deps # Desktop and Chrome tabs +open-terminal install-deps desktop # Only one of them +open-terminal install-deps --dry-run # Show the command without running it +open-terminal install-deps --package libreoffice # Any other apt package +``` + +It skips what is already installed, shows the command and asks before running +it, and uses `sudo` when not run as root. Pass `--yes` to skip the question, for +example from a script; without a terminal, `sudo` reads its password from +standard input. On Ubuntu, Chrome tabs get Google Chrome's own package (x86-64 +only), because Ubuntu ships Chromium only as a snap. Restart Open Terminal +afterwards. GNOME, host mode, and other distributions need the packages below. + On **Ubuntu 26.04 and other Wayland-only GNOME installations**, install: ```sh diff --git a/open_terminal/cli.py b/open_terminal/cli.py index 05f5fb2..bd5385b 100644 --- a/open_terminal/cli.py +++ b/open_terminal/cli.py @@ -246,13 +246,15 @@ def bridge(path: str): @main.command("install-deps") @click.argument("features", nargs=-1, type=click.Choice(["desktop", "browser"])) +@click.option("--package", "extra", multiple=True, help="Also install this apt package. Repeat for more.") @click.option("--dry-run", is_flag=True, help="Print what would be installed without installing it.") @click.option("--yes", is_flag=True, help="Install without asking.") -def install_deps(features: tuple[str, ...], dry_run: bool, yes: bool): +def install_deps(features: tuple[str, ...], extra: tuple[str, ...], dry_run: bool, yes: bool): """Install the system packages for Desktop and Chrome tabs. - Installs both unless FEATURES names one. Supports Debian and Ubuntu and - needs root or sudo. Restart Open Terminal afterwards. + Installs both unless FEATURES names one, or only --package is given. + Supports Debian and Ubuntu and needs root or sudo. Restart Open Terminal + afterwards. """ from open_terminal import config @@ -260,7 +262,8 @@ def install_deps(features: tuple[str, ...], dry_run: bool, yes: bool): from open_terminal.utils import packages - raise SystemExit(packages.install(features or packages.FEATURES, dry_run=dry_run, yes=yes)) + features = features or (() if extra else packages.FEATURES) + raise SystemExit(packages.install(features, extra, dry_run=dry_run, yes=yes)) @main.command() diff --git a/open_terminal/utils/packages.py b/open_terminal/utils/packages.py index 84b892e..2256017 100644 --- a/open_terminal/utils/packages.py +++ b/open_terminal/utils/packages.py @@ -6,6 +6,7 @@ set the Docker image ships through apt, on Debian and Ubuntu. import os import platform +import re import shlex import shutil import subprocess @@ -59,12 +60,16 @@ def ubuntu(): return False -def install(features, *, dry_run=False, yes=False): - """Install what *features* still lack. Returns the process exit code.""" +def install(features, extra=(), *, dry_run=False, yes=False): + """Install what *features* still lack, plus any *extra* apt packages. Returns the process exit code.""" if sys.platform != "linux" or not shutil.which("apt-get"): raise click.ClickException(f"install-deps supports Debian and Ubuntu. For other systems see {DOCS}") - features = list(dict.fromkeys(features)) - packages, deb = [], None + for name in extra: + # Names only: anything else could reach apt as an option, run as root. + if not re.fullmatch(r"[a-z0-9][a-z0-9+.-]*", name): + raise click.BadParameter(f"{name!r} is not a package name.", param_hint="--package") + features, extra = list(dict.fromkeys(features)), list(dict.fromkeys(extra)) + packages, deb = missing(extra), None for feature in features: wanted = APT[feature] if feature == "browser": @@ -81,7 +86,7 @@ def install(features, *, dry_run=False, yes=False): wanted = (*wanted, *FONTS) packages += missing(wanted) if not packages and not deb: - return report(features) + return report(features, extra) root = os.geteuid() == 0 if not root and not shutil.which("sudo"): @@ -118,12 +123,13 @@ def install(features, *, dry_run=False, yes=False): if code: click.echo("Install failed. Run the command above yourself, then restart Open Terminal.", err=True) return code - click.echo("Restart Open Terminal to use the new features.") - return report(features) + if features: + click.echo("Restart Open Terminal to use the new features.") + return report(features, extra) -def report(features): - ok = True +def report(features, extra=()): + ok = not missing(extra) for feature in features: if ready(feature): click.echo(f"{feature}: ready")