-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsetup.py
executable file
·300 lines (219 loc) · 9.45 KB
/
setup.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#!/usr/bin/python3
import readline
import os
import sys
import time
import glob
import inspect
import zipfile
import shutil
import traceback
import code
from queue import Queue
queue = Queue()
os.environ['LC_ALL'] = 'C'
#first import paths and make changes if necassary
from setup_app import paths
#for example change log file location:
#paths.LOG_FILE = '/tmp/my.log'
from setup_app import static
# second import module base, this makes some initial settings
from setup_app.utils import base
from setup_app.utils.package_utils import PackageUtils
packageUtils = PackageUtils()
packageUtils.check_and_install_packages()
from setup_app.messages import msg
from setup_app.config import Config
from setup_app.utils.progress import jansProgress
from setup_app.setup_options import get_setup_options
from setup_app.utils import printVersion
from setup_app.test_data_loader import TestDataLoader
from setup_app.utils.properties_utils import propertiesUtils
from setup_app.utils.setup_utils import SetupUtils
from setup_app.utils.collect_properties import CollectProperties
from setup_app.installers.jans import JansInstaller
from setup_app.installers.httpd import HttpdInstaller
from setup_app.installers.opendj import OpenDjInstaller
from setup_app.installers.couchbase import CouchbaseInstaller
from setup_app.installers.jre import JreInstaller
from setup_app.installers.jetty import JettyInstaller
from setup_app.installers.jython import JythonInstaller
from setup_app.installers.oxauth import OxauthInstaller
from setup_app.installers.scim import ScimInstaller
from setup_app.installers.fido import FidoInstaller
from setup_app.installers.config_api import ConfigApiInstaller
#from setup_app.installers.oxd import OxdInstaller
if base.snap:
try:
open('/proc/mounts').close()
except:
print("Please execute the following command\n sudo snap connect jans-server:mount-observe :mount-observe\nbefore running setup. Exiting ...")
sys.exit()
# initialize config object
Config.init(paths.INSTALL_DIR)
Config.determine_version()
# we must initilize SetupUtils after initilizing Config
SetupUtils.init()
# get setup options from args
argsp, setupOptions = get_setup_options()
terminal_size = shutil.get_terminal_size()
tty_rows=terminal_size.lines
tty_columns = terminal_size.columns
if not argsp.n:
base.check_resources()
# pass progress indicator to Config object
Config.pbar = jansProgress
for key in setupOptions:
setattr(Config, key, setupOptions[key])
jansInstaller = JansInstaller()
jansInstaller.initialize()
print()
print("Installing Janssen Server...\n\nFor more info see:\n {} \n {}\n".format(paths.LOG_FILE, paths.LOG_ERROR_FILE))
print("Detected OS : {} {} {}".format('snap' if base.snap else '', base.os_type, base.os_version))
print("Janssen Version : {}".format(Config.oxVersion))
print("Detected init : {}".format(base.os_initdaemon))
print("Detected Apache : {}".format(base.determineApacheVersion()))
print()
setup_loaded = {}
if setupOptions['setup_properties']:
base.logIt('%s Properties found!\n' % setupOptions['setup_properties'])
setup_loaded = propertiesUtils.load_properties(setupOptions['setup_properties'])
elif os.path.isfile(Config.setup_properties_fn):
base.logIt('%s Properties found!\n' % Config.setup_properties_fn)
setup_loaded = propertiesUtils.load_properties(Config.setup_properties_fn)
elif os.path.isfile(Config.setup_properties_fn+'.enc'):
base.logIt('%s Properties found!\n' % Config.setup_properties_fn+'.enc')
setup_loaded = propertiesUtils.load_properties(Config.setup_properties_fn+'.enc')
collectProperties = CollectProperties()
if os.path.exists(Config.jans_properties_fn):
collectProperties.collect()
collectProperties.save()
Config.installed_instance = True
if argsp.csx:
print("Saving collected properties")
collectProperties.save()
sys.exit()
if not Config.noPrompt and not Config.installed_instance and not setup_loaded:
propertiesUtils.promptForProperties()
propertiesUtils.check_properties()
# initialize installers, order is important!
jreInstaller = JreInstaller()
jettyInstaller = JettyInstaller()
jythonInstaller = JythonInstaller()
openDjInstaller = OpenDjInstaller()
couchbaseInstaller = CouchbaseInstaller()
httpdinstaller = HttpdInstaller()
oxauthInstaller = OxauthInstaller()
configApiInstaller = ConfigApiInstaller()
fidoInstaller = FidoInstaller()
scimInstaller = ScimInstaller()
#oxdInstaller = OxdInstaller()
if Config.installed_instance:
for installer in (openDjInstaller, couchbaseInstaller, httpdinstaller,
oxauthInstaller, scimInstaller, fidoInstaller,
#oxdInstaller
):
setattr(Config, installer.install_var, installer.installed())
if not argsp.shell:
propertiesUtils.promptForProperties()
if not (argsp.t or argsp.x) and not Config.addPostSetupService:
print("No service was selected to install. Exiting ...")
sys.exit()
if argsp.t or argsp.x:
testDataLoader = TestDataLoader()
testDataLoader.scimInstaller = scimInstaller
if argsp.x:
print("Loading test data")
testDataLoader.dbUtils.bind()
testDataLoader.createLdapPw()
testDataLoader.load_test_data()
testDataLoader.deleteLdapPw()
print("Test data loaded. Exiting ...")
sys.exit()
if argsp.shell:
code.interact(local=locals())
sys.exit()
print()
print(jansInstaller)
proceed = True
if not Config.noPrompt:
proceed_prompt = input('Proceed with these values [Y|n] ').lower().strip()
if proceed_prompt and proceed_prompt[0] !='y':
proceed = False
#register post setup progress
class PostSetup:
service_name = 'post-setup'
install_var = 'installPostSetup'
app_type = static.AppType.APPLICATION
install_type = static.InstallOption.MONDATORY
jansProgress.register(PostSetup)
jansProgress.queue = queue
def do_installation():
jansProgress.before_start()
jansProgress.start()
try:
jettyInstaller.calculate_selected_aplications_memory()
if not Config.installed_instance:
jansInstaller.configureSystem()
jansInstaller.make_salt()
oxauthInstaller.make_salt()
if not base.snap:
jreInstaller.start_installation()
jettyInstaller.start_installation()
jythonInstaller.start_installation()
jansInstaller.copy_scripts()
jansInstaller.encode_passwords()
Config.ldapCertFn = Config.opendj_cert_fn
Config.ldapTrustStoreFn = Config.opendj_p12_fn
Config.encoded_ldapTrustStorePass = Config.encoded_opendj_p12_pass
jansInstaller.prepare_base64_extension_scripts()
jansInstaller.render_templates()
jansInstaller.render_configuration_template()
if not base.snap:
jansInstaller.update_hostname()
jansInstaller.set_ulimits()
jansInstaller.copy_output()
jansInstaller.setup_init_scripts()
# Installing jans components
if Config.wrends_install:
openDjInstaller.start_installation()
if Config.cb_install:
couchbaseInstaller.start_installation()
if (Config.installed_instance and 'installHttpd' in Config.addPostSetupService) or (not Config.installed_instance and Config.installHttpd):
httpdinstaller.configure()
if (Config.installed_instance and 'installOxAuth' in Config.addPostSetupService) or (not Config.installed_instance and Config.installOxAuth):
oxauthInstaller.start_installation()
if (Config.installed_instance and 'installFido2' in Config.addPostSetupService) or (not Config.installed_instance and Config.installFido2):
fidoInstaller.start_installation()
if (Config.installed_instance and 'installScimServer' in Config.addPostSetupService) or (not Config.installed_instance and Config.installScimServer):
scimInstaller.start_installation()
if (Config.installed_instance and configApiInstaller.install_var in Config.addPostSetupService) or (not Config.installed_instance and Config.get(configApiInstaller.install_var)):
configApiInstaller.start_installation()
#if (Config.installed_instance and 'installOxd' in Config.addPostSetupService) or (not Config.installed_instance and Config.installOxd):
# oxdInstaller.start_installation()
if argsp.t:
testDataLoader.load_test_data()
jansProgress.progress(PostSetup.service_name, "Saving properties")
propertiesUtils.save_properties()
time.sleep(2)
for service in jansProgress.services:
if service['app_type'] == static.AppType.SERVICE:
jansProgress.progress(PostSetup.service_name, "Starting {}".format(service['name'].title()))
time.sleep(2)
service['object'].stop()
service['object'].start()
jansInstaller.post_install_tasks()
jansProgress.progress(static.COMPLETED)
print()
for m in Config.post_messages:
print(m)
except:
base.logIt("FATAL", True, True)
if proceed:
do_installation()
print('\n', static.colors.OKGREEN)
msg_text = msg.post_installation if Config.installed_instance else msg.installation_completed.format(Config.hostname)
print(msg_text)
print('\n', static.colors.ENDC)
# we need this for progress write last line
time.sleep(2)