Skip to content

Commit

Permalink
Setup runner user
Browse files Browse the repository at this point in the history
  • Loading branch information
TeyKey1 committed Feb 11, 2024
1 parent 548ed16 commit c869fa9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
15 changes: 12 additions & 3 deletions setup/hive_rpi_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

HIVE_GROUP = "hive"
HIVE_USER = "hive"
RUNNER_USER = "runner"


@click.group(invoke_without_command=True)
Expand All @@ -35,8 +36,11 @@ def install():
"Please specify the new user name", default=HIVE_USER)
hive_group = click.prompt(
"Please specify the new group name", default=HIVE_GROUP)

print("The test-runner binaries will run in a sandbox with a separate user.")
runner_user = click.prompt("Please specify the runner user name:", default=RUNNER_USER)

setup_hive(hive_user=hive_user, hive_group=hive_group, create=True)
setup_hive(hive_user=hive_user, hive_group=hive_group, runner_user=runner_user, create=True)


@cli.command()
Expand Down Expand Up @@ -73,17 +77,22 @@ def update():
"Please specify the Hive user name", default=HIVE_USER)
hive_group = click.prompt(
"Please specify the Hive group name", default=HIVE_GROUP)

print("The test-runner binaries will run in a sandbox with a separate user.")
runner_user = click.prompt("Please specify the runner user name:", default=RUNNER_USER)

setup_hive(hive_user=hive_user, hive_group=hive_group, create=False)
setup_hive(hive_user=hive_user, hive_group=hive_group, runner_user=runner_user, create=False)


def setup_hive(hive_user: str, hive_group: str, create: bool):
def setup_hive(hive_user: str, hive_group: str, runner_user: str, create: bool):
"""Run the whole setup process. If create is True attempts to create a new Hive install. If False attempts to update an existing install."""
setup_routines.setup_group(groupname=hive_group, create=create)

setup_routines.setup_user(
username=hive_user, groupname=hive_group, create=create)

setup_routines.setup_runner_user(username=runner_user, create=create)

# Set working dir to hive user base dir
os.chdir(f"/home/{hive_user}/")

Expand Down
16 changes: 16 additions & 0 deletions setup/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ def setup_user(username: str, groupname: str, create: bool):
exit(1)


def setup_runner_user(username: str, create: bool):
"""Setup the user used to run the Hive test runner"""
if create:
try:
res = subprocess.run(
["adduser", "--system", username], check=True, capture_output=True)
print(f"Successfully created Hive test runner user '{username}'")
except subprocess.CalledProcessError:
reason = res.stderr.decode("utf-8", "ignore")
print(f"Failed to create Hive test runner user: {reason}")
exit(1)
except Exception as e:
print(f"Failed to create Hive test runner user: {e}")
exit(1)


def setup_debug_probe_permissions():
"""Applies the udev rules so non-root users (eg. the created hive user) can access the connected debug probes (see https://probe.rs/docs/getting-started/probe-setup/#udev-rules)"""
urllib.request.urlretrieve("https://probe.rs/files/69-probe-rs.rules", "/etc/udev/rules.d/69-probe-rs.rules");
Expand Down

0 comments on commit c869fa9

Please sign in to comment.