forked from GluuFederation/community-edition-setup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.py
executable file
·125 lines (90 loc) · 3.49 KB
/
install.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
#!/usr/bin/python3
import site
import re
import glob
import sys
import os
import subprocess
import argparse
import time
import zipfile
import shutil
import distutils
import requests
from urllib.parse import urljoin
run_time = time.strftime("%Y-%m-%d_%H-%M-%S")
ces_dir = '/install/community-edition-setup'
parser = argparse.ArgumentParser(description="This script extracts community-edition-setup package and runs setup.py without arguments")
parser.add_argument('-o', help="download latest package from github and override current community-edition-setup", action='store_true')
parser.add_argument('--args', help="Arguments to be passed to setup.py")
parser.add_argument('-b', help="Github branch name, e.g. version_4.0.b4")
argsp = parser.parse_args()
npyscreen_package = '/opt/dist/app/npyscreen-master.zip'
if argsp.o:
for cep in glob.glob('/opt/dist/gluu/community-edition-setup*.zip'):
os.remove(cep)
if os.path.exists(ces_dir):
back_dir = ces_dir+'.back.'+run_time
print("Backing up", ces_dir, "to", back_dir)
os.rename(ces_dir, back_dir)
github_base_url = 'https://github.com/GluuFederation/community-edition-setup/archive/'
arhchive_name = 'master.zip'
if argsp.b:
arhchive_name = argsp.b+'.zip'
download_link = urljoin(github_base_url, arhchive_name)
ces_list = glob.glob('/opt/dist/gluu/community-edition-setup*.zip')
if not ces_list:
if not argsp.o:
print("community-edition-setup package was not found")
dl = input("Download from github? (Y/n) ")
else:
dl = 'y'
if not dl.strip() or dl.lower()[0]=='y':
print("Downloading ", download_link)
result = requests.get(download_link, allow_redirects=True)
with open('/opt/dist/gluu/community-edition-setup.zip', 'wb') as w:
w.write(result.content)
ces_list = [os.path.join('/opt/dist/gluu', arhchive_name)]
else:
print("Exiting...")
sys.exit()
ces = max(ces_list)
ces_zip = zipfile.ZipFile(ces)
parent_dir = ces_zip.filelist[0].filename
target_dir = '/tmp/ces_tmp'
ces_zip.extractall(target_dir)
if not os.path.exists(ces_dir):
os.makedirs(ces_dir)
print("Extracting community-edition-setup package")
source_dir = os.path.join(target_dir, parent_dir)
ces_zip.close()
if not os.path.exists(source_dir):
sys.exit("Unzip failed. Exting")
cmd = 'cp -r -f {}* /install/community-edition-setup'.format(source_dir)
os.system(cmd)
os.system('rm -r -f '+source_dir)
shutil.rmtree(target_dir)
os.chmod('/install/community-edition-setup/setup.py', 33261)
post_setup = '/install/community-edition-setup/post-setup-add-components.py'
if os.path.exists(post_setup):
os.chmod(post_setup, 33261)
if argsp.o:
npy_download_link = 'https://github.com/npcole/npyscreen/archive/master.zip'
result = requests.get(npy_download_link, allow_redirects=True)
with open(npyscreen_package, 'wb') as w:
w.write(result.content)
if os.path.exists(npyscreen_package):
site_libdir = site.getsitepackages()[0]
dest_dir = os.path.join(site_libdir, 'npyscreen')
if not os.path.exists(dest_dir):
print("Extracting npyscreen to", dest_dir)
npyzip = zipfile.ZipFile(npyscreen_package)
parent_dir = npyzip.filelist[0].filename
target_dir = '/tmp/npyscreen_tmp'
npyzip.extractall(target_dir)
npyzip.close()
shutil.copytree(
os.path.join(target_dir, parent_dir, 'npyscreen'),
dest_dir
)
shutil.rmtree(target_dir)