-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathupdate_shared_libraries.py
More file actions
64 lines (52 loc) · 1.91 KB
/
update_shared_libraries.py
File metadata and controls
64 lines (52 loc) · 1.91 KB
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
import requests
import os
import re
REPO = "bogdanfinn/tls-client"
DEST_DIR = "../tls_client/dependencies/"
MAJOR_VERSION = "1"
# Regex to strip version from filenames like -v1.8.0
version_pattern = re.compile(r"-v?\d+\.\d+\.\d+")
# Mapping from original GitHub filenames (without version) to local dependency filenames
rename_map = {
# Windows
"tls-client-windows-32.dll": "tls-client-32.dll",
"tls-client-windows-64.dll": "tls-client-64.dll",
# MacOS
"tls-client-darwin-arm64.dylib": "tls-client-arm64.dylib",
"tls-client-darwin-amd64.dylib": "tls-client-x86.dylib",
# Linux
"tls-client-linux-alpine-amd64.so": "tls-client-amd64.so",
"tls-client-linux-ubuntu-amd64.so": "tls-client-x86.so",
"tls-client-linux-arm64.so": "tls-client-arm64.so",
}
# Fetch all releases
releases_url = f"https://api.github.com/repos/{REPO}/releases"
releases = requests.get(releases_url).json()
# Find the latest release with the desired major version
latest_release = None
for release in releases:
tag = release.get("tag_name", "")
version = tag.lstrip("v")
if version.startswith(MAJOR_VERSION + "."):
latest_release = release
break
if not latest_release:
print(f"No release found with major version {MAJOR_VERSION}.")
exit(1)
tag_name = latest_release["tag_name"]
assets = latest_release.get("assets", [])
os.makedirs(DEST_DIR, exist_ok=True)
for asset in assets:
name = asset["name"]
# Strip version from filename
name_stripped = version_pattern.sub("", name)
# Apply renaming if matched
target_name = rename_map.get(name_stripped)
if not target_name:
print(f"Skipping unmatched file: {name}")
continue
download_url = asset["browser_download_url"]
print(f"Downloading {name} → {target_name}")
response = requests.get(download_url)
with open(os.path.join(DEST_DIR, target_name), "wb") as f:
f.write(response.content)