Skip to content

Commit

Permalink
python: Move check_root() from setup to lib
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
  • Loading branch information
nathanchance committed Dec 17, 2024
1 parent d2902bb commit c785ed5
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 13 deletions.
5 changes: 0 additions & 5 deletions python/lib/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,6 @@ def check_ip(ip_to_check):
ipaddress.ip_address(ip_to_check)


def check_root():
if os.geteuid() != 0:
raise RuntimeError("root access is required!")


# Easier than os.walk() + shutil.chown()
def chown(new_user, folder):
lib.utils.run(['chown', '-R', f"{new_user}:{new_user}", folder])
Expand Down
5 changes: 5 additions & 0 deletions python/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ def call_git_loud(directory, cmd, **kwargs):
return call_git(directory, cmd, **kwargs, capture_output=False)


def check_root():
if os.geteuid() != 0:
raise RuntimeError("root access is required!")


def chronic(*args, **kwargs):
kwargs.setdefault('capture_output', True)

Expand Down
2 changes: 1 addition & 1 deletion python/setup/almalinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def get_alma_version():


def prechecks():
lib.setup.check_root()
lib.utils.check_root()
alma_version = get_alma_version()
if alma_version not in (9, ):
raise RuntimeError(
Expand Down
2 changes: 1 addition & 1 deletion python/setup/alpine.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def setup_podman(user_name):
if not (password := args.user_password):
password = getpass.getpass(prompt='Password for Alpine user account: ')

lib.setup.check_root()
lib.utils.check_root()
enable_community_repo()
update_and_install_packages()
setup_user(args.user_name, password)
Expand Down
2 changes: 1 addition & 1 deletion python/setup/arch.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ def parse_arguments():


def prechecks():
lib.setup.check_root()
lib.utils.check_root()


def setup_doas(username):
Expand Down
2 changes: 1 addition & 1 deletion python/setup/debian.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def pi_setup(user_name):


def prechecks():
lib.setup.check_root()
lib.utils.check_root()

supported_versions = (
'bullseye',
Expand Down
2 changes: 1 addition & 1 deletion python/setup/equinix.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def parse_arguments():
if __name__ == '__main__':
args = parse_arguments()

lib.setup.check_root()
lib.utils.check_root()

drive = args.drive
folder = Path(args.folder)
Expand Down
2 changes: 1 addition & 1 deletion python/setup/fedora.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def machine_is_trusted():


def prechecks():
lib.setup.check_root()
lib.utils.check_root()
if (fedora_version := get_fedora_version()) not in range(MIN_FEDORA_VERSION,
MAX_FEDORA_VERSION + 1):
raise RuntimeError(
Expand Down
2 changes: 1 addition & 1 deletion python/setup/rocky.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def get_rocky_version():


def prechecks():
lib.setup.check_root()
lib.utils.check_root()
rocky_version = get_rocky_version()
if rocky_version not in (9, ):
raise RuntimeError(
Expand Down
2 changes: 1 addition & 1 deletion python/setup/ubuntu.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def parse_arguments():


def prechecks():
lib.setup.check_root()
lib.utils.check_root()

supported_versions = ('focal', 'jammy', 'kinetic')
if (codename := lib.setup.get_version_codename()) not in supported_versions:
Expand Down

0 comments on commit c785ed5

Please sign in to comment.