Skip to main content

max / alloy

1.9 KB · 43 lines History Blame Raw
1 # privilege.sh — how the build scripts become root. Sourced, never executed.
2 #
3 # Alloy names run0 as the way a person becomes root (wiki alloy-privilege,
4 # "run0-first, not sudo"). These scripts are the one place that could not
5 # follow, because they run on the *dev host* rather than on the shipped OS,
6 # and the x86_64 build host is fw13: Pop!_OS, systemd 255, no run0 at all.
7 # So the mechanism resolves here, once, instead of being hardcoded to either
8 # one. When every build host is on systemd 256 or newer this file loses its
9 # else-branch and becomes two lines.
10 #
11 # Two functions, because run0 runs its child on a pty by default and sudo
12 # does not:
13 #
14 # priv output is for the person watching. The pty is right: podman keeps
15 # its progress rendering and dd redraws its status line in place.
16 # privc output is captured, piped, or consumed as an exit status. --pipe
17 # suppresses the pty, without which every captured line arrives
18 # carrying a carriage return and `$(privc du -h X | cut -f1)`
19 # returns "1.2G" with a \r stuck to the end of it.
20 #
21 # The rule for a new call site: if a human reads it as it scrolls past, priv.
22 # Anything else, privc.
23 #
24 # Working directory is the other thing run0 does not inherit the way sudo
25 # does. Every privileged call site under build/ passes absolute paths, built
26 # from $REPO_ROOT, so it does not matter — verified 2026-08-10 across
27 # build-iso.sh, build-image.sh and write-device.sh. A new call site taking a
28 # relative path is the thing that would break it, so check rather than assume.
29 #
30 # PRIV_NAME is the resolved command, for scripts that print a root command
31 # for the operator to type. A message naming sudo on a machine where the
32 # script itself used run0 teaches the wrong one.
33
34 if command -v run0 >/dev/null 2>&1; then
35 PRIV_NAME="run0"
36 priv() { run0 "$@"; }
37 privc() { run0 --pipe "$@"; }
38 else
39 PRIV_NAME="sudo"
40 priv() { sudo "$@"; }
41 privc() { sudo "$@"; }
42 fi
43