Ensure script is ran as root.
This commit is contained in:
parent
5f39ae7138
commit
b98b76d4e4
|
|
@ -1,5 +1,10 @@
|
|||
from sys import platform
|
||||
from pci_passthrough_assist.permissions import is_ran_by_root
|
||||
|
||||
if platform != "linux":
|
||||
print("This tool will only work on Linux based OS.")
|
||||
exit(1)
|
||||
|
||||
if not is_ran_by_root():
|
||||
print("This script needs to run as root.")
|
||||
exit(1)
|
||||
5
src/pci_passthrough_assist/permissions.py
Normal file
5
src/pci_passthrough_assist/permissions.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
from pci_passthrough_assist.process_runner import sh
|
||||
|
||||
|
||||
def is_ran_by_root() -> bool:
|
||||
return sh(["whoami"]) == "root"
|
||||
14
src/pci_passthrough_assist/process_runner.py
Normal file
14
src/pci_passthrough_assist/process_runner.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
from subprocess import run
|
||||
|
||||
|
||||
def sh_binary(args: list[str], ) -> bytes:
|
||||
return run(args, capture_output=True).stdout
|
||||
|
||||
|
||||
def sh(args: list[str], rstrip_newline=True):
|
||||
string_output: str = sh_binary(args).decode()
|
||||
return string_output if not rstrip_newline else string_output.rstrip("\n")
|
||||
|
||||
|
||||
def sh_lines(args: list[str]) -> list[str]:
|
||||
return sh(args, rstrip_newline=True).splitlines()
|
||||
Loading…
Reference in a new issue