Skip to content

Commit 7d84915

Browse files
check for non-standard install of pioreactor
1 parent ba7be80 commit 7d84915

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

pioreactor/cli/pio.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33

44
import subprocess
55
import sys
6+
from os import geteuid
67
from shlex import quote
78
from typing import Optional
89

910
import click
1011
from msgspec.json import decode as loads
1112
from msgspec.json import encode as dumps
1213

14+
import pioreactor
1315
from pioreactor import exc
1416
from pioreactor import plugin_management
1517
from pioreactor import whoami
@@ -54,21 +56,24 @@ def pio(ctx) -> None:
5456
Report errors or feedback: https://github.com/Pioreactor/pioreactor/issues
5557
"""
5658

57-
# if a user runs `pio`, we want the check_firstboot_successful to run, hence the invoke_without_command
58-
# https://click.palletsprojects.com/en/8.1.x/commands/#group-invocation-without-command
59-
if ctx.invoked_subcommand is None:
60-
click.echo(ctx.get_help())
59+
if not whoami.is_testing_env():
60+
# this check could go somewhere else. TODO This check won't execute if calling pioreactor from a script.
61+
if not whoami.check_firstboot_successful():
62+
raise SystemError(
63+
"/usr/local/bin/firstboot.sh found on disk. firstboot.sh likely failed. Try looking for errors in `sudo systemctl status firstboot.service`."
64+
)
6165

62-
# this check could go somewhere else. TODO This check won't execute if calling pioreactor from a script.
63-
if not whoami.check_firstboot_successful():
64-
raise SystemError(
65-
"/usr/local/bin/firstboot.sh found on disk. firstboot.sh likely failed. Try looking for errors in `sudo systemctl status firstboot.service`."
66-
)
66+
# running as root can cause problems as files created by the software are owned by root
67+
if geteuid() == 0:
68+
raise SystemError("Don't run as root!")
6769

68-
from os import geteuid
70+
# user-installs of pioreactor are not the norm and cause problems. This may change in the future.
71+
if pioreactor.__file__ != "/usr/local/lib/python3.11/dist-packages/pioreactor/__init__.py":
72+
raise SystemError("Pioreactor installed in a non-standard location. Please re-install.")
6973

70-
if geteuid() == 0:
71-
raise SystemError("Don't run as root!")
74+
# https://click.palletsprojects.com/en/8.1.x/commands/#group-invocation-without-command
75+
if ctx.invoked_subcommand is None:
76+
click.echo(ctx.get_help())
7277

7378
# load plugins
7479
plugin_management.get_plugins()

0 commit comments

Comments
 (0)