From cd2ed0c275c2a70f23c69005ba3d1ccae781f5e1 Mon Sep 17 00:00:00 2001 From: Tom Overlund Date: Fri, 28 Mar 2025 10:58:25 -0400 Subject: [PATCH] Check for existence of 'sudo' on Linux in ./mach bootstrap (#35739) * Check for existence of sudo command in ./mach bootstrap on Linux (#35736) Signed-off-by: Tom Overlund * Remove extraneous semicolon from previous commit (test-tidy fix). Signed-off-by: Tom Overlund --------- Signed-off-by: Tom Overlund --- python/servo/platform/linux.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/python/servo/platform/linux.py b/python/servo/platform/linux.py index 411a8fc1578..8ff35b25bdf 100644 --- a/python/servo/platform/linux.py +++ b/python/servo/platform/linux.py @@ -10,6 +10,7 @@ import distro import os import subprocess +import shutil from typing import Optional, Tuple from .base import Base @@ -204,6 +205,12 @@ class Linux(Base): if not install: return False + def check_sudo(): + if os.geteuid() != 0: + if shutil.which('sudo') is None: + return False + return True + def run_as_root(command, force=False): if os.geteuid() != 0: command.insert(0, 'sudo') @@ -212,6 +219,13 @@ class Linux(Base): return subprocess.call(command) print("Installing missing dependencies...") + if not check_sudo(): + print("'sudo' command not found." + " You may be able to install dependencies manually." + " See https://github.com/servo/servo/wiki/Building.") + input("Press Enter to continue...") + return False + if run_as_root(command + pkgs, force) != 0: raise EnvironmentError("Installation of dependencies failed.") return True