forked from heavy-duty/rig
30 lines
1.6 KiB
Bash
30 lines
1.6 KiB
Bash
|
|
#!/usr/bin/env bash
|
||
|
|
# admin-path.sh — assert the admin binaries are REACHABLE, not merely that we
|
||
|
|
# are root.
|
||
|
|
#
|
||
|
|
# Being uid 0 and being able to find useradd are different facts, and rig
|
||
|
|
# asserted only the first. `su` without `-`, sudo with a sanitised secure_path,
|
||
|
|
# and several container images all hand you a root shell whose PATH carries no
|
||
|
|
# /usr/sbin — which is where useradd, usermod and groupadd live on Debian. The
|
||
|
|
# result was a bare `useradd: command not found` naming a line number inside a
|
||
|
|
# versioned install root, emitted AFTER a registration token had been read off
|
||
|
|
# the operator's terminal (#139).
|
||
|
|
#
|
||
|
|
# It REFUSES rather than repairing PATH itself. A command that quietly prepends
|
||
|
|
# /usr/sbin teaches the operator nothing and leaves a misconfigured host
|
||
|
|
# misconfigured; the same reason bootstrap refuses rather than guessing. The
|
||
|
|
# message carries the fix so the refusal costs one paste, not an investigation.
|
||
|
|
|
||
|
|
# require_admin_bins <bin>... — die unless every one resolves on PATH.
|
||
|
|
require_admin_bins() {
|
||
|
|
local missing=() b
|
||
|
|
for b in "$@"; do
|
||
|
|
command -v "$b" >/dev/null 2>&1 || missing+=("$b")
|
||
|
|
done
|
||
|
|
[ "${#missing[@]}" -eq 0 ] && return 0
|
||
|
|
# Names the REMEDY, not this script: the operator typed a `rig ...` command,
|
||
|
|
# and echoing the internal path back at them is the unhelpful half of the
|
||
|
|
# original `useradd: command not found`.
|
||
|
|
die "cannot find ${missing[*]} on PATH — it lives in /usr/sbin, which this root shell does not carry (a 'su' without '-' does this, and so do some container images). Re-run the same rig command with: PATH=/usr/sbin:/sbin:\$PATH"
|
||
|
|
}
|