diff --git a/Cargo.lock b/Cargo.lock
index 68c8310..c496a5a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2303,7 +2303,6 @@ name = "xtask"
version = "0.1.0"
dependencies = [
"clap",
- "rustix 1.1.5",
"thiserror 2.0.21",
"xshell",
]
diff --git a/README.md b/README.md
index 6c7272b..d89aeba 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,13 @@
# bootvine
A live tree of systemd jobs on the boot console, in the spirit of
-nix-output-monitor. It replaces the scrolling kernel and systemd lines with the
-units still pending and, in the room the tree leaves, a timeline of the slowest
-ones that ran.
+[nix-output-monitor](https://github.com/maralorn/nix-output-monitor). It
+replaces the scrolling kernel and systemd lines with the units still pending
+and, in the room the tree leaves, a timeline of the slowest ones that ran.
+
+I started bootvine out of frustration with the boot screen of most Linux
+distributions: a wall of log lines scrolling past too fast to read, which never
+gave me any idea of what was going on.
@@ -12,12 +16,14 @@ units that have to stop first.
-Passphrase prompts, such as a LUKS unlock in the initrd, are answered in place
-over the tree.
+Passphrase prompts, such as a
+[LUKS](https://gitlab.com/cryptsetup/cryptsetup) unlock in the initrd, are
+answered in place over the tree.
-It needs systemd ≥ 246 as PID 1, libdbus and a virtual terminal. With a
+It needs systemd ≥ 246 as PID 1,
+[libdbus](https://www.freedesktop.org/wiki/Software/dbus/) and a virtual terminal. With a
systemd initrd it shows the boot from about a second after the kernel starts.
## Try it without installing
@@ -25,7 +31,7 @@ systemd initrd it shows the boot from about a second after the kernel starts.
Neither of these touches your system's boot.
Play a scripted boot, poweroff and encrypted-root boot in your terminal, with
-Rust installed:
+[Rust](https://www.rust-lang.org/tools/install) installed:
```sh
git clone https://codeberg.org/wvhulle/bootvine.git
@@ -38,8 +44,8 @@ cargo run --example luks
`q` quits. The encrypted root unlocks with the passphrase `demo`; `Esc` quits
while it asks.
-Or, with Nix, boot a sample NixOS machine with slow and failing units in a
-QEMU window:
+Or, with [Nix](https://nixos.org/download/), boot a sample [NixOS](https://nixos.org) machine with slow and
+failing units in a [QEMU](https://www.qemu.org) window:
```sh
nix run git+https://codeberg.org/wvhulle/bootvine#sample-machine-vm
diff --git a/docs/architecture.md b/docs/architecture.md
index 8e04f50..86d016a 100644
--- a/docs/architecture.md
+++ b/docs/architecture.md
@@ -7,8 +7,9 @@ while it does. None of this is needed to install or configure it.
- **systemd ≥ 246 as PID 1.** bootvine reads the jobs and units from the
service manager over D-Bus.
-- **libdbus.** It talks to PID 1 over systemd's private socket, which zbus
- cannot use; see [systemd's private socket](#systemds-private-socket).
+- **[libdbus](https://www.freedesktop.org/wiki/Software/dbus/).** It talks to
+ PID 1 over systemd's private socket, which
+ [zbus](https://github.com/dbus2/zbus) cannot use; see [systemd's private socket](#systemds-private-socket).
- **A virtual terminal.** It draws on `tty12` and switches the console to it.
## Lifecycle
@@ -52,8 +53,10 @@ back. Kernel messages from before it starts are already on screen; see
### Passphrase prompts
-bootvine acts as a systemd password agent: it watches
-`/run/systemd/ask-password` and answers requests, such as a LUKS unlock, in a
+bootvine acts as a systemd
+[password agent](https://systemd.io/PASSWORD_AGENTS/): it watches
+`/run/systemd/ask-password` and answers requests, such as a
+[LUKS](https://gitlab.com/cryptsetup/cryptsetup) unlock, in a
popup over the tree. If another agent's prompt is already showing when it
starts, it stays behind it and comes forward once the prompt is answered.
diff --git a/docs/configuration.md b/docs/configuration.md
index 8b9962d..a621975 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -3,7 +3,7 @@
Every setting has a default, so bootvine needs no configuration. To change
some, write only those keys:
-- **On NixOS**, under `services.bootvine.settings`. The module writes them to
+- **On [NixOS](https://nixos.org)**, under `services.bootvine.settings`. The module writes them to
`/etc/bootvine.toml` in the real root and the initrd, and the rebuild fails
if `bootvine check` rejects them.
@@ -25,7 +25,8 @@ some, write only those keys:
```
Then check the file and, if bootvine runs in your initrd, rebuild the
- initramfs, since the dracut and mkinitcpio hooks copy the file into it:
+ initramfs, since the [dracut](https://github.com/dracut-ng/dracut-ng) and
+ [mkinitcpio](https://wiki.archlinux.org/title/Mkinitcpio) hooks copy the file into it:
```sh
bootvine check /etc/bootvine.toml
diff --git a/docs/development.md b/docs/development.md
index 9c1f1fb..2501f58 100644
--- a/docs/development.md
+++ b/docs/development.md
@@ -2,8 +2,9 @@
## Setup
-Work inside the dev shell (`direnv allow` once). Version control is jj, not
-the `git` CLI.
+Work inside the dev shell (`direnv allow` once, with
+[direnv](https://direnv.net)). Version control is
+[jj](https://github.com/jj-vcs/jj), not the `git` CLI.
## Before committing
@@ -23,14 +24,15 @@ nix run .#check-conventional-commits -- origin/main..HEAD
```
Git users can install the same commit-message check and a formatting check as
-hooks with `prek install` (from the dev shell) or `pre-commit install`.
+hooks with `prek install` ([prek](https://github.com/j178/prek), from the dev
+shell) or `pre-commit install` ([pre-commit](https://pre-commit.com)).
## Continuous integration
-`.woodpecker/rust-and-flake-checks.yaml` runs on Codeberg for every push and
-pull request: the bootvine build with its tests, the xtask build, clippy,
+`.woodpecker/rust-and-flake-checks.yaml` runs on Codeberg's
+[Woodpecker CI](https://woodpecker-ci.org) for every push and pull request: the bootvine build with its tests, the xtask build, clippy,
rustfmt, an evaluation of every flake output, and the commit-message check on
-pull requests. Builds on `main` are pushed to the `wvhulle` Cachix cache, which
+pull requests. Builds on `main` are pushed to the `wvhulle` [Cachix](https://www.cachix.org) cache, which
`nixConfig` in `flake.nix` offers as a substituter. The two VM checks need KVM,
which Codeberg's runners lack, so they only run locally.
@@ -61,14 +63,14 @@ on marker files instead of sleeping. To step through one by hand, run
call `test_script()`.
Prefix VM and recording commands with `env -u LD_LIBRARY_PATH` when your shell
-exports libraries that clash with QEMU or Chromium.
+exports libraries that clash with [QEMU](https://www.qemu.org) or Chromium.
## Repository tasks
- `nix run .#record-screencasts` re-records the README animations from the
scripted demos and copies the passphrase screenshot from the VM check.
-- `cargo xtask install --destdir
--initrd dracut` stages an install
- without touching the system; `cargo xtask uninstall --destdir ` removes
+- `cargo run -- install --destdir --initrd dracut` stages an install
+ without touching the system; `cargo run -- uninstall --destdir ` removes
it again.
## Code style and design
diff --git a/docs/install.md b/docs/install.md
index d0258e4..158b28f 100644
--- a/docs/install.md
+++ b/docs/install.md
@@ -45,54 +45,58 @@ as well, the initrd has to run systemd.
## Ubuntu
-1. Install the build dependencies and Rust. The repository pins a nightly
- toolchain in `rust-toolchain.toml`, which rustup fetches on the first
- build:
+1. Install the build dependencies and Rust:
```sh
sudo apt install build-essential pkg-config libdbus-1-dev git curl
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```
-2. Clone, build and install the binary and the systemd units, and enable
- them. `cargo xtask install` builds as you and asks `sudo` only for the
- copying and `systemctl enable`:
+2. Build bootvine into `~/.cargo/bin`:
```sh
- git clone https://codeberg.org/wvhulle/bootvine.git
- cd bootvine
- cargo xtask install
+ cargo install --locked --git https://codeberg.org/wvhulle/bootvine bootvine
```
- This installs `/usr/bin/bootvine`, and `bootvine.service` and
- `bootvine-shutdown.service` in `/usr/lib/systemd/system`, which is enough
- for stage 2 and shutdown.
+3. Install it for the system and enable its units. It asks `sudo` itself for
+ the copying and `systemctl enable`:
-3. Optionally, show the boot from the initrd. This needs a dracut initramfs
- with systemd in it; initramfs-tools has no systemd, so on releases that use
+ ```sh
+ bootvine install
+ ```
+
+ This copies the binary to `/usr/bin/bootvine`, and `bootvine.service` and
+ `bootvine-shutdown.service` to `/usr/lib/systemd/system`, which is enough
+ for stage 2 and shutdown. The copy in `~/.cargo/bin` is no longer needed;
+ `cargo uninstall bootvine` removes it.
+
+4. Optionally, show the boot from the initrd. This needs a
+ [dracut](https://github.com/dracut-ng/dracut-ng) initramfs with systemd in
+ it; initramfs-tools has no systemd, so on releases that use
it bootvine starts in stage 2 only.
```sh
- cargo xtask install --initrd dracut
+ bootvine install --initrd dracut
sudo dracut --force
```
This adds the dracut module in `/usr/lib/dracut/modules.d/90bootvine` and
enables it in `/etc/dracut.conf.d/bootvine.conf`.
-4. Reboot.
+5. Reboot.
## Other distributions
Install as in the Ubuntu steps, with your distribution's packages for a C
toolchain, `pkg-config` and the libdbus headers.
-For the initrd, use the dracut module as above, or on mkinitcpio:
+For the initrd, use the dracut module as above, or on
+[mkinitcpio](https://wiki.archlinux.org/title/Mkinitcpio):
1. Install the hook in `/usr/lib/initcpio/install/sd-bootvine`:
```sh
- cargo xtask install --initrd mkinitcpio
+ bootvine install --initrd mkinitcpio
```
2. Add `sd-bootvine` after `systemd` in `HOOKS` in `/etc/mkinitcpio.conf`.
@@ -105,10 +109,13 @@ For the initrd, use the dracut module as above, or on mkinitcpio:
## Packaging
-`cargo xtask install --destdir ` stages the files under `` instead of
-the root, and combines with `--initrd`.
+`bootvine install --destdir ` stages the files under `` instead of
+the root, without `sudo` or `systemctl`, and combines with `--initrd` and
+`--prefix`. The units' `ExecStart` follows `--prefix`. The initrd hooks expect
+the default `/usr`.
## Uninstall
-`cargo xtask uninstall` removes everything `cargo xtask install` put in place.
-On NixOS, remove `services.bootvine.enable` and rebuild.
+`bootvine uninstall` disables and removes everything `bootvine install` put in
+place, with the same `--prefix` and `--destdir`. On NixOS, remove
+`services.bootvine.enable` and rebuild.
diff --git a/src/lib.rs b/src/lib.rs
index 287af3d..1a5c142 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -3,4 +3,5 @@ pub mod boot_view;
pub mod console_session;
pub mod demo_script;
pub mod screen_settings;
+pub mod system_install;
pub mod systemd_link;
diff --git a/src/main.rs b/src/main.rs
index 49a4a6f..6b0ebc1 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,9 +1,5 @@
use std::{
- error::Error,
- io::ErrorKind,
- path::{Path, PathBuf},
- process::ExitCode,
- time::Duration,
+ error::Error, fmt::Display, io::ErrorKind, path::PathBuf, process::ExitCode, time::Duration,
};
use bootvine::{
@@ -11,9 +7,12 @@ use bootvine::{
screen_settings::config_file::{
Config, ConfigError, Timing, default_config_table, read_config_file,
},
+ system_install::install_files::{
+ InstallOptions, UninstallOptions, install_files, uninstall_files,
+ },
systemd_link::{boot_feed::RootRequest, systemd_bus::Scope},
};
-use clap::{Parser, Subcommand, ValueEnum};
+use clap::{Args, Parser, Subcommand, ValueEnum};
use jiff::fmt::friendly::SpanParser;
#[derive(Parser)]
@@ -25,6 +24,12 @@ use jiff::fmt::friendly::SpanParser;
struct Cli {
#[command(subcommand)]
command: Option,
+ #[command(flatten)]
+ watch: WatchOptions,
+}
+
+#[derive(Args)]
+struct WatchOptions {
#[arg(long, help = "Watch the user service manager instead of PID 1")]
user: bool,
#[arg(
@@ -55,12 +60,27 @@ struct Cli {
#[derive(Subcommand)]
enum Command {
#[command(about = "Print every setting with its default value")]
- Defaults {
- #[arg(long, value_enum, default_value_t = DefaultsFormat::Toml)]
- format: DefaultsFormat,
- },
+ Defaults(DefaultsOptions),
#[command(about = "Exit with an error if a config file is unreadable or invalid")]
- Check { path: PathBuf },
+ Check(CheckOptions),
+ #[command(
+ about = "Install this binary and the systemd units, and enable them; asks sudo when needed"
+ )]
+ Install(InstallOptions),
+ #[command(about = "Disable and remove what install put in place")]
+ Uninstall(UninstallOptions),
+}
+
+#[derive(Args)]
+struct DefaultsOptions {
+ #[arg(long, value_enum, default_value_t = DefaultsFormat::Toml)]
+ format: DefaultsFormat,
+}
+
+#[derive(Args)]
+struct CheckOptions {
+ #[arg(help = "Config file to check, such as /etc/bootvine.toml")]
+ path: PathBuf,
}
#[derive(Clone, Copy, ValueEnum)]
@@ -72,9 +92,21 @@ enum DefaultsFormat {
fn main() -> ExitCode {
let cli = Cli::parse();
match cli.command {
- Some(Command::Defaults { format }) => print_defaults(format),
- Some(Command::Check { ref path }) => check_config_file(path),
- None => watch_boot(cli),
+ Some(Command::Defaults(options)) => print_defaults(options.format),
+ Some(Command::Check(options)) => check_config_file(&options),
+ Some(Command::Install(options)) => report_outcome(install_files(&options)),
+ Some(Command::Uninstall(options)) => report_outcome(uninstall_files(&options)),
+ None => watch_boot(cli.watch),
+ }
+}
+
+fn report_outcome(outcome: Result<(), impl Display>) -> ExitCode {
+ match outcome {
+ Ok(()) => ExitCode::SUCCESS,
+ Err(error) => {
+ eprintln!("bootvine: {error}");
+ ExitCode::FAILURE
+ }
}
}
@@ -99,44 +131,42 @@ fn print_defaults(format: DefaultsFormat) -> ExitCode {
}
}
-fn check_config_file(path: &Path) -> ExitCode {
- match read_config_file(path) {
+fn check_config_file(options: &CheckOptions) -> ExitCode {
+ match read_config_file(&options.path) {
Ok(_) => ExitCode::SUCCESS,
Err(error) => {
- eprintln!("bootvine: {}: {error}", path.display());
+ eprintln!("bootvine: {}: {error}", options.path.display());
ExitCode::FAILURE
}
}
}
-fn watch_boot(cli: Cli) -> ExitCode {
- let config = match read_config_file(&cli.config) {
+fn watch_boot(options: WatchOptions) -> ExitCode {
+ let config = match read_config_file(&options.config) {
Ok(config) => config,
Err(ConfigError::Unreadable(error)) if error.kind() == ErrorKind::NotFound => {
Config::default()
}
Err(error) => {
- eprintln!("bootvine: ignoring {}: {error}", cli.config.display());
+ eprintln!("bootvine: ignoring {}: {error}", options.config.display());
Config::default()
}
};
let settings = Settings {
- scope: if cli.user { Scope::User } else { Scope::System },
- shutdown: cli.shutdown,
- target: cli
+ scope: if options.user {
+ Scope::User
+ } else {
+ Scope::System
+ },
+ shutdown: options.shutdown,
+ target: options
.target
.map_or(RootRequest::ManagerDefault, RootRequest::Named),
timing: Timing {
- keep_final_frame_for: cli.hold.unwrap_or(config.timing.keep_final_frame_for),
+ keep_final_frame_for: options.hold.unwrap_or(config.timing.keep_final_frame_for),
..config.timing
},
colors: config.colors,
};
- match run(&settings) {
- Ok(()) => ExitCode::SUCCESS,
- Err(error) => {
- eprintln!("bootvine: {error}");
- ExitCode::FAILURE
- }
- }
+ report_outcome(run(&settings))
}
diff --git a/src/system_install.rs b/src/system_install.rs
new file mode 100644
index 0000000..fd1ca1f
--- /dev/null
+++ b/src/system_install.rs
@@ -0,0 +1,2 @@
+pub mod install_error;
+pub mod install_files;
diff --git a/src/system_install/install_error.rs b/src/system_install/install_error.rs
new file mode 100644
index 0000000..72129c7
--- /dev/null
+++ b/src/system_install/install_error.rs
@@ -0,0 +1,11 @@
+use std::{io, path::PathBuf, process::ExitStatus};
+
+#[derive(Debug, thiserror::Error)]
+pub enum InstallError {
+ #[error("{}: {source}", path.display())]
+ File { path: PathBuf, source: io::Error },
+ #[error("could not run {program}: {source}")]
+ Spawn { program: String, source: io::Error },
+ #[error("{program} failed: {status}")]
+ Failed { program: String, status: ExitStatus },
+}
diff --git a/src/system_install/install_files.rs b/src/system_install/install_files.rs
new file mode 100644
index 0000000..2b20573
--- /dev/null
+++ b/src/system_install/install_files.rs
@@ -0,0 +1,309 @@
+use std::{
+ env,
+ ffi::OsString,
+ fs::{self, Permissions},
+ io::ErrorKind,
+ iter::once,
+ os::unix::fs::PermissionsExt,
+ path::{Path, PathBuf},
+ process::Command,
+};
+
+use clap::{Args, ValueEnum};
+use rustix::process::geteuid;
+
+use crate::system_install::install_error::InstallError;
+
+const DRACUT_MODULE_DIR: &str = "/usr/lib/dracut/modules.d/90bootvine";
+const DRACUT_CONF: &str = "/etc/dracut.conf.d/bootvine.conf";
+const MKINITCPIO_HOOK: &str = "/usr/lib/initcpio/install/sd-bootvine";
+const PACKAGED_BINARY_PATH: &str = "/usr/bin/bootvine";
+
+struct PackagedUnit {
+ name: &'static str,
+ contents: &'static str,
+}
+
+const PACKAGED_UNITS: [PackagedUnit; 2] = [
+ PackagedUnit {
+ name: "bootvine.service",
+ contents: include_str!("../../system-files/systemd/bootvine.service"),
+ },
+ PackagedUnit {
+ name: "bootvine-shutdown.service",
+ contents: include_str!("../../system-files/systemd/bootvine-shutdown.service"),
+ },
+];
+const DRACUT_MODULE_SETUP: &str =
+ include_str!("../../system-files/dracut/90bootvine/module-setup.sh");
+const MKINITCPIO_INSTALL_HOOK: &str =
+ include_str!("../../system-files/mkinitcpio/install/sd-bootvine");
+
+#[derive(Args)]
+pub struct InstallTarget {
+ #[arg(
+ long,
+ default_value = "/usr",
+ help = "Prefix for bin/bootvine and lib/systemd/system"
+ )]
+ prefix: PathBuf,
+ #[arg(
+ long,
+ help = "Stage the files under this directory instead of /; skips sudo and systemctl"
+ )]
+ destdir: Option,
+}
+
+#[derive(Args)]
+pub struct InstallOptions {
+ #[command(flatten)]
+ target: InstallTarget,
+ #[arg(
+ long,
+ value_enum,
+ default_value_t = InitrdGenerator::None,
+ help = "Also install the hook that adds bootvine to this initramfs generator"
+ )]
+ initrd: InitrdGenerator,
+ #[arg(long, help = "Leave the units disabled")]
+ no_enable: bool,
+}
+
+#[derive(Args)]
+pub struct UninstallOptions {
+ #[command(flatten)]
+ target: InstallTarget,
+}
+
+#[derive(Clone, Copy, PartialEq, Eq, ValueEnum)]
+pub enum InitrdGenerator {
+ None,
+ Dracut,
+ Mkinitcpio,
+}
+
+struct InstalledFile {
+ destination: PathBuf,
+ contents: Vec,
+ mode: u32,
+}
+
+impl InstallTarget {
+ fn staged(&self, path: &Path) -> PathBuf {
+ match &self.destdir {
+ Some(root) => root.join(path.strip_prefix("/").unwrap_or(path)),
+ None => path.to_owned(),
+ }
+ }
+
+ fn changes_live_system(&self) -> bool {
+ self.destdir.is_none()
+ }
+
+ fn needs_sudo(&self) -> bool {
+ self.changes_live_system() && !geteuid().is_root()
+ }
+
+ fn binary_path(&self) -> PathBuf {
+ self.prefix.join("bin/bootvine")
+ }
+
+ fn unit_path(&self, unit: &str) -> PathBuf {
+ self.prefix.join("lib/systemd/system").join(unit)
+ }
+
+ fn every_installed_path(&self) -> Vec {
+ once(self.binary_path())
+ .chain(unit_names().map(|unit| self.unit_path(unit)))
+ .chain([
+ Path::new(DRACUT_MODULE_DIR).join("module-setup.sh"),
+ PathBuf::from(DRACUT_CONF),
+ PathBuf::from(MKINITCPIO_HOOK),
+ ])
+ .collect()
+ }
+}
+
+fn running_binary() -> Result {
+ env::current_exe().map_err(|source| InstallError::File {
+ path: PathBuf::from("/proc/self/exe"),
+ source,
+ })
+}
+
+fn is_running_binary(path: &Path, running: &Path) -> bool {
+ fs::canonicalize(path).is_ok_and(|resolved| resolved == running)
+}
+
+fn binary_file(target: &InstallTarget) -> Result