# Path: temci/utils/util.py
# def has_root_privileges() -> bool:
#     """
#     Has the current user root privileges?
#     """
#     return does_command_succeed("head /proc/1/stack")


import os
import sys
        import json, shlex
from temci.utils.util import has_root_privileges
        from temci.scripts.cli import cli_with_error_catching


def run():
    sudo_opt_index = sys.argv.index("--sudo") if "--sudo" in sys.argv else sys.maxsize
    raw_opt_index = sys.argv.index("--") if "--" in sys.argv else sys.maxsize
    has_sudo_opt = sudo_opt_index != sys.maxsize and sudo_opt_index < raw_opt_index

    if not has_sudo_opt or has_root_privileges():
        cli_with_error_catching()
    else:
        if has_sudo_opt:
            sys.argv.remove("--sudo")
        cmd = "sudo TEMCI_ENV={} {}".format(
            shlex.quote(json.dumps({k:os.environ[k] for k in os.environ})),

# Path: temci/utils/util.py
# def has_root_privileges() -> bool:
#     """
#     Has the current user root privileges?
#     """
#     return does_command_succeed("head /proc/1/stack")


# Path: temci/scripts/run.py
import os
import sys
        import json, shlex
from temci.utils.util import has_root_privileges
        from temci.scripts.cli import cli_with_error_catching



def run():
    sudo_opt_index = sys.argv.index("--sudo") if "--sudo" in sys.argv else sys.maxsize
    raw_opt_index = sys.argv.index("--") if "--" in sys.argv else sys.maxsize
    has_sudo_opt = sudo_opt_index != sys.maxsize and sudo_opt_index < raw_opt_index

    if not has_sudo_opt or has_root_privileges():
        cli_with_error_catching()
    else:
        if has_sudo_opt:
            sys.argv.remove("--sudo")
        cmd = "sudo TEMCI_ENV={} {}".format(
            shlex.quote(json.dumps({k:os.environ[k] for k in os.environ})),

            " ".join(shlex.quote(arg) for arg in sys.argv))