|
| 1 | +#!/usr/bin/python3 |
| 2 | + |
| 3 | +import sys |
| 4 | +import os |
| 5 | +import zipfile |
| 6 | +import argparse |
| 7 | +from urllib.parse import urljoin |
| 8 | + |
| 9 | +jans_setup_dir = '/opt/jans/jans-setup' |
| 10 | +sys.path.append(jans_setup_dir) |
| 11 | + |
| 12 | +if not (os.path.join(jans_setup_dir) and ('/etc/jans/conf/jans.properties')): |
| 13 | + print("Please install Jans server then execute this script.") |
| 14 | + sys.exit() |
| 15 | + |
| 16 | + |
| 17 | +from setup_app import paths |
| 18 | +paths.LOG_FILE = os.path.join(jans_setup_dir, 'logs/flex-setup.log') |
| 19 | +paths.LOG_ERROR_FILE = os.path.join(jans_setup_dir, 'logs/flex-setup-error.log') |
| 20 | +from setup_app import static |
| 21 | +from setup_app.utils import base |
| 22 | + |
| 23 | +from setup_app.utils.package_utils import packageUtils |
| 24 | +from setup_app.config import Config |
| 25 | +from setup_app.utils.collect_properties import CollectProperties |
| 26 | +from setup_app.installers.node import NodeInstaller |
| 27 | +from setup_app.installers.httpd import HttpdInstaller |
| 28 | +from setup_app.installers.config_api import ConfigApiInstaller |
| 29 | + |
| 30 | +parser = argparse.ArgumentParser(description="This script downloads Gluu Admin UI components and installs") |
| 31 | +parser.add_argument('--setup-branch', help="Jannsen setup github branch", default='main') |
| 32 | +argsp = parser.parse_args() |
| 33 | + |
| 34 | +# initialize config object |
| 35 | +Config.init(paths.INSTALL_DIR) |
| 36 | +Config.determine_version() |
| 37 | + |
| 38 | +collectProperties = CollectProperties() |
| 39 | +collectProperties.collect() |
| 40 | + |
| 41 | +maven_base_url = 'https://maven.jans.io/maven/io/jans/' |
| 42 | +app_versions = { |
| 43 | + "SETUP_BRANCH": argsp.setup_branch, |
| 44 | + "JANS_APP_VERSION": "1.0.0", |
| 45 | + "JANS_BUILD": "-SNAPSHOT", |
| 46 | + "ADMIN_UI_FRONTEND_BRANCH": "main", |
| 47 | + "NODE_VERSION": "v14.18.2" |
| 48 | +} |
| 49 | + |
| 50 | +node_installer = NodeInstaller() |
| 51 | +httpdInstaller = HttpdInstaller() |
| 52 | +configApiInstaller = ConfigApiInstaller() |
| 53 | + |
| 54 | +if not node_installer.installed(): |
| 55 | + node_fn = 'node-{0}-linux-x64.tar.xz'.format(app_versions['NODE_VERSION']) |
| 56 | + node_path = os.path.join(Config.distAppFolder, node_fn) |
| 57 | + if not os.path.exists(node_path): |
| 58 | + print("Downloading", node_fn) |
| 59 | + base.download('https://nodejs.org/dist/{0}/node-{0}-linux-x64.tar.xz'.format(app_versions['NODE_VERSION']), node_path) |
| 60 | + print("Installing node") |
| 61 | + node_installer.install() |
| 62 | + |
| 63 | + |
| 64 | +gluu_admin_ui_source_path = os.path.join(Config.distJansFolder, 'gluu-admin-ui.zip') |
| 65 | +log4j2_adminui_path = os.path.join(Config.distJansFolder, 'log4j2-adminui.xml') |
| 66 | +log4j2_path = os.path.join(Config.distJansFolder, 'log4j2.xml') |
| 67 | +admin_ui_plugin_source_path = os.path.join(Config.distJansFolder, 'admin-ui-plugin-distribution.jar') |
| 68 | +admin_ui_config_properties_path = os.path.join(Config.distJansFolder, 'auiConfiguration.properties') |
| 69 | + |
| 70 | +print("Downloading components") |
| 71 | +base.download(urljoin(maven_base_url, 'admin-ui-plugin/{0}{1}/admin-ui-plugin-{0}{1}-distribution.jar'.format(app_versions['JANS_APP_VERSION'], app_versions['JANS_BUILD'])), admin_ui_plugin_source_path) |
| 72 | +base.download('https://raw.githubusercontent.com/JanssenProject/jans-config-api/master/server/src/main/resources/log4j2.xml', log4j2_path) |
| 73 | +base.download('https://raw.githubusercontent.com/JanssenProject/jans-config-api/master/plugins/admin-ui-plugin/config/log4j2-adminui.xml', log4j2_adminui_path) |
| 74 | +base.download('https://github.com/GluuFederation/gluu-admin-ui/archive/refs/heads/{}.zip'.format(app_versions['ADMIN_UI_FRONTEND_BRANCH']), gluu_admin_ui_source_path) |
| 75 | +base.download('https://raw.githubusercontent.com/JanssenProject/jans/{}/flex-linux-setup/auiConfiguration.properties'.format(app_versions['SETUP_BRANCH']), admin_ui_config_properties_path) |
| 76 | + |
| 77 | + |
| 78 | +print("Installing Gluu Admin UI Frontend") |
| 79 | +package_zip = zipfile.ZipFile(gluu_admin_ui_source_path, "r") |
| 80 | +package_par_dir = package_zip.namelist()[0] |
| 81 | +source_dir = os.path.join(Config.outputFolder, package_par_dir) |
| 82 | + |
| 83 | +print("Extracting", gluu_admin_ui_source_path) |
| 84 | +package_zip.extractall(Config.outputFolder) |
| 85 | + |
| 86 | +configApiInstaller.renderTemplateInOut(os.path.join(source_dir, '.env.tmp'), source_dir, source_dir) |
| 87 | +configApiInstaller.copyFile(os.path.join(source_dir, '.env.tmp'), os.path.join(source_dir, '.env')) |
| 88 | +configApiInstaller.run([paths.cmd_chown, '-R', 'node:node', source_dir]) |
| 89 | +cmd_path = 'PATH=$PATH:{}/bin:{}/bin'.format(Config.jre_home, Config.node_home) |
| 90 | + |
| 91 | +for cmd in ('npm install @openapitools/openapi-generator-cli', 'npm run api', 'npm install', 'npm run build:prod'): |
| 92 | + print("Executing `{}`".format(cmd)) |
| 93 | + run_cmd = '{} {}'.format(cmd_path, cmd) |
| 94 | + configApiInstaller.run(['/bin/su', 'node','-c', run_cmd], source_dir) |
| 95 | + |
| 96 | +target_dir = os.path.join(httpdInstaller.server_root, 'admin') |
| 97 | +print("Copying files to", target_dir) |
| 98 | +configApiInstaller.copyTree(os.path.join(source_dir, 'dist'), target_dir) |
| 99 | + |
| 100 | +configApiInstaller.check_clients([('role_based_client_id', '2000.')]) |
| 101 | +configApiInstaller.renderTemplateInOut(admin_ui_config_properties_path, Config.distJansFolder, configApiInstaller.custom_config_dir) |
| 102 | +admin_ui_plugin_path = os.path.join(configApiInstaller.libDir, os.path.basename(admin_ui_plugin_source_path)) |
| 103 | +configApiInstaller.web_app_xml_fn = os.path.join(configApiInstaller.jetty_base, configApiInstaller.service_name, 'webapps/jans-config-api.xml') |
| 104 | +configApiInstaller.copyFile(admin_ui_plugin_source_path, configApiInstaller.libDir) |
| 105 | +configApiInstaller.add_extra_class(admin_ui_plugin_path) |
| 106 | + |
| 107 | +for logfn in (log4j2_adminui_path, log4j2_path): |
| 108 | + configApiInstaller.copyFile(logfn, configApiInstaller.custom_config_dir) |
| 109 | + |
| 110 | +print("Restarting Janssen Config Api") |
| 111 | +configApiInstaller.restart() |
| 112 | + |
| 113 | +print("Installation was completed. Browse https://{}/admin".format(Config.hostname)) |
0 commit comments