forked from EMCECS/objectscale-developer-edition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.py
160 lines (146 loc) · 6.11 KB
/
install.py
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# This is the main installation script, meant to be run
# by the developer on any OS to install
import platform
import libmgr
import os
import subprocess
import shutil
import auxillary.arg_cache
import importlib
# TODO: These requirements should be verified.
requirement_cpu_count = 4
requirement_ram_mb = 16384
requirement_ram_mb_free = 10000
requirement_disk_space_mb = 100000
class colorText:
def __init__(self):
init = True
reset = '\033[0m'
bold = '\033[01m'
disable = '\033[02m'
underline = '\033[04m'
reverse = '\033[07m'
strikethrough = '\033[09m'
invisible = '\033[08m'
class fg:
black = '\033[30m'
red = '\033[31m'
green = '\033[32m'
orange = '\033[33m'
blue = '\033[34m'
purple = '\033[35m'
cyan = '\033[36m'
lightgrey = '\033[37m'
darkgrey = '\033[90m'
lightred = '\033[91m'
lightgreen = '\033[92m'
yellow = '\033[93m'
lightblue = '\033[94m'
pink = '\033[95m'
lightcyan = '\033[96m'
class bg:
black = '\033[40m'
red = '\033[41m'
green = '\033[42m'
orange = '\033[43m'
blue = '\033[44m'
purple = '\033[45m'
cyan = '\033[46m'
lightgrey = '\033[47m'
# A function designed to check the requirements of the host system.
# This function is agnostic to all OSes and needs to be able to run
# on all supported OSes.
# All of these should be warning messages, except checking disk space.
def check_system_requirements(psutil):
cpu_count = os.cpu_count()
ram_mb = psutil.virtual_memory().total / 1000000
ram_mb_free = psutil.virtual_memory().available / 1000000
disk_free_space_mb = shutil.disk_usage(os.getcwd())[2] / 1000000
if cpu_count < requirement_cpu_count:
print(
colorText.bold + 'WARNING: Found ' +
str(cpu_count) + ' logical CPU cores, we recommend at least ' +
str(requirement_cpu_count) + ' cores.\n'
'Objectscale performance may suffer.' + colorText.reset)
if ram_mb < requirement_ram_mb:
print(
colorText.bold + 'WARNING: Found ' +
str(ram_mb) + 'MB of RAM, we recommend at least ' +
str(requirement_ram_mb) + 'MB of RAM.\n'
'Objectscale performance will suffer.' + colorText.reset)
if ram_mb_free < requirement_ram_mb_free:
print(
colorText.bold + 'WARNING: Found ' +
str(ram_mb_free) + 'MB of free RAM, we recommend at least ' +
str(requirement_ram_mb_free) + 'MB of free RAM.\n'
'Objectscale performance may suffer.' + colorText.reset)
if disk_free_space_mb < requirement_disk_space_mb:
print(
colorText.bold + 'WARNING: Found ' +
str(disk_free_space_mb) + 'MB of free Disk Space, we recommend at least ' +
str(requirement_disk_space_mb) + 'MB of free space.\n'
'Objectscale performance may suffer.' + colorText.reset)
if disk_free_space_mb * 2 < requirement_disk_space_mb:
print(
colorText.bold + 'Error: Disk space much too low to support a development environment. Please allocate '
'more free space on your disk (>' + str(requirement_disk_space_mb / 2) + ' total), and then run again.' + colorText.reset)
exit(112)
def main():
#Preamble. Things that have nothing to do with installation.
print(colorText.reset)
print('Hello, Developer.')
args = auxillary.arg_cache.parse_cache()
args = args.parser.parse_args()
# Discern the current operating system and run the proper install script for it.
# The install scripts are imported on the fly to reduce software conflicts.
os_var = platform.system().casefold()
if os_var.find('linux') > -1:
print('Starting dependency installations for Linux.')
subprocess.run(['sudo', 'apt-get', 'clean'])
subprocess.run(['sudo', 'apt-get', 'update'])
subprocess.run(['sudo', 'apt', 'install', 'python3-pip'])
subprocess.run(['sudo', 'apt-get', 'install', 'gcc', 'python3-dev'])
subprocess.run(['sudo', 'pip3', 'install', 'psutil'])
print('Dependency installations complete')
# This section of code is used to fetch and check all prerequisites for this installation process
# With the exception of Minikube, Docker, Helm, and of course, Objectscale.
print('-----Libraries & Prerequisites-----')
manager = libmgr.libmgr()
manager.get_libs()
psutil = importlib.import_module('psutil')
check_system_requirements(psutil)
print('----- END Libraries & Prerequisites -----')
version_query = importlib.import_module('auxillary.version_query')
query = version_query.version_manager(args.token)
query.fetch_versions()
if args.versions_query:
query.list_versions()
return
if args.version is not None:
query.select_version(args.version)
try:
if os_var.find('linux') > -1:
print('Starting installation for Linux.')
tux_installer = importlib.import_module('linux.install_linux')
print('Dependency installations complete')
tux_installer.install_tux(args)
print('Dependency installations complete')
elif os_var.find('windows') > -1:
print('Starting installation for Windows.')
install_prereqs(args)
windows_installer = importlib.import_module('windows.install_windows')
windows_installer.install_win(args, manager.certs_found)
elif os_var.find('darwin') > -1:
print('Installation on MacOS is currently unsupported.')
#mac_installer = importlib.import_module('macos.install_macos')
#mac_installer.install_mac()
else:
print("Error: Unsupported OS: " + os_var)
except:
# If for whatever reason we get an exception,
# Make sure that the color is reset.
print(colorText.reset)
if __name__ == "__main__":
main()
else:
print('Not run in main context.')