Native install: mandatory install directory, UI delivered from the repository

- install.sh always asks for the install directory (--prefix or a prompt
  with confirmation, no default); refuses system directories, the
  repository checkout itself, paths inside/containing it and non-empty
  directories (a resumed install is allowed). A preflight refusal says
  nothing was changed.
- UI is part of the repository: committed build in deploy/ui-dist with
  SOURCE_HASH and a staleness guard (check-ui.sh, loud warning). install.sh
  and update.sh resolve the UI: --ui-dist FILE|DIR, --build-ui, committed
  build; install stops without a UI unless --no-ui. update.sh swaps the UI
  when its hash differs from the installed one (.ui-source-hash).
- build-ui.sh: --docker, --local (host Node >= 20.19, temporary copy),
  --node-download (portable Node, SHA-256 verified), --publish.
- Verified on Alpine 3.23: install without UI options installs the real UI;
  local build equals the Docker build; update skips an unchanged UI and
  warns on a stale build. --node-download is untested (needs network).
- Docs: Scenario 2 guide, change summary, plan, README.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ayurishchevandClaude Sonnet 5.5 committed 2026-10-05 12:38:18 +03:00
1 parent 4abd2044f0
commit 8371d889a4
31 files changed
+920 -114

No files matched your search

@@ -38,6 +38,49 @@ Phase 3 of [Deployment_Scenarios_PLAN](2026-10-05_Deployment_Scenarios_PLAN.md).
Test containers, images and the UI archive were removed afterwards.
## Follow-up: the install directory is always asked for
A first run on a clean Alpine 3.24 host failed with "an installation already exists": the repository had been cloned straight into `/opt/OpenVPN-Monitoring-Simple`, the default prefix, and the preflight took the checkout's `APP_CORE` for an installation. My tests always ran from a separate source directory, so this was not caught.
| Change | Detail |
|---|---|
| `--prefix` is mandatory | No default any more: the option, or an interactive prompt with a confirmation; without a terminal the script stops. `/opt/OpenVPN-Monitoring-Simple` is only a suggestion |
| Prefix checks (before anything is changed) | absolute and normalised path; not a system directory (the installer sets permissions on it, `chmod 755 /root` would be harmful); not the repository checkout, not inside it, not containing it; new or empty (a resumed install is allowed); an existing non-empty directory is refused and points to `update.sh` |
| Not done on purpose | An "install in place" mode (checkout = install directory) was drafted and dropped: with the source and the install directory separated it is unnecessary, and a rollback after a `git pull` in place was not verified (the git `HEAD` could stay on the new commit while the files are restored) |
| Messages | A refusal in preflight now says "nothing was changed on this system"; a later failure says to rerun with the same `--prefix` |
| `update.sh`, `backup.sh`, `restore.sh` | Unchanged: they read the prefix from `/etc/ovpmon/deploy.state`. Adoption of a hand-made installation by `update.sh` (including a checkout used as the install directory) stays as it was |
| `.gitignore` | `__pycache__/` and `*.pyc` |
Checked without installing anything: system directories, the checkout itself, a path inside the checkout, `..`/relative/trailing-slash paths, a missing `--prefix` without a terminal, and the interactive prompt (empty answer, system directory, the checkout, a valid path declined three times) all stop before any change; nothing was created on the host.
## Follow-up: the UI is part of the repository (plan: [UI_Delivery_PLAN](2026-10-05_UI_Delivery_PLAN.md))
Incident: `install.sh` without `--ui-dist` installed only a placeholder page, so after the install "the UI was not there". The UI is now delivered like any other part of the checkout.
| Change | Detail |
|---|---|
| Committed build | `deploy/ui-dist/` (build of `APP_UI`) with `SOURCE_HASH`; refreshed by a maintainer with `deploy/native/build-ui.sh --publish` before committing UI changes. Outside `APP_UI`, so the container builds are unaffected; `deploy/ui-dist` is in `.dockerignore` (the all-in-one image builds the UI itself); `.gitignore` does not ignore it |
| `ui_source_hash` (`lib.sh`) | SHA-256 over `src/`, `public/`, `index.html`, `package.json`, `package-lock.json`, `vite.config.js`, `jsconfig.json` (relative paths in `LC_ALL=C` order, hash per file, hash of the list; never `node_modules`/`dist`); busybox and GNU (`sha256sum`, or `shasum` on macOS). One function for `build-ui.sh`, `check-ui.sh`, `install.sh`, `update.sh` |
| `check-ui.sh` | prints `fresh`, `stale` or `missing`; exit 0, 1, 2 |
| Staleness guard | committed build older than the sources: a loud, precise warning in `install.sh`/`update.sh` (hashes, `build-ui.sh --publish` for maintainers, `--build-ui` for the host); not fatal |
| Order (`install.sh`, `update.sh`) | `--ui-dist FILE\|DIR`, `--build-ui`, committed `deploy/ui-dist`, (install only: `deploy/native/ui-dist.tar.gz`); nothing found: `install.sh` stops unless `--no-ui` (placeholder only then); `update.sh` keeps the installed UI |
| Web root hash | `/var/www/ovpmon/.ui-source-hash`; `update.sh` skips the UI swap when the repository build has the same hash, otherwise swaps it in phase 6 (inside the backup and the automatic rollback); the source is decided after `git pull` |
| `stage_ui` | accepts a tarball or a directory, validates `index.html` before the live web root is touched, same atomic swap |
| `build-ui.sh` | default unchanged in effect (tarball), now Docker if it works else local; `--docker`, `--local` (`npm ci` in a temporary copy of `APP_UI`, Node >= 20.19 check, per-OS instructions), `--node-download` (official Node 20, SHA-256 verified, glibc only, temporary), `--publish`, `--check`, `--repo`; tarballs contain `SOURCE_HASH` |
Checked on a temporary copy of the repository (nothing installed, no service touched): `sh -n`/`bash -n` of all scripts; `ui_source_hash` identical under dash, bash and busybox sh and equal to an independent Python computation, unaffected by `node_modules`, `dist` and `.DS_Store`, changed by a source edit; `check-ui.sh` fresh/stale/missing with exit codes; `ui_resolve` and `stage_ui` for a directory, a tarball with and without `SOURCE_HASH`, an invalid source and the fallback archive; `build-ui.sh --local --publish -o` with a stub `node`/`npm` (old Node refused with instructions, source tree stays clean, `deploy/ui-dist` and the tarball written, check says fresh); `ui_resolve --build-ui` through the default Docker builder produced a real tarball whose `SOURCE_HASH` equals the hash of the sources. Not tested here: `--node-download` (needs nodejs.org), `--docker --publish` on the real tree, a real install and update with the new UI logic on a host, and `build-ui.sh --local` with a real Node.
Real runs after the implementation (Alpine 3.23 container with OpenRC; Docker only for the maintainer build):
| Check | Result |
|---|---|
| `build-ui.sh --publish` (Docker) and `check-ui.sh` | `deploy/ui-dist` (1.3 MB) written, `fresh` |
| `install.sh --prefix ...` with **no UI option** (the incident) | The UI of the repository is installed automatically: real index page (`OpenVPN Controller`), `.ui-source-hash` equals `SOURCE_HASH`, HTTPS health check 200 |
| `build-ui.sh --local` with the distribution's Node (v24, no Docker) | Builds in a temporary copy; the source tree stays clean (no `node_modules`, no `dist`); the archive's `SOURCE_HASH` equals the Docker build's |
| `update.sh`, UI sources unchanged | "UI: unchanged (same sources as the installed UI)", no swap |
| `update.sh`, a UI source changed after the build | Loud warning that the committed build is older than the sources and how to fix it; the update still completes |
| Not run | `--node-download` (needs the network and nodejs.org), Debian/Ubuntu runs of the new UI logic, `install.sh --build-ui` on a host |
## Notes and limits
- A container is not a host: no real firewall, cgroup and init details can differ. Run the procedure once on a VM of the target OS before production. Test containers needed explicit help (an init process for OpenRC, writable cgroup); these are test artefacts, not product defects.