Skip to content

Commit

Permalink
feat(jans-linux-setup): Jans linux setup pkg mysql and uninstall (#827)
Browse files Browse the repository at this point in the history
* fix: jans-linux-setup package requirements for sql

* feat: implement uninstall for pkg
  • Loading branch information
devrimyatar committed Feb 16, 2022
1 parent 493337f commit 0fb53e1
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 47 deletions.
88 changes: 47 additions & 41 deletions jans-linux-setup/jans_setup/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,52 @@ def prepare_jans_cli_package():
print("Preparing jans-cli package")
extract_subdir(jans_zip_file, 'jans-cli', 'jans-cli', os.path.join(jans_app_dir, 'jans-cli.zip'))


def uninstall_jans():
check_installation()
print('\033[31m')
print("This process is irreversible.")
print("You will lose all data related to Janssen Server.")
print('\033[0m')
print()
while True:
print('\033[31m \033[1m')
response = input("Are you sure to uninstall Janssen Server? [yes/N] ")
print('\033[0m')
if response.lower() in ('yes', 'n', 'no'):
if not response.lower() == 'yes':
sys.exit()
else:
break
else:
print("Please type \033[1m yes \033[0m to uninstall")

print("Uninstalling Jannsen Server...")
for service in jetty_services:
if os.path.exists(os.path.join(jetty_home, service)):
default_fn = os.path.join('/etc/default/', service)
if os.path.exists(default_fn):
print("Removing", default_fn)
os.remove(default_fn)
print("Stopping", service)
os.system('systemctl stop ' + service)

if argsp.profile == 'jans':
print("Stopping OpenDj Server")
os.system('/opt/opendj/bin/stop-ds')

remove_list = ['/etc/certs', '/etc/jans', '/opt/jans', '/opt/amazon-corretto*', '/opt/jre', '/opt/node*', '/opt/jetty*', '/opt/jython*']
if argsp.profile == 'jans':
remove_list.append('/opt/opendj')
if not argsp.keep_downloads:
remove_list.append('/opt/dist')

for p in remove_list:
cmd = 'rm -r -f ' + p
print("Executing", cmd)
os.system('rm -r -f ' + p)


def main():

check_install_dependencies()
Expand Down Expand Up @@ -346,48 +392,8 @@ def main():
os.system('systemctl restart jans-config-api')

elif argsp.uninstall:
check_installation()
print('\033[31m')
print("This process is irreversible.")
print("You will lose all data related to Janssen Server.")
print('\033[0m')
print()
while True:
print('\033[31m \033[1m')
response = input("Are you sure to uninstall Janssen Server? [yes/N] ")
print('\033[0m')
if response.lower() in ('yes', 'n', 'no'):
if not response.lower() == 'yes':
sys.exit()
else:
break
else:
print("Please type \033[1m yes \033[0m to uninstall")

print("Uninstalling Jannsen Server...")
for service in jetty_services:
if os.path.exists(os.path.join(jetty_home, service)):
default_fn = os.path.join('/etc/default/', service)
if os.path.exists(default_fn):
print("Removing", default_fn)
os.remove(default_fn)
print("Stopping", service)
os.system('systemctl stop ' + service)

if argsp.profile == 'jans':
print("Stopping OpenDj Server")
os.system('/opt/opendj/bin/stop-ds')

remove_list = ['/etc/certs', '/etc/jans', '/opt/jans', '/opt/amazon-corretto*', '/opt/jre', '/opt/node*', '/opt/jetty*', '/opt/jython*']
if argsp.profile == 'jans':
remove_list.append('/opt/opendj')
if not argsp.keep_downloads:
remove_list.append('/opt/dist')

for p in remove_list:
cmd = 'rm -r -f ' + p
print("Executing", cmd)
os.system('rm -r -f ' + p)
uninstall_jans()

else:

Expand Down
14 changes: 9 additions & 5 deletions jans-linux-setup/jans_setup/jans_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@
dir_path = os.path.dirname(os.path.realpath(__file__))
sys.path.append(dir_path)

if not (os.path.exists('/opt/dist/jans/jans.zip') or os.path.exists('jans-auth.war')):
if not (os.path.exists('/opt/dist/jans/jans.zip') or os.path.exists('jans-auth.war')) or '-uninstall' in sys.argv:
import install
install.setup_dir = dir_path
print("Downloading Files")
install.download_files()
install.extract_yaml_files()
install.prepare_jans_cli_package()
if '-uninstall' in sys.argv:
install.uninstall_jans()
sys.exit()
else:
print("Downloading Files")
install.download_files()
install.extract_yaml_files()
install.prepare_jans_cli_package()

os.environ['LC_ALL'] = 'C'
from setup_app.utils.arg_parser import arg_parser
Expand Down
2 changes: 2 additions & 0 deletions jans-linux-setup/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ setuptools>=59.6.0
pyasn1==0.4.8
ruamel.yaml>=0.16.5
sqlalchemy==1.4.31
sqlalchemy==1.3.23
cryptography==36.0.1
google-cloud-spanner==3.13.0
ldap3
PyMySQL
Expand Down
3 changes: 2 additions & 1 deletion jans-linux-setup/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def find_version(*file_paths):
"setuptools>=59.6.0",
"pyasn1==0.4.8",
"ruamel.yaml>=0.16.5",
"sqlalchemy==1.4.31",
"sqlalchemy==1.3.23",
"cryptography==36.0.1",
"google-cloud-spanner==3.13.0",
"ldap3",
"PyMySQL",
Expand Down

0 comments on commit 0fb53e1

Please sign in to comment.