Refuse to run the Linux setup as root

setup-linux.sh accepted being run as root and simply set SUDO="". That quietly
broke everything user-scoped: PM2 keeps its process list in $HOME/.pm2 and the
login entry goes in $HOME/.config/autostart, so under sudo both landed in /root.
The install reported success, then `pm2 list` as the real user showed nothing -
it was talking to a different daemon - and the autostart entry sat in a home
directory that never logs in.

Both scripts now refuse, and name the account to use when SUDO_USER says how
they were invoked. setup-linux.sh still uses sudo for apt, which is the only
part that needs it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Brandon Li
2026-09-13 13:21:59 -05:00
co-authored by Claude Opus 5
parent a6a79bba7e
commit 153b1273c3
2 changed files with 23 additions and 5 deletions
+10
View File
@@ -31,6 +31,16 @@ done
info() { printf ' %s\n' "$1"; }
warn() { printf ' ! %s\n' "$1" >&2; }
# Same reason as setup-linux.sh: PM2's process list lives in $HOME/.pm2 and the
# login entry in $HOME/.config/autostart. As root both go to /root, invisible to
# the account that actually logs in.
if [ "$(id -u)" -eq 0 ]; then
echo " [X] do not run this as root${SUDO_USER:+ - run it as $SUDO_USER}." >&2
echo " PM2 and the login entry are per-user; as root they land in /root" >&2
echo " and your own 'pm2 list' will be empty." >&2
exit 1
fi
info "project root: $ROOT"
# ── PM2 ─────────────────────────────────────────────────────────────────────