-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall
More file actions
executable file
·81 lines (68 loc) · 2.24 KB
/
install
File metadata and controls
executable file
·81 lines (68 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = "Vadym Stupakov"
__email__ = "vadim.stupakov@gmail.com"
import os
import stat
import sys
from argparse import ArgumentParser, RawTextHelpFormatter
from pathlib import Path
from subprocess import run
ROOT_DIR = Path(__file__).absolute().parent.resolve()
ENV = os.environ.copy()
if __name__ == "__main__":
scripts = [s for s in (ROOT_DIR / "lib").iterdir() if s.name.startswith("install_")]
scripts = sorted(scripts, key=lambda s: s.name.lower())
script2file = {s.stem: s for s in scripts}
scripts_help_str = "\n ".join(script2file.keys())
parser = ArgumentParser(
prog="install",
formatter_class=RawTextHelpFormatter,
)
parser.add_argument(
"-s",
"--script",
help=f"script to run (choices are):\n {scripts_help_str}",
default="install_all_no_root",
)
parser.add_argument(
"--mode",
help="Installation mode",
choices=["gui", "headless"],
default="headless",
)
parser.add_argument(
"--force_superuser",
help="Install all from superuser. Use it for docker builds, for example",
action="store_true",
)
args, extra_args = parser.parse_known_args()
if args.script not in script2file:
print(
f"❌ Invalid script: '{args.script}'\nAvailable choices:\n {scripts_help_str}",
file=sys.stderr,
)
sys.exit(1)
env_args = {}
for k, v in args.__dict__.items():
if isinstance(v, bool):
v = str(int(v))
env_args[f"args_{k}".upper()] = v
ENV.update(env_args)
ENV["ROOT_DIR"] = ROOT_DIR.as_posix()
is_superuser = os.getuid() == 0
cmd = ["/bin/bash", (script2file[args.script]).as_posix()] + extra_args[1:]
print(cmd)
if is_superuser:
if args.force_superuser:
fake_sudo = ROOT_DIR / "lib/sudo"
fake_sudo.chmod(fake_sudo.stat().st_mode | stat.S_IEXEC)
ENV["PATH"] = f"{fake_sudo.parent}{os.pathsep}{ENV['PATH']}"
else:
print("Run this script without sudo!")
sys.exit(-1)
try:
ret = run(cmd, env=ENV)
sys.exit(ret.returncode)
except KeyboardInterrupt:
sys.exit(0)