|
3 | 3 |
|
4 | 4 | import subprocess |
5 | 5 | import sys |
| 6 | +from os import geteuid |
6 | 7 | from shlex import quote |
7 | 8 | from typing import Optional |
8 | 9 |
|
9 | 10 | import click |
10 | 11 | from msgspec.json import decode as loads |
11 | 12 | from msgspec.json import encode as dumps |
12 | 13 |
|
| 14 | +import pioreactor |
13 | 15 | from pioreactor import exc |
14 | 16 | from pioreactor import plugin_management |
15 | 17 | from pioreactor import whoami |
@@ -54,21 +56,24 @@ def pio(ctx) -> None: |
54 | 56 | Report errors or feedback: https://github.com/Pioreactor/pioreactor/issues |
55 | 57 | """ |
56 | 58 |
|
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 | + ) |
61 | 65 |
|
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!") |
67 | 69 |
|
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.") |
69 | 73 |
|
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()) |
72 | 77 |
|
73 | 78 | # load plugins |
74 | 79 | plugin_management.get_plugins() |
|
0 commit comments