mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-16 16:14:28 -04:00
properly detect sudo UID
This commit is contained in:
parent
31c66a1068
commit
1b7aca130b
2 changed files with 7 additions and 5 deletions
|
@ -596,8 +596,8 @@ def setup_django(out_dir: Path | None=None, check_db=False, config: benedict=CON
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
bump_startup_progress_bar(advance=1000)
|
bump_startup_progress_bar(advance=1000)
|
||||||
|
|
||||||
subcommand = sys.argv[1] if len(sys.argv) > 1 else 'unknown'
|
is_using_meta_cmd = any(ignored_subcommand in sys.argv for ignored_subcommand in ('help', 'version', '--help', '--version'))
|
||||||
if subcommand not in ('help', 'version', '--help', '--version'):
|
if not is_using_meta_cmd:
|
||||||
# show error message to user only if they're not running a meta command / just trying to get help
|
# show error message to user only if they're not running a meta command / just trying to get help
|
||||||
STDERR.print()
|
STDERR.print()
|
||||||
STDERR.print(Panel(
|
STDERR.print(Panel(
|
||||||
|
|
|
@ -27,13 +27,15 @@ RUNNING_AS_UID = os.getuid()
|
||||||
RUNNING_AS_GID = os.getgid()
|
RUNNING_AS_GID = os.getgid()
|
||||||
EUID = os.geteuid()
|
EUID = os.geteuid()
|
||||||
EGID = os.getegid()
|
EGID = os.getegid()
|
||||||
|
SUDO_UID = int(os.environ.get('SUDO_UID', 0))
|
||||||
|
SUDO_GID = int(os.environ.get('SUDO_GID', 0))
|
||||||
USER: str = Path('~').expanduser().resolve().name
|
USER: str = Path('~').expanduser().resolve().name
|
||||||
|
|
||||||
IS_ROOT = RUNNING_AS_UID == 0
|
IS_ROOT = RUNNING_AS_UID == 0
|
||||||
IN_DOCKER = os.environ.get('IN_DOCKER', False) in ('1', 'true', 'True', 'TRUE', 'yes')
|
IN_DOCKER = os.environ.get('IN_DOCKER', False) in ('1', 'true', 'True', 'TRUE', 'yes')
|
||||||
|
|
||||||
FALLBACK_UID = RUNNING_AS_UID
|
FALLBACK_UID = RUNNING_AS_UID or SUDO_UID
|
||||||
FALLBACK_GID = RUNNING_AS_GID
|
FALLBACK_GID = RUNNING_AS_GID or SUDO_GID
|
||||||
if RUNNING_AS_UID == 0:
|
if RUNNING_AS_UID == 0:
|
||||||
try:
|
try:
|
||||||
# if we are running as root it's really hard to figure out what the correct archivebox user should be
|
# if we are running as root it's really hard to figure out what the correct archivebox user should be
|
||||||
|
@ -101,7 +103,7 @@ def drop_privileges():
|
||||||
os.environ['USER'] = pw_record.pw_name
|
os.environ['USER'] = pw_record.pw_name
|
||||||
|
|
||||||
if ARCHIVEBOX_USER == 0 or not ARCHIVEBOX_USER_EXISTS:
|
if ARCHIVEBOX_USER == 0 or not ARCHIVEBOX_USER_EXISTS:
|
||||||
print('[yellow]:warning: Running as [red]root[/red] is not recommended and may make your [blue]DATA_DIR[/blue] inaccessible to other users on your system.[/yellow]', file=sys.stderr)
|
print('[yellow]:warning: Running as [red]root[/red] is not recommended and may make your [blue]DATA_DIR[/blue] inaccessible to other users on your system.[/yellow] (use [blue]sudo[/blue] instead)', file=sys.stderr)
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue