Skip to content

Commit

Permalink
feat(jans-ce-setup): ce-setup suse compatibility (#692)
Browse files Browse the repository at this point in the history
  • Loading branch information
devrimyatar authored Jan 24, 2022
1 parent f820355 commit f0076fc
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 42 deletions.
26 changes: 20 additions & 6 deletions jans-ce-setup/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,29 @@
else:
print("Can't determine Jetty Version. Continuing with version {}".format(app_versions['JETTY_VERSION']))


package_installer = shutil.which('apt') or shutil.which('dnf') or shutil.which('yum') or shutil.which('zypper')

package_dependencies = []

try:
from distutils import dist
except:
if not argsp.n:
install_dist = input('python3-disutils package is needed. Install now? [Y/n] ')
if install_dist.lower().startswith('n'):
print("Can't continue...")
sys.exit()
os.system('apt install -y python3-distutils')
package_dependencies.append('python3-distutils')

try:
import ldap3
except:
package_dependencies.append('python3-ldap3')


if package_dependencies and not argsp.n:
install_dist = input('Required package(s): {}. Install now? [Y/n] '.format(', '.join(package_dependencies)))
if install_dist.lower().startswith('n'):
print("Can't continue...")
sys.exit()

os.system('{} install -y {}'.format(package_installer, ' '.join(package_dependencies)))


def extract_subdir(zip_fn, sub_dir, target_dir, zipf=None):
Expand Down
4 changes: 4 additions & 0 deletions jans-ce-setup/setup_app/data/package_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,9 @@
"centos 8": {
"optional": "",
"mondatory": "httpd mod_ssl curl wget tar xz unzip python3-ldap3 python3-requests python3-ruamel-yaml rsyslog python3-certifi python3-PyMySQL bzip2 python3-cryptography"
},
"suse 15": {
"optional": "",
"mondatory": "apache2 curl wget tar xz unzip python3-ldap3 python3-requests python3-ruamel.yaml rsyslog python3-certifi python3-PyMySQL bzip2"
}
}
94 changes: 63 additions & 31 deletions jans-ce-setup/setup_app/installers/httpd.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ def __init__(self):
self.apache2_ssl_conf = os.path.join(self.output_folder, 'https_jans.conf')
self.apache2_24_conf = os.path.join(self.output_folder, 'httpd_2.4.conf')
self.apache2_ssl_24_conf = os.path.join(self.output_folder, 'https_jans.conf')
self.https_jans_fn = '/etc/httpd/conf.d/https_jans.conf' if base.clone_type == 'rpm' else '/etc/apache2/sites-available/https_jans.conf'

if base.os_type == 'suse':
self.https_gluu_fn = '/etc/apache2/vhosts.d/_https_gluu.conf'
elif base.clone_type == 'rpm':
self.https_gluu_fn = '/etc/httpd/conf.d/https_gluu.conf'
else:
self.https_gluu_fn = '/etc/apache2/sites-available/https_gluu.conf'


def configure(self):
self.logIt(self.pbar_text, pbar=self.service_name)
Expand All @@ -46,10 +53,12 @@ def configure(self):

if base.snap:
icons_conf_fn = '/etc/apache2/mods-available/alias.conf'
if base.os_type == 'suse':
icons_conf_fn = '/etc/apache2/default-server.conf'
elif base.clone_type == 'deb':
icons_conf_fn = '/etc/apache2/mods-available/alias.conf'
elif base.clone_type == 'rpm':
icons_conf_fn = '/etc/httpd/conf.d/autoindex.conf'
else:
icons_conf_fn = '/etc/apache2/mods-available/alias.conf'

with open(icons_conf_fn[:]) as f:
icons_conf = f.readlines()
Expand All @@ -66,11 +75,10 @@ def configure(self):
self.copyFile(tmp_fn, '/var/www/html')

# we only need these modules
mods_enabled = ['env', 'proxy_http', 'access_compat', 'alias', 'authn_core', 'authz_core', 'authz_host', 'headers', 'mime', 'mpm_event', 'proxy', 'proxy_ajp', 'security2', 'reqtimeout', 'setenvif', 'socache_shmcb', 'ssl', 'unique_id', 'rewrite']
if base.clone_type == 'deb':
mods_enabled.insert(0, 'dir')
elif base.clone_type == 'rpm':
mods_enabled.insert(0, 'mod_dir')
mods_enabled = ['env', 'log_config', 'proxy', 'proxy_http', 'access_compat', 'alias', 'authn_core', 'authz_core', 'authz_host', 'headers', 'mime', 'mpm_event', 'proxy_ajp', 'security2', 'reqtimeout', 'setenvif', 'socache_shmcb', 'ssl', 'unique_id', 'rewrite']

cmd_a2enmod = shutil.which('a2enmod')
cmd_a2dismod = shutil.which('a2dismod')

if base.snap:
mods_enabled_dir = os.path.join(base.snap_common, 'etc/apache2/mods-enabled')
Expand All @@ -93,10 +101,43 @@ def configure(self):
if not os.path.exists(target_fn):
os.symlink(conf_fn, target_fn)

elif base.clone_type == 'rpm':
elif base.clone_type == 'deb':
for mod_load_fn in glob.glob('/etc/apache2/mods-enabled/*'):
mod_load_base_name = os.path.basename(mod_load_fn)
f_name, f_ext = os.path.splitext(mod_load_base_name)
if not f_name in mods_enabled:
self.run([cmd_a2dismod, mod_load_fn])
for amod in mods_enabled:
if os.path.exists('/etc/apache2/mods-available/{}.load'.format(amod)):
self.run([cmd_a2enmod, amod])

elif base.os_type == 'suse':
result = self.run([cmd_a2enmod, '-l'])
current_modules = result.strip().split()
for amod in current_modules:
if not amod in mods_enabled:
self.run([cmd_a2dismod, amod])
for amod in mods_enabled:
if not amod in current_modules:
self.run([cmd_a2enmod, amod])
cmd_a2enflag = shutil.which('a2enflag')
self.run([cmd_a2enflag, 'SSL'])

httpd_conf_fn = '/etc/apache2/httpd.conf'
httpd_conf_txt = self.readFile(httpd_conf_fn)
httpd_conf = httpd_conf_txt.splitlines()

for mod_load_fn in glob.glob('/etc/httpd/conf.modules.d/*'):
for i, l in enumerate(httpd_conf[:]):
if l.strip().startswith('DirectoryIndex'):
httpd_conf[i] = l.replace('DirectoryIndex', '#DirectoryIndex')

self.writeFile(httpd_conf_fn, '\n'.join(httpd_conf))

else:
modules_config_dir = '/etc/apache2/sysconfig.d' if base.os_type == 'suse' else '/etc/httpd/conf.modules.d'
for mod_load_fn in glob.glob(os.path.join(modules_config_dir,'*')):
if not os.path.isfile(mod_load_fn):
continue
with open(mod_load_fn) as f:
mod_load_content = f.readlines()

Expand All @@ -107,27 +148,16 @@ def configure(self):

if ls and not ls.startswith('#'):
lsl = ls.split('/')
if not lsl[0].startswith('LoadModule'):
continue
module = lsl[-1][4:-3]

if not module in mods_enabled:
mod_load_content[i] = l.replace('LoadModule', '#LoadModule')
modified = True

if modified:
self.writeFile(mod_load_fn, ''.join(mod_load_content))
else:

cmd_a2enmod = shutil.which('a2enmod')
cmd_a2dismod = shutil.which('a2dismod')

for mod_load_fn in glob.glob('/etc/apache2/mods-enabled/*.load'):
mod_load_base_name = os.path.basename(mod_load_fn)
f_name, f_ext = os.path.splitext(mod_load_base_name)
if not f_name in mods_enabled:
self.run([cmd_a2dismod, '-f', f_name])

for amod in mods_enabled:
self.run([cmd_a2enmod, amod])

if not Config.get('httpdKeyPass'):
Config.httpdKeyPass = self.getPW()
Expand All @@ -140,24 +170,26 @@ def configure(self):
self.start()

def write_httpd_config(self):

self.update_rendering_dict()
for tmp in (self.apache2_conf, self.apache2_ssl_conf, self.apache2_24_conf, self.apache2_ssl_24_conf):
self.renderTemplateInOut(tmp, self.templates_folder, self.output_folder)

# CentOS 7.* + systemd + apache 2.4
if self.service_name == 'httpd' and self.apache_version == "2.4":
self.copyFile(self.apache2_24_conf, '/etc/httpd/conf/httpd.conf')
self.copyFile(self.apache2_ssl_24_conf, '/etc/httpd/conf.d/https_jans.conf')
self.copyFile(self.apache2_ssl_24_conf, '/etc/httpd/conf.d/https_gluu.conf')

if base.os_type == 'suse':
self.copyFile(self.apache2_ssl_conf, self.https_gluu_fn)

if base.clone_type == 'rpm' and base.os_initdaemon == 'init':
elif base.clone_type == 'rpm' and base.os_initdaemon == 'init':
self.copyFile(self.apache2_conf, '/etc/httpd/conf/httpd.conf')
self.copyFile(self.apache2_ssl_conf, self.https_jans_fn)
self.copyFile(self.apache2_ssl_conf, self.https_gluu_fn)

if base.clone_type == 'deb':
self.copyFile(self.apache2_ssl_conf, self.https_jans_fn)
self.run([paths.cmd_ln, '-s', self.https_jans_fn,
'/etc/apache2/sites-enabled/https_jans.conf'])
elif base.clone_type == 'deb':
self.copyFile(self.apache2_ssl_conf, self.https_gluu_fn)
self.run([paths.cmd_ln, '-s', self.https_gluu_fn,
'/etc/apache2/sites-enabled/https_gluu.conf'])

def installed(self):
return os.path.exists(self.https_jans_fn)
8 changes: 7 additions & 1 deletion jans-ce-setup/setup_app/utils/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
os_type = 'red'
elif 'ubuntu-core' in os_type:
os_type = 'ubuntu'
elif ('sles' in os_type) or ('opensuse' in os_type):
os_type = 'suse'
elif row[0] == 'VERSION_ID':
os_version = row[1].split('.')[0]

Expand All @@ -71,7 +73,7 @@
deb_sysd_clone = os_name in ('ubuntu18', 'ubuntu20', 'debian9', 'debian10')

# Determine service path
if (os_type in ('centos', 'red', 'fedora') and os_initdaemon == 'systemd') or deb_sysd_clone:
if (os_type in ('centos', 'red', 'fedora', 'suse') and os_initdaemon == 'systemd') or deb_sysd_clone:
service_path = shutil.which('systemctl')
elif os_type in ['debian', 'ubuntu']:
service_path = '/usr/sbin/service'
Expand All @@ -81,10 +83,14 @@
if os_type in ('centos', 'red', 'fedora'):
clone_type = 'rpm'
httpd_name = 'httpd'
elif os_type == 'suse':
clone_type = 'rpm'
httpd_name = 'apache2'
else:
clone_type = 'deb'
httpd_name = 'apache2'


if snap:
snapctl = shutil.which('snapctl')

Expand Down
12 changes: 8 additions & 4 deletions jans-ce-setup/setup_app/utils/package_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ def get_install_commands(self):
check_text = '0'

elif base.clone_type == 'rpm':
install_command = 'yum install -y {0}'
update_command = 'yum install -y epel-release'
if base.os_type == 'suse':
install_command = 'zypper install -y {0}'
update_command = ''
else:
install_command = 'yum install -y {0}'
update_command = 'yum install -y epel-release'
query_command = 'rpm -q {0}'
check_text = 'is not installed'

return install_command, update_command, query_command, check_text


Expand Down Expand Up @@ -94,7 +98,7 @@ def check_and_install_packages(self):
if install[install_type]:
self.logIt("Installing packages " + packages)
print("Installing packages", packages)
if not base.os_type == 'fedora':
if not base.os_type in ('fedora', 'suse'):
sout, serr = self.run(update_command, shell=True, get_stderr=True)
self.installNetPackage(packages)

Expand Down

0 comments on commit f0076fc

Please sign in to comment.