const WAITER: &str = r#"pkexec="$1"; helper="$2"; file="$3"; ver="$4"; lpid="$5"; out="$6"; err="$7"; result="$8"; start="$9"
"$pkexec" "$helper" "$file" "$ver" "$lpid" >"$out" 2>"$err" </dev/null
rc=$?
grep -qx READY "$out" 2>/dev/null || exit "$rc"
if [ "$rc" -eq 0 ]; then
rm -f "$result"
else
reason=$(sed -n 's/^agentmux-install-update: //p' "$err" | tail -n 1 | tr -d '"\\' | cut -c1-300)
[ -n "$reason" ] || reason="the installer stopped with status $rc"
printf '{"version":"%s","error":"%s"}\n' "$ver" "$reason" >"$result"
fi
# The launcher is on its way out (it was told to quit when the helper said READY):
# start AgentMux once it has gone, whether or not the install worked.
n=0
while kill -0 "$lpid" 2>/dev/null; do
[ "$n" -lt 180 ] || exit "$rc"
sleep 1
n=$((n + 1))
done
exec "$start"
"#;Expand description
What the waiter runs: pkexec <helper> <file> <version> <launcher pid>, with the
helper’s output in files the launcher and the waiter read (the files are opened
here, as the user, so root never needs a path in the user’s folders).
Arguments: pkexec, helper, file, version, launcher pid, out, err, result, the
command that starts AgentMux.
Before the helper printed READY (password refused or unavailable, or the file
failed a check) AgentMux is still running: the exit status tells the launcher
what happened, and nothing else is done. After it, the waiter outlives the
launcher: it leaves why the install failed (a success leaves nothing), waits for
the launcher to be gone and starts AgentMux again, the old version or the new.