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 <tomov@dilacero.org>

* Remove extraneous semicolon from previous commit (test-tidy fix).

Signed-off-by: Tom Overlund <tomov@dilacero.org>

---------

Signed-off-by: Tom Overlund <tomov@dilacero.org>
This commit is contained in:
Tom Overlund 2025-03-28 10:58:25 -04:00 committed by GitHub
parent 482d28e4ff
commit cd2ed0c275
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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