Skip to main content

max / alloy

2.8 KB · 65 lines History Blame Raw
1 #!/bin/sh
2 # alloy-layer-notice — tell the person at the machine what the blank boot is.
3 #
4 # alloy-layer-components.service lays the console and terminal down as layered
5 # packages, then reboots. Two boots therefore show nothing a user can act on:
6 # the first one after an install, and the first one after adopting a rebuilt
7 # image, because `bootc switch` discards the layer and the unit re-fires to
8 # install the new image's copy (measured, build/layertest/README.md). The
9 # second of those is the common case and the one nobody expects, since the
10 # machine was working when they typed the command.
11 #
12 # Installed machines boot with `quiet loglevel=3` so kernel and audit output
13 # does not overwrite tuigreet (usr/lib/bootc/kargs.d/10-alloy.toml), and there
14 # is no plymouth. So that boot is a genuinely blank screen: systemd's own
15 # status lines are suppressed by `quiet`, and the unit's Description never
16 # reaches anyone. Nothing tells the user, hence this.
17 #
18 # Writing to /dev/console rather than to stdout, and it is the point rather
19 # than a detail. The unit's output goes to the journal, which is exactly where
20 # a person with no console and no terminal cannot read it. `quiet` filters
21 # kernel printk and does not touch a userspace write to the console device, so
22 # this lands on the foreground VT whatever the cmdline says.
23 #
24 # `|| true` on every write, and no `set -e`. This script is on the boot path in
25 # front of the only thing that gives the machine a console: a notice that fails
26 # must never be the reason the components are not installed. Same argument as
27 # alloy-session's, one unit earlier.
28 #
29 # Deliberately dependency-free: sh, printf, one redirect. It runs on a machine
30 # that does not have its own console yet, so anything it reaches for is
31 # something that can be missing.
32
33 say() {
34 printf '%s\n' "$1" > /dev/console 2>/dev/null || true
35 }
36
37 case "${1:-start}" in
38 start)
39 say ""
40 say "Alloy is installing its console and terminal."
41 say ""
42 say "This runs once after an install, and again after you adopt a"
43 say "rebuilt image. It takes a few minutes, and the machine restarts"
44 say "by itself when it finishes."
45 say ""
46 say "Nothing is wrong. There is no login until it is done."
47 say ""
48 ;;
49 fail)
50 say ""
51 say "Alloy could not install its console and terminal."
52 say ""
53 say "The next restart tries again. If it keeps failing, the reason is"
54 say "in the journal, which you can read over ssh:"
55 say ""
56 say " journalctl -u alloy-layer-components"
57 say ""
58 ;;
59 *)
60 # An unknown argument is a caller bug, and the unit is the only caller.
61 # Saying nothing is right: the alternative is a machine whose first
62 # words to its owner are a usage message.
63 ;;
64 esac
65