2019-02-28 13:56:54 +00:00
|
|
|
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import requests
|
|
|
|
import re
|
|
|
|
import subprocess
|
|
|
|
|
2019-03-08 23:01:24 +00:00
|
|
|
platforms = ["linux", "macos", "win"]
|
|
|
|
|
|
|
|
if sys.platform == "darwin":
|
|
|
|
md5sum_cmd = ["md5", "-r"]
|
|
|
|
else:
|
|
|
|
md5sum_cmd = ["md5sum"]
|
|
|
|
|
2019-02-28 13:56:54 +00:00
|
|
|
fetch_deps_path = os.path.join(os.path.dirname(sys.argv[0]), "fetch_deps.sh")
|
|
|
|
|
|
|
|
print("Fetching latest release")
|
2020-12-16 10:59:23 +00:00
|
|
|
json = requests.get("https://api.github.com/repos/rizinorg/cutter-deps/releases/latest").json()
|
2019-02-28 13:56:54 +00:00
|
|
|
|
|
|
|
release_url = json["assets"][0]["browser_download_url"]
|
2019-03-08 23:01:24 +00:00
|
|
|
for platform in platforms:
|
|
|
|
release_url = release_url.replace(platform, "${PLATFORM}")
|
2019-02-28 13:56:54 +00:00
|
|
|
|
2019-03-08 23:01:24 +00:00
|
|
|
with open(fetch_deps_path) as f:
|
|
|
|
fetch_deps = f.read()
|
2019-02-28 13:56:54 +00:00
|
|
|
|
2019-03-08 23:01:24 +00:00
|
|
|
md5 = {}
|
|
|
|
for platform in platforms:
|
|
|
|
platform_url = release_url.replace("${PLATFORM}", platform)
|
|
|
|
print(f"Getting MD5 for {platform_url}")
|
2019-02-28 13:56:54 +00:00
|
|
|
|
2019-03-08 23:01:24 +00:00
|
|
|
curl = subprocess.Popen(["curl", "-fL", platform_url], stdout=subprocess.PIPE)
|
|
|
|
md5sum = subprocess.run(md5sum_cmd, stdin=curl.stdout, capture_output=True, encoding="utf-8").stdout
|
|
|
|
curl.wait()
|
|
|
|
if curl.returncode != 0:
|
|
|
|
print(f"Failed to download {platform_url}, skipping.")
|
|
|
|
continue
|
2019-02-28 13:56:54 +00:00
|
|
|
|
2019-03-08 23:01:24 +00:00
|
|
|
md5sum = re.fullmatch("([a-zA-Z0-9]+)( +-)?\n?", md5sum).group(1)
|
2019-02-28 13:56:54 +00:00
|
|
|
|
2019-03-08 23:01:24 +00:00
|
|
|
print(f"MD5: {md5sum}")
|
|
|
|
fetch_deps = re.sub(f"^{platform.upper()}_URL=.*$", f"{platform.upper()}_URL={platform_url}".replace("\\", r"\\"), fetch_deps, flags=re.MULTILINE)
|
|
|
|
fetch_deps = re.sub(f"^{platform.upper()}_MD5=.*$", f"{platform.upper()}_MD5={md5sum}".replace("\\", r"\\"), fetch_deps, flags=re.MULTILINE)
|
2019-02-28 13:56:54 +00:00
|
|
|
|
|
|
|
with open(fetch_deps_path, "w") as f:
|
|
|
|
f.write(fetch_deps)
|