10
10
import configparser
11
11
import subprocess
12
12
import shutil
13
+ import tempfile
13
14
14
15
from pathlib import Path
15
16
from urllib import request
16
17
from urllib .parse import urljoin
17
18
19
+ cur_dir = os .path .dirname (__file__ )
18
20
19
21
if '--remove-flex' in sys .argv :
20
22
@@ -53,25 +55,30 @@ def get_flex_setup_parser():
53
55
54
56
__STATIC_SETUP_DIR__ = '/opt/jans/jans-setup/'
55
57
58
+ if os .path .exists (__STATIC_SETUP_DIR__ ):
59
+ os .system ('mv {} {}-{}' .format (__STATIC_SETUP_DIR__ , __STATIC_SETUP_DIR__ .rstrip ('/' ), time .ctime ().replace (' ' , '_' )))
60
+
56
61
installed_components = {'admin_ui' : False , 'casa' : False }
57
62
argsp = None
63
+ jans_installer_downloaded = False
64
+ install_py_path = os .path .join (cur_dir , 'jans_install.py' )
65
+
66
+ def download_jans_install_py (setup_branch ):
67
+ print ("Downloading" , os .path .basename (install_py_path ))
68
+ install_url = 'https://raw.githubusercontent.com/JanssenProject/jans/{}/jans-linux-setup/jans_setup/install.py' .format (setup_branch )
69
+ request .urlretrieve (install_url , install_py_path )
58
70
59
71
try :
60
72
import jans_setup
61
73
path_ = list (jans_setup .__path__ )
62
74
sys .path .append (path_ [0 ])
63
75
except ModuleNotFoundError :
64
- if os .path .exists (os .path .join (__STATIC_SETUP_DIR__ , 'setup_app' )):
65
- sys .path .append (__STATIC_SETUP_DIR__ )
66
- else :
76
+ if not os .path .exists ('/etc/jans/conf/jans.properties' ):
67
77
argsp , nargs = get_flex_setup_parser ().parse_known_args ()
68
-
69
78
print ("Unable to locate jans-setup, installing ..." )
70
-
71
79
setup_branch = argsp .jans_setup_branch or 'main'
72
- install_url = 'https://raw.githubusercontent.com/JanssenProject/jans/{}/jans-linux-setup/jans_setup/install.py' .format (setup_branch )
73
- request .urlretrieve (install_url , 'install.py' )
74
- install_cmd = '{} install.py --setup-branch={}' .format (sys .executable , setup_branch )
80
+ download_jans_install_py (setup_branch )
81
+ install_cmd = '{} {} --setup-branch={}' .format (sys .executable , install_py_path , setup_branch )
75
82
76
83
if argsp .download_exit :
77
84
nargs .append ('--download-exit' )
@@ -86,22 +93,46 @@ def get_flex_setup_parser():
86
93
87
94
print ("Executing" , install_cmd )
88
95
os .system (install_cmd )
89
- sys . path . append ( __STATIC_SETUP_DIR__ )
96
+ jans_installer_downloaded = True
90
97
91
98
if not argsp :
92
99
argsp , nargs = get_flex_setup_parser ().parse_known_args ()
93
100
101
+ if not jans_installer_downloaded :
102
+ jans_archieve_url = 'https://github.com/JanssenProject/jans/archive/refs/heads/{}.zip' .format (argsp .jans_branch )
103
+ with tempfile .TemporaryDirectory () as tmp_dir :
104
+ jans_zip_file = os .path .join (tmp_dir , os .path .basename (jans_archieve_url ))
105
+ print ("Downloading {} as {}" .format (jans_archieve_url , jans_zip_file ))
106
+ request .urlretrieve (jans_archieve_url , jans_zip_file )
107
+
108
+ print ("Extracting jans-setup package" )
109
+ jans_zip = zipfile .ZipFile (jans_zip_file )
110
+ parent_dir = jans_zip .filelist [0 ].orig_filename
111
+ unpack_dir = os .path .join (tmp_dir , 'unpacked' )
112
+ shutil .unpack_archive (jans_zip_file , unpack_dir )
113
+ shutil .copytree (os .path .join (unpack_dir , parent_dir , 'jans-linux-setup/jans_setup' ), __STATIC_SETUP_DIR__ )
114
+ jans_zip .close ()
115
+
116
+ sys .path .append (__STATIC_SETUP_DIR__ )
117
+ from setup_app import downloads
118
+ from setup_app .utils import base
119
+ downloads .base .current_app .app_info = base .readJsonFile (os .path .join (__STATIC_SETUP_DIR__ , 'app_info.json' ))
120
+ downloads .download_sqlalchemy ()
121
+ downloads .download_gcs ()
122
+
94
123
install_components = {
95
124
'admin_ui' : argsp .install_admin_ui ,
96
125
'casa' : argsp .install_casa
97
126
}
98
127
99
-
100
128
logs_dir = os .path .join (__STATIC_SETUP_DIR__ , 'logs' )
101
129
102
130
if not os .path .exists (logs_dir ):
103
131
os .makedirs (logs_dir )
104
132
133
+ if not __STATIC_SETUP_DIR__ in sys .path :
134
+ sys .path .append (__STATIC_SETUP_DIR__ )
135
+
105
136
from setup_app import paths
106
137
paths .LOG_FILE = os .path .join (logs_dir , 'flex-setup.log' )
107
138
paths .LOG_ERROR_FILE = os .path .join (logs_dir , 'flex-setup-error.log' )
@@ -338,7 +369,7 @@ def enable_apache_mod_dir(self):
338
369
339
370
340
371
def rewrite_cli_ini (self ):
341
- print (" - Rewriting Jans CLI init file for plgins " )
372
+ print (" - Rewriting Jans CLI init file for plugins " )
342
373
cli_config = Path (jans_cli_installer .config_ini_fn )
343
374
344
375
if cli_config .exists ():
@@ -364,7 +395,9 @@ def install_gluu_admin_ui(self):
364
395
365
396
client_check_result = config_api_installer .check_clients ([('admin_ui_client_id' , '2001.' )])
366
397
if client_check_result ['2001.' ] == - 1 :
367
- ldif_parser = myLdifParser (jans_cli_installer .ldif_client )
398
+
399
+ cli_ldif_client_fn = os .path .join (jans_cli_installer .templates_folder , os .path .basename (jans_cli_installer .ldif_client ))
400
+ ldif_parser = myLdifParser (cli_ldif_client_fn )
368
401
ldif_parser .parse ()
369
402
370
403
ldif_parser .entries [0 ][1 ]['inum' ] = ['%(admin_ui_client_id)s' ]
0 commit comments