-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
317 lines (260 loc) · 15.5 KB
/
main.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
from utils import (curl, fail2ban, mysql, nginx, php, phpmyadmin, redis, cacert, acme_sh, nghttp2, postgresql, python,
httpd, apr, imagemagick, openresty, memcached, lua_nginx_module, php_plugins, pip, tengine, xcache,
boost, github, pure_ftpd, htop, misc, freetype, libiconv, bison, openssl, php_patches, mariadb)
import json
import os
import datetime
from base_logger import logger
def make_online_resource():
with open(r"./output/resources.json", "r") as f:
resource_list = json.loads(f.read())
with open(r"./output/latest_meta.json", "r") as f:
latest_meta_list = json.loads(f.read())
dynamic_redirect_rules_file = open(r"./output/_redirects", "w+")
redirect_rules_html = open(r"./output/index.html", "w+")
redirect_rules_html.write(f"""<!DOCTYPE html>
<html>
<head>
<title>Oneinstack Mirror</title>
</head>
<body>
<h1>Oneinstack Mirror</h1>
<p><b>Author: <a href="https://github.com/Masterain98">Masterain</a></b></p>
<p>This page is generated by <a href="https://github.com/dalao-org/oneinstack-mirror-generator">oneinstack-mirror-generator</a></p>
<p>This mirror is generated at {datetime.datetime.now(datetime.UTC).strftime("%Y-%m-%d %H:%M:%S")} UTC</p>
<p>A suggested version file can be found in <a href="/suggest_versions.txt">suggest_versions.txt.</a></p>
""")
for resource in resource_list:
logger.info("Processing " + str(resource))
if "file_name" in resource.keys():
file_name = resource['file_name']
else:
file_name = resource["url"].split("/")[-1]
if resource["url"].startswith("http"):
rule = f"/oneinstack/src/{file_name} {resource["url"].replace("http://", "https://")} 301"
dynamic_redirect_rules_file.write(rule + "\n")
redirect_rules_html.write(f' <a href="{resource["url"]}">{file_name}</a><br>\n')
if "mariadb" in file_name:
version_folder_name = file_name.replace("-linux-systemd-x86_64.tar.gz", "")
os.makedirs(f"output/src/mariadb/{version_folder_name}/bintar-linux-systemd-x86_64/", exist_ok=True)
with open(f"output/src/mariadb/{version_folder_name}/bintar-linux-systemd-x86_64/md5sums.txt", "w+") as f:
f.write(f"{resource['md5']} {file_name}\n")
mariadb_redirect_rule = (f"/oneinstack/src/mariadb/{version_folder_name}/bintar-linux-systemd-x86_64"
f"/{file_name} {resource["url"].replace("http://", "https://")} 301")
dynamic_redirect_rules_file.write(mariadb_redirect_rule + "\n")
dynamic_redirect_rules_file.writelines(["/src/*.tar.gz /oneinstack/src/:splat.tar.gz 301\n",
"/src/*.tar.bz2 /oneinstack/src/:splat.tar.bz2 301\n",
"/src/*.tar.gz.asc /oneinstack/src/:splat.tar.gz.asc 301\n",
"/src/*.tgz /oneinstack/src/:splat.tgz 301\n",
"/src/*.zip /oneinstack/src/:splat.zip 301\n",
"/src/*.rar /oneinstack/src/:splat.rar 301\n"])
dynamic_redirect_rules_file.close()
redirect_rules_html.write("""</body>
</html>
""")
redirect_rules_html.close()
# Generate suggest_versions.txt
with open(r"./output/suggest_versions.txt", "w+") as f:
for meta in latest_meta_list:
f.write(f"{meta['version_file_name']}={meta['version']}\n")
def main():
mode = os.environ.get("MODE", "PROD")
if mode == "PROD":
os.makedirs("output/src", exist_ok=True)
resource_list = []
latest_meta_list = []
curl_output = curl.make_cache()
resource_list += curl_output[0]
latest_meta_list.append(curl_output[1])
resource_list += fail2ban.make_cache()
mysql_output = mysql.make_cache()
resource_list += mysql_output[0]
latest_meta_list += mysql_output[1]
nginx_output = nginx.make_cache()
resource_list += nginx_output[0]
latest_meta_list.append(nginx_output[1])
php_output = php.make_cache()
resource_list += php_output[0]
latest_meta_list += php_output[1]
phpmyadmin_output = phpmyadmin.make_cache()
resource_list += phpmyadmin_output[0]
latest_meta_list += phpmyadmin_output[1]
resource_list += redis.make_cache()
resource_list += cacert.make_cache()
resource_list += acme_sh.make_cache()
nghttp2_output = nghttp2.make_cache()
resource_list += nghttp2_output[0]
latest_meta_list.append(nghttp2_output[1])
postgresql_output = postgresql.make_cache()
resource_list += postgresql_output[0]
latest_meta_list.append(postgresql_output[1])
resource_list += python.make_cache()
httpd_output = httpd.make_cache()
resource_list += httpd_output[0]
latest_meta_list.append(httpd_output[1])
apr_output = apr.make_cache()
resource_list += apr_output[0]
latest_meta_list += apr_output[1]
imagemagick_output = imagemagick.make_cache()
resource_list += imagemagick_output[0]
latest_meta_list.append(imagemagick_output[1])
openresty_output = openresty.make_cache()
resource_list += openresty_output[0]
latest_meta_list.append(openresty_output[1])
resource_list += memcached.make_cache()
resource_list += lua_nginx_module.make_cache()
resource_list += pip.make_cache()
tengine_output = tengine.make_cache()
resource_list += tengine_output[0]
latest_meta_list.append(tengine_output[1])
resource_list += xcache.make_cache()
resource_list += boost.make_cache()
openssl_output = openssl.make_cache()
resource_list += openssl_output[0]
latest_meta_list += openssl_output[1]
lua_resty_core_output = github.download_repo_by_tag("openresty", "lua-resty-core",
"tar.gz", True, "lua_resty_core_ver")
resource_list += lua_resty_core_output[0]
latest_meta_list.append(lua_resty_core_output[1])
resource_list += pure_ftpd.make_cache()
resource_list += htop.make_cache()
jemalloc_output = github.get_single_package_from_release("jemalloc", "jemalloc", "jemalloc_ver")
resource_list += jemalloc_output[0]
latest_meta_list.append(jemalloc_output[1])
lua_resty_lrucache_output = github.download_repo_by_tag("openresty", "lua-resty-lrucache", "tar.gz", True,
"lua_resty_lrucache_ver")
resource_list += lua_resty_lrucache_output[0]
latest_meta_list.append(lua_resty_lrucache_output[1])
luajit2_output = github.download_repo_by_tag("openresty", "luajit2", "tar.gz", True, "luajit2_ver")
resource_list += luajit2_output[0]
latest_meta_list.append(luajit2_output[1])
lua_cjson_output = github.download_repo_by_tag("openresty", "lua-cjson", "tar.gz", True, "lua_cjson_ver")
resource_list += lua_cjson_output[0]
latest_meta_list.append(lua_cjson_output[1])
resource_list += github.get_package_from_release_with_regular_expression("gperftools",
"gperftools",
r"gperftools-\d+.\d+.tar.gz",
3,
None)[0]
icu_output = github.get_package_from_release_with_regular_expression("unicode-org",
"icu",
r"(icu4c-)[\d|\-|\_]+(src\.tgz)",
3,
"icu4c_ver")
resource_list += icu_output[0]
latest_meta_list.append(icu_output[1])
# gdrive package is changed!!!
resource_list += github.get_package_from_release_with_regular_expression("glotlabs",
"gdrive",
r"linux",
1,
None)[0]
libzip_output = github.get_package_from_release_with_regular_expression("nih-at",
"libzip",
r"\.tar\.gz",
5,
"libzip_ver")
resource_list += libzip_output[0]
latest_meta_list.append(libzip_output[1])
libsodium_output = github.get_package_from_release_with_regular_expression("jedisct1",
"libsodium",
r"\d+\.tar\.gz",
5,
"libsodium_ver")
resource_list += libsodium_output[0]
latest_meta_list.append(libsodium_output[1])
# Name changed!!! Was argon2-20190702.tar.gz and 20190702.tar.gz
argon2_output = github.download_repo_by_tag("P-H-C", "phc-winner-argon2",
archive_type="tar.gz", filter_blacklist=True,
latest_meta_name="argon2_ver")
resource_list += argon2_output[0]
argon2_fix_list = []
for data in argon2_output[0]:
if "phc-winner-argon2" in data["file_name"]:
new_file_name = data["file_name"].replace("phc-winner-argon2", "argon2")
argon2_fix_list.append({"file_name": new_file_name, "url": data["url"], "version": data["version"]})
resource_list += argon2_fix_list
latest_meta_list.append(argon2_output[1])
freetype_output = freetype.make_cache()
resource_list += freetype_output[0]
latest_meta_list.append(freetype_output[1])
resource_list += github.get_package_from_release_with_regular_expression("libevent",
"libevent",
r"\.tar\.gz$",
5,
None)[0]
resource_list += github.download_repo_by_tag("jokkedk", "webgrind", "zip", False, None)[0]
# ngx_devel_kit name changed!!!
resource_list += github.download_repo_by_tag("vision5", "ngx_devel_kit", "tar.gz", False, None)[0]
resource_list += github.get_package_from_release_with_regular_expression("kkos", "oniguruma",
r"\.tar\.gz$", 5, None)[0]
resource_list += github.get_package_from_release_with_regular_expression("dropbox", "dbxcli",
r"dbxcli-linux-arm", 1, None)[0]
resource_list += github.get_package_from_release_with_regular_expression("dropbox", "dbxcli",
r"dbxcli-linux-amd64", 1, None)[0]
resource_list += bison.make_cache()
libiconv_output = libiconv.make_cache()
resource_list += libiconv_output[0]
latest_meta_list.append(libiconv_output[1])
misc_output = misc.make_cache()
resource_list += misc_output[0]
latest_meta_list += misc_output[1]
mariadb_output = mariadb.make_cache()
resource_list += mariadb_output[0]
latest_meta_list += mariadb_output[1]
apcu_output = php_plugins.make_cache("APCU", "apcu",
False, "apcu_ver")
resource_list += apcu_output[0]
latest_meta_list.append(apcu_output[1])
gmagick_output = php_plugins.make_cache("gmagick", "gmagick",
True, "gmagick_ver")
resource_list += gmagick_output[0]
latest_meta_list.append(gmagick_output[1])
imagick_output = php_plugins.make_cache("imagick", "imagick",
False, "imagick_ver")
resource_list += imagick_output[0]
latest_meta_list.append(imagick_output[1])
pecl_memcache_output = php_plugins.make_cache("memcache", "memcache",
False, "pecl_memcache_ver")
resource_list += pecl_memcache_output[0]
latest_meta_list.append(pecl_memcache_output[1])
pecl_mongodb_output = php_plugins.make_cache("mongodb", "mongodb",
False, "pecl_mongodb_ver")
resource_list += pecl_mongodb_output[0]
latest_meta_list.append(pecl_mongodb_output[1])
swoole_output = php_plugins.make_cache("swoole", "swoole",
False, "swoole_ver")
resource_list += swoole_output[0]
latest_meta_list.append(swoole_output[1])
yaf_output = php_plugins.make_cache("YAF", "yaf",
False, "yaf_ver")
resource_list += yaf_output[0]
latest_meta_list.append(yaf_output[1])
xdebug_output = php_plugins.make_cache("xdebug", "xdebug",
False, "xdebug_ver")
resource_list += xdebug_output[0]
latest_meta_list.append(xdebug_output[1])
pecl_mongo_output = php_plugins.make_cache("mongo", "mongo",
False, "pecl_mongo_ver")
resource_list += pecl_mongo_output[0]
latest_meta_list.append(pecl_mongo_output[1])
resource_list += php_patches.make_cache()
# Older versions of PHP plugins
latest_meta_list += [
{"version_file_name": "apcu_oldver", "version": "4.0.11"},
{"version_file_name": "gmagick_oldver", "version": "1.1.7RC3"},
{"version_file_name": "imagick_oldver", "version": "3.4.4"},
{"version_file_name": "pecl_memcache_oldver", "version": "4.0.5.2"},
{"version_file_name": "pecl_mongodb_oldver", "version": "1.9.2"},
{"version_file_name": "swoole_oldver", "version": "4.8.12"},
{"version_file_name": "xdebug_oldver", "version": "2.9.8"},
]
with open(r"./output/resources.json", "w+") as f:
f.write(json.dumps(resource_list, indent=4))
with open(r"./output/latest_meta.json", "w+") as f:
f.write(json.dumps(latest_meta_list, indent=4))
else:
logger.info("Mode is not PROD, skipping resource list generation.")
make_online_resource()
if __name__ == "__main__":
main()